|
发表于 2012-12-20 01:03:16
|
显示全部楼层
可能英语注释的不太清楚,动笔花花就清楚了。
const signed int aa[8]={40,-40,-40,40, 40,-40,-40,40}; // x data for shape vertex
const signed int bb[8]={40,40,-40,-40, 40,40,-40,-40}; // y data for shape vertex
const signed int cc[8]={-40,-40,-40,-40, 40,40,40,40}; // z data for shape vertex
上边三个数组存的立方体8个顶点坐标,如(40,40,-40)。我改成40了,在320*240的TFT上看起来更大。
const int ff[12]={1,2,3,4, 5,6,7,8, 1,2,3,4}; // start vertex for lines
const int gg[12]={2,3,4,1, 6,7,8,5, 5,6,7,8}; // end vertex for lines
这两个数组存的12条边的顺序,如1-2,表示顶点1到顶点2的那条边。
newx[i] = (x / (z / 256 + 1)) + OFFSETX; // translate 3d to 2d coordinates for screen
newy[i] = (y / (z / 256 + 1)) + OFFSETY; // drawing so we can see the cube
按照书上的,上面改成这样了,觉得效果好些。
rotx = rotx + 0.01; // rotate the cube on X axis
roty = roty + 0.01; // and on its y axis
rotz = rotz + 0.0; // dont bother with z or it gets confusing
可以改旋转速度。
其实确实挺简单的,不难理解,看看那本书Chapter 6 图形变换,for语句里的就不难理解了。原理知道了,可是能做出什么东西呢?STM32上的3D游戏?呵呵,可以做个3D版的陀螺仪。
这代码应该可以优化。不知有没有更好的算法,这个太占资源了。不加外部SRAM,STM32刷320*240TFT都成问题。 |
|