Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {//обработчик сообщений
- PAINTSTRUCT ps;
- static HBRUSH hBrush;
- class TFPoint{
- public:
- float X;
- float Y;
- float Z;
- };
- TFPoint CubePoints[]={
- {-50, -50, -50},
- {50, -50, -50},
- {50, 50, -50},
- {-50, 50, -50},
- {-50, 50, 50},
- {-50, -50, 50},
- {50, -50, 50},
- {50, 50, 50}
- };
- int Gran[6][4]={
- {0, 3, 4, 5},
- {0, 5, 6, 1},
- {2, 7, 4, 3},
- {7, 6, 5, 4},
- {0, 1, 2, 3},
- {2, 1, 6, 7}
- };
- POINT point1[4];
- HDC hdc;
- int sx, sy, xPos, yPos, zDelta;
- switch (message)
- {
- case WM_MOUSEMOVE:
- sx = LOWORD(lParam);
- sy = HIWORD(lParam);
- thetta+=((sx%180)-90)/10;
- phi+=((sy%180)-90)/10;
- InvalidateRect(hWnd, NULL, TRUE);
- break;
- case WM_MOUSEWHEEL:
- zDelta=(int) wParam;
- ScreenDist-=zDelta/1000000.;
- InvalidateRect(hWnd, NULL, TRUE);
- break;
- case WM_SIZE:
- sx = LOWORD(lParam);//Ширина
- sy = HIWORD(lParam);//Высота
- break;
- case WM_PAINT:
- hBrush = CreateSolidBrush(RGB(255, 0, 0)); // Создание кисти
- hdc = BeginPaint(hWnd, &ps);//Установка режима
- th=thetta*factor;
- ph=phi*factor;
- costh=cos(th);
- sinth=sin(th);
- cosph=cos(ph);
- sinph=sin(ph);
- A=rho*sinph*costh; B=rho*sinph*sinth; C=rho*cosph;
- Al=A/(sqrt(A*A+B*B+C*C));
- Bl=B/(sqrt(A*A+B*B+C*C));
- Cl=C/(sqrt(A*A+B*B+C*C));
- for(int i = 0; i<6; i++){
- for(int j=0; j<3; j++){
- xt[j]=CubePoints[Gran[i][j]].X;
- yt[j]=CubePoints[Gran[i][j]].Y;
- zt[j]=CubePoints[Gran[i][j]].Z;
- }
- A = yt[0]*(zt[1]-zt[2])-yt[1]*(zt[0]-zt[2])+yt[2]*(zt[0]-zt[1]);
- B =-(xt[0]*(zt[1]-zt[2])-xt[1]*(zt[0]-zt[2])+xt[2]*(zt[0]-zt[1]));
- C = xt[0]*(yt[1]-yt[2])-xt[1]*(yt[0]-yt[2])+xt[2]*(yt[0]-yt[1]);
- An = A/(sqrt(A*A+B*B+C*C));
- Bn = B/(sqrt(A*A+B*B+C*C));
- Cn = C/(sqrt(A*A+B*B+C*C));
- alpha=(An*Al+Bn*Bl+Cn*Cl);
- for(int j=0; j<4; j++){
- point1[j]=Perspective(CubePoints[Gran[i][j]].X,
- CubePoints[Gran[i][j]].Y,
- CubePoints[Gran[i][j]].Z);
- }
- D = point1[0].x*(point1[1].y-point1[2].y)-
- point1[1].x*(point1[0].y-point1[2].y)+
- point1[2].x*(point1[0].y-point1[1].y);
- if (D<0){
- hBrush = CreateSolidBrush(RGB((1-alpha)*255,
- (1-alpha)*255,(1-alpha)*255));
- SelectObject(hdc,hBrush);
- Polygon(hdc,point1,4);
- }
- }
- EndPaint(hWnd, &ps);
- break;
- case WM_DESTROY:PostQuitMessage(0);
- break;
- default:return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0;
- }
- // Обработчик сообщений для окна "О программе".
- INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- UNREFERENCED_PARAMETER(lParam);
- switch (message)
- {
- case WM_INITDIALOG:
- return (INT_PTR)TRUE;
- case WM_COMMAND:
- if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
- {
- EndDialog(hDlg, LOWORD(wParam));
- return (INT_PTR)TRUE;
- }
- break;
- }
- return (INT_PTR)FALSE;
- }
Add Comment
Please, Sign In to add comment