有视频为证 v.youku.com/v_show/id_XNjEwODcxODc2.html 以下为源代码: #include "includes.h" #include "LHLGUI.h" MemDevHandle mmemdev; /******************************调色板数据******************************/ const unsigned short colorpalettle[]= { RGB(255,255,255), RGB(5,90,144), RGB(196,64,42), RGB(0,0,255), RGB(255,0,0), RGB(0,255,0), RGB(255,255,0), RGB(0,0,0) }; /****************************调色板索引数据****************************/ enum { CP_WHITE=0, CP_GRAY, CP_UN, CP_BLUE, CP_RED, CP_GREEN, CP_YELLOW, CP_BLACK }; /************3维图像的点定义******************/ typedef struct { float x; float y; float z; }GUI_POINT_3D; typedef struct { GUI_POINT_3D SideCenter; short PointIndex[4]; }SideStruct; /****************长方体特征点定义***********************/ const GUI_POINT_3D GP_Cube[]={{-1,-1,-1},{1,-1,-1},{1,-1,1},{-1,-1,1}, {-1, 1,-1},{1, 1,-1},{1, 1,1},{-1, 1,1}}; const short CubeColor[6]={CP_WHITE,CP_GRAY,CP_UN,CP_BLUE,CP_RED,CP_GREEN}; /*****************长方体旋转角度************************/ float Angle_x=0.0f; float Angle_y=0.0f; float Angle_z=0.0f; void CreatGUITask(void) { xTaskCreate( GUI_Process_TaskBody, ( signed portCHAR * ) "GUI_Pro", StackSize_GUIPROCESS, NULL, GUIPROCESSPro, NULL ); } GUI_POINT_3D Culculate[8]={0}; void SideStructInit(SideStruct *NewStruct,short m1,short m2,short m3,short m4) { NewStruct->ointIndex[0]=m1; NewStruct->ointIndex[1]=m2; NewStruct->ointIndex[2]=m3; NewStruct->ointIndex[3]=m4; NewStruct->SideCenter.x=(GP_Cube[m1].x+GP_Cube[m3].x)/2; NewStruct->SideCenter.y=(GP_Cube[m1].y+GP_Cube[m3].y)/2; NewStruct->SideCenter.z=(GP_Cube[m1].z+GP_Cube[m3].z)/2; } void GUI_3D_Polygon(GUI_POINT_3D *pResultPoint,const GUI_POINT_3D *pPoint, short Len,float xAngle,float yAngle,float zAngle) { float Focus_K,Focus_len;//计算人的视角所引起的物体变形 float cosfx=cosf(xAngle); float cosfy=cosf(yAngle); float cosfz=cosf(zAngle); float sinfx=sinf(xAngle); float sinfy=sinf(yAngle); float sinfz=sinf(zAngle); short i; float tempx,tempy,tempz; float tempx1,tempy1,tempz1; for(i=0;ix; tempy=(pPoint+i)->y; tempz=(pPoint+i)->z; tempy1 = tempy * cosfx - tempz * sinfx; tempz1 = tempy * sinfx + tempz * cosfx; tempy = tempy1; tempz = tempz1; tempx1 = tempx * cosfy - tempz * sinfy; tempz1 = tempx * sinfy + tempz * cosfy; tempx = tempx1; tempz = tempz1; tempx1 = tempx * cosfz - tempy * sinfz; tempy1 = tempx * sinfz + tempy * cosfz; tempx = tempx1; tempy = tempy1; Focus_len=(25-tempz)/25; Focus_K=tempy/tempx; tempx*=Focus_len; tempy=tempx*Focus_K; (pResultPoint+i)->x=tempx; (pResultPoint+i)->y=tempy; (pResultPoint+i)->z=tempz; } } GUI_POINT_3D cube3dbuffer[8]={0}; SideStruct Cube_6Side[6]; SideStruct Cube_6SideBuffer[6]; short Cube_SideOrder[6]={0,1,2,3,4,5}; float AccX,AccY,AccZ; void GUI_Process_TaskBody(void *p) { short x,y,m; BSP_Init(); SideStructInit(Cube_6Side ,0,1,2,3); SideStructInit(Cube_6Side+1,0,1,5,4); SideStructInit(Cube_6Side+2,1,2,6,5); SideStructInit(Cube_6Side+3,2,3,7,6); SideStructInit(Cube_6Side+4,3,0,4,7); SideStructInit(Cube_6Side+5,4,5,6,7); GUI_MemDevInit(&mmemdev,320,240,GUI_MEMDEV_4BIT);//初始化内存设备 GUI_MemDevSetColorPalettle(&mmemdev,colorpalettle);//选择自定义调色板 GUICore_SetMemDev(&mmemdev);//选择内存设备为当前绘图设备 while(1) { ADS7843_Rd_Addata((u16 *)&x,(u16 *)&y); if((short)xSideCenter,1,Angle_x,Angle_y,Angle_z); (Cube_6SideBuffer+x)->SideCenter.x=(Cube_6SideBuffer+x)->SideCenter.x*100+100; (Cube_6SideBuffer+x)->SideCenter.y=(Cube_6SideBuffer+x)->SideCenter.y*100+100; } for(x=0;xx*80+120; (cube3dbuffer+x)->y=(cube3dbuffer+x)->y*80+100; } for(x=3;xPointIndex+y)].x; (mbffer+y)->y=cube3dbuffer[*((Cube_6Side+Cube_SideOrder[x])->ointIndex+y)].y; } GUI_FillPolygon(mbffer,4,0,0,CubeColor[Cube_SideOrder[x]]); } GUI_MemDevShow(&mmemdev,0,0);//将绘制好的图像贴到屏幕上 } } void _cb_mButton(void *Handle,MsgType msg) { NMBTN_SetInCallBack(Handle,1); switch(msg) { case BTN_MOVEIN: break; case BTN_MOVEOUT: break; case BTN_MESSAGESEND: break; case BTN_REDRAW_NOTPRESSED: break; case BTN_REDRAW_PRESSED: break; default: break; } NMBTN_SetInCallBack(Handle,0); } |