#include "Include.h"
/*============================================================================*/
const U32 __HeapSize =4096;
const U32 __StackSize =8192;
const U32 __Priority =200;
const char __Name[32] ="3D 演示";
const U32 __Icon =0;
const char __IconPath[32] =" ";
const char __Version[8] ="V1.0";
const char __Date[16] =__DATE__;
const char __Time[16] =__TIME__;
const char __Desc[32] ="Designeriuwei";
/*============================================================================*/
/* 描述一个3D像素点 */
typedef struct POINT_3D{
int x;
int y;
int z;
//GUI_COLOR color;
}POINT_3D;
/* 描述旋转角度 */
typedef struct _TYPE_ROTATION_ANGLE{
float x;
float y;
float z;
}type_rot_ang;
/* 描述移动位置 */
typedef struct _TYPE_TRANSLATION_DIST{
float x;
float y;
float z;
}type_tran_dis;
/*============================================================================*/
/*============================================================================*/
/* 用户和显示屏的视角关系定义 */
#define USRX 0.0
#define USRY 0.0
#define USRZ 50.9 // OFFSETZ*0.707,1:1比例显示
#define OFFSETX 320
#define OFFSETY 240
#define OFFSETZ 72
void Pixel3dTransform(int x,int y,type_rot_ang *pangle, type_tran_dis *ptrandis, POINT_3D *ppixel, POINT *pt)
{
float sinx,cosx,siny,cosy,sinz,cosz;
float tempx,tempy,tempz;
float dx,dy,dz;
sinx = sin(pangle->x);
cosx = cos(pangle->x);
siny = sin(pangle->y);
cosy = cos(pangle->y);
sinz = sin(pangle->z);
cosz = cos(pangle->z);
dx = ppixel->x;
dy = ppixel->y;
dz = ppixel->z;
tempy = dy*cosx - dz*sinx;
tempz = dy*sinx + dz*cosx;
dy = tempy;
dz = tempz;
tempx = dx*cosy - dz*siny;
tempz = dx*siny + dz*cosy;
dx = tempx;
dz = tempz;
tempx = dx * cosz - dy * sinz;
tempy = dx * sinz + dy * cosz;
dx = tempx;
dy = tempy;
dx = dx + ptrandis->x;
dy = dy + ptrandis->y;
dz = dz - ptrandis->z + OFFSETZ;
pt->x = ((dx-USRX)*(USRZ/dz)) + x;
pt->y = ((dy-USRY)*(USRZ/dz)) + y;
// ppreturn->color = ppixel->color;
}
/*============================================================================*/
/*============================================================================*/
#define IDC_AX_INC 0x1000
#define IDC_AY_INC 0x1001
#define IDC_AZ_INC 0x1002
#define IDC_DX_INC 0x1003
#define IDC_DY_INC 0x1004
#define IDC_DZ_INC 0x1005
#define IDC_AX_DEC 0x1010
#define IDC_AY_DEC 0x1011
#define IDC_AZ_DEC 0x1012
#define IDC_DX_DEC 0x1013
#define IDC_DY_DEC 0x1014
#define IDC_DZ_DEC 0x1015
#define IDC_AUTO 0x1020
#define IDC_RESET 0x1021
type_rot_ang angle;
type_tran_dis pos;
int auto_run;
POINT_3D pt3d[36];
static RESULT WinProc(HWND hwnd,U32 msg,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
HANDLE hfile;
RECT rc,m_rc[14];
char buf[128];
int i,j,k,x,y;
////
switch(msg)
{
case MSG_CREATE:
angle.x = 0.0;
angle.y = 0.0;
angle.z = 0.0;
pos.x = 0.0;
pos.y = 0.0;
pos.z = 0.0;
auto_run =0;
GetClientRect(hwnd,&rc);
x=0;
y=rc.dy-32;
GetMatrixRectangle(m_rc,x,y,rc.dx,32,7,2,4,2);
CreateWindow("button",hwnd,m_rc[0].x,m_rc[0].y,m_rc[0].dx,m_rc[0].dy,0,0,IDC_AX_INC,"ax+");
CreateWindow("button",hwnd,m_rc[1].x,m_rc[1].y,m_rc[1].dx,m_rc[1].dy,0,0,IDC_AY_INC,"ay+");
CreateWindow("button",hwnd,m_rc[2].x,m_rc[2].y,m_rc[2].dx,m_rc[2].dy,0,0,IDC_AZ_INC,"az+");
CreateWindow("button",hwnd,m_rc[3].x,m_rc[3].y,m_rc[3].dx,m_rc[3].dy,0,0,IDC_DX_INC,"dx+");
CreateWindow("button",hwnd,m_rc[4].x,m_rc[4].y,m_rc[4].dx,m_rc[4].dy,0,0,IDC_DY_INC,"dy+");
CreateWindow("button",hwnd,m_rc[5].x,m_rc[5].y,m_rc[5].dx,m_rc[5].dy,0,0,IDC_DZ_INC,"dz+");
CreateWindow("button",hwnd,m_rc[6].x,m_rc[6].y,m_rc[6].dx,m_rc[6].dy,0,0,IDC_AUTO,"Auto");
CreateWindow("button",hwnd,m_rc[7].x,m_rc[7].y,m_rc[7].dx,m_rc[7].dy,0,0,IDC_AX_DEC,"ax-");
CreateWindow("button",hwnd,m_rc[8].x,m_rc[8].y,m_rc[8].dx,m_rc[8].dy,0,0,IDC_AY_DEC,"ay-");
CreateWindow("button",hwnd,m_rc[9].x,m_rc[9].y,m_rc[9].dx,m_rc[9].dy,0,0,IDC_AZ_DEC,"az-");
CreateWindow("button",hwnd,m_rc[10].x,m_rc[10].y,m_rc[10].dx,m_rc[10].dy,0,0,IDC_DX_DEC,"dx-");
CreateWindow("button",hwnd,m_rc[11].x,m_rc[11].y,m_rc[11].dx,m_rc[11].dy,0,0,IDC_DY_DEC,"dy-");
CreateWindow("button",hwnd,m_rc[12].x,m_rc[12].y,m_rc[12].dx,m_rc[12].dy,0,0,IDC_DZ_DEC,"dz-");
CreateWindow("button",hwnd,m_rc[13].x,m_rc[13].y,m_rc[13].dx,m_rc[13].dy,0,0,IDC_RESET,"Reset");
break;
////////
case MSG_COMMAND:
{
U16 code,id;
////
SetRepeated(500,10);
code =HIWORD(wParam);
id =LOWORD(wParam);
switch(id)
{
case IDC_AX_INC:
angle.x+=0.1;
break;
////
case IDC_AY_INC:
angle.y+=0.1;
break;
////
case IDC_AZ_INC:
angle.z+=0.1;
break;
////
case IDC_DX_INC:
pos.x+=0.1;
break;
////
case IDC_DY_INC:
pos.y+=0.1;
break;
////
case IDC_DZ_INC:
pos.z+=0.1;
break;
////
case IDC_AX_DEC:
angle.x-=0.1;
break;
////
case IDC_AY_DEC:
angle.y-=0.1;
break;
////
case IDC_AZ_DEC:
angle.z-=0.1;
break;
////
case IDC_DX_DEC:
pos.x-=0.1;
break;
////
case IDC_DY_DEC:
pos.y-=0.1;
break;
////
case IDC_DZ_DEC:
pos.z-=0.1;
break;
////
case IDC_RESET:
if(code==BN_UP)
{
angle.x =0;
angle.y =0;
angle.z =0;
pos.x =0;
pos.y =0;
pos.z =0;
}
break;
////
case IDC_AUTO:
if(code==BN_UP)
{
if(auto_run==0)
{
auto_run=1;
}
else
{
auto_run=0;
}
}
break;
////
}
InvalidateRect(hwnd,0,0);
}
break;
////////
case MSG_TIMER:
if(auto_run==1)
{
angle.x += 0.07;
angle.y += 0.1;
angle.z += 0.05;
InvalidateRect(hwnd,0,0);
}
break;
////////
case MSG_PAINT:
hdc=BeginPaint(hwnd);
GetClientRect(hwnd,&rc);
FillRectangle(hdc,0,0,rc.dx,rc.dy-32,RGB(0,0,0));
k = 0;
for(i=0;i<6;i++)
{
for(j=0; j<6; j++)
{
pt3d[k].x = j*12 - 20;
pt3d[k].y = 0;
pt3d[k].z = i*12 - 20;
k++;
}
}
for(i=0; i<36; i++)
{
POINT pt;
Pixel3dTransform(rc.dx>>1,(rc.dy-32)>>1,&angle, &pos, &pt3d, &pt);
Circle(hdc,pt.x, pt.y,4,RAND_RGB(0xff,0xff,0xff));
}
////
x=2;
y=2;
StrPrintf(buf,"ax=%.1f, ay=%.1f, az=%.1f",angle.x,angle.y,angle.z);
TextOut(hdc,x,y,RGB(200,0,0),RGB_TRANS,buf);
y+=16;
StrPrintf(buf,"dx=%.1f, dy=%.1f, dz=%.1f",pos.x,pos.y,pos.z);
TextOut(hdc,x,y,RGB(200,0,0),RGB_TRANS,buf);
EndPaint(hwnd,hdc);
break;
////////
default:
return DefaultWindowProc(hwnd,msg,wParam,lParam);
}
return 0;
}
/*============================================================================*/
void main(void)
{
HWND hwnd;
HANDLE hTimer0;
////
// CreateThread(thread0,0,1024,200,0);
hwnd =CreateMainWindow( 80,40,320,240,
RGB(160,160,160),
WS_CAPTION|WS_BORDER_DUAL,
0,
WinProc,
(char*)__Name);
ShowWindow(hwnd,SW_SHOW);
hTimer0=SetTimer(hwnd,0x3000,50,0);
WindowMessageLoop(hwnd);
KillTimer(hTimer0);
DestroyMainWindow(hwnd);
}
|