提到3d渲染引,通常只会用,现在呢把这东西移植到了stm32上,大家可以学习下,不光能旋转立方体,只要是简单的3d图(例如纸飞机)都能显示
视频:https://v.youku.com/v_show/id_XMzc0NDEyNzc4NA==.html
贴上源码
- float cube[8][3]={{-15,-15,-15},{-15,15,-15},{15,15,-15},{15,-15,-15},{-15,-15,15},{-15,15,15},{15,15,15},{15,-15,15}};//立方体坐标
- int lineid[25]={1,2,2,3,3,4,4,1,5,6,6,7,7,8,8,5,8,4,7,3,6,2,5,1};//记录点之间连接顺序
- float *matconv(float *a,float b[3][3]){//计算矩阵算法
- float res[3];
- int i;
- for(i=0;i<3;i++){
- res[i]=b[i][0]*a[0]+b[i][1]*a[1]+b[i][2]*a[2];
- }
- for(i=0;i<3;i++){
- a[i]=res[i];
- }
- return a;
- }
- void rotate(float *obj,float x,float y,float z){//旋转这个向量
- float rz[3][3]={{cos(z),sin(z),0},{sin(z),cos(z),0},{0,0,0}};
- float ry[3][3]={{0,0,0},{0,cos(y),sin(y)},{0,sin(y),cos(y)}};
- float rx[3][3]={{cos(x),0,sin(x)},{0,0,0},{sin(x),0,cos(x)}};
- matconv(matconv(matconv(obj,rz),ry),rx);
- }
复制代码
|