Created
December 1, 2013 19:41
-
-
Save yakreved/7739849 to your computer and use it in GitHub Desktop.
kg lab 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include "графика 5.h" | |
#include <math.h> | |
#include "Resource.h" | |
#include<stdio.h> | |
int key1 = 0, key2 = 0, f = 0, o = 0, R = 0; | |
#define PI 3.14159265 | |
char fa[10] = " ", Ra[10] = " ", oa[10] = " "; | |
void Draw(int[12][4], HDC); | |
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) | |
{ | |
int i, j, u, Q[12][4], P[12][4]; | |
float M[4][4]; | |
int wmId, wmEvent; | |
PAINTSTRUCT ps; | |
HDC hdc, memdc; | |
HWND hWnd; | |
HWND edit1 = GetDlgItem(hDlg, IDC_EDIT1); | |
HWND edit2 = GetDlgItem(hDlg, IDC_EDIT2); | |
HWND edit3 = GetDlgItem(hDlg, IDC_EDIT3); | |
UNREFERENCED_PARAMETER(lParam); | |
HINSTANCE hInst; | |
Q[0][0] = 30; Q[0][1] = 30; Q[0][2] = 30; Q[0][3] = 1; | |
Q[1][0] = 50; Q[1][1] = 30; Q[1][2] = 10; Q[1][3] = 1; | |
Q[2][0] = 70; Q[2][1] = 30; Q[2][2] = 10; Q[2][3] = 1; | |
Q[3][0] = 90; Q[3][1] = 30; Q[3][2] = 30; Q[3][3] = 1; | |
Q[4][0] = 70; Q[4][1] = 30; Q[4][2] = 50; Q[4][3] = 1; | |
Q[5][0] = 50; Q[5][1] = 30; Q[5][2] = 50; Q[5][3] = 1; | |
Q[6][0] = 60; Q[6][1] = 60; Q[6][2] = 30; Q[6][3] = 1; | |
switch (message) | |
{ | |
case WM_COMMAND: | |
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) | |
{ | |
EndDialog(hDlg, LOWORD(wParam)); | |
return (INT_PTR)TRUE; | |
} | |
wmId = LOWORD(wParam); | |
wmEvent = HIWORD(wParam); | |
switch (wmId) | |
{ | |
case IDC_BUT1: | |
R = 0; f = 0; o = 0; | |
SendMessage(edit1, EM_GETLINE, 0, (LPARAM)oa); | |
SendMessage(edit2, EM_GETLINE, 0, (LPARAM)fa); | |
SendMessage(edit3, EM_GETLINE, 0, (LPARAM)Ra); | |
i = 0; j = 0; u = 1; | |
while (oa[i] != ' ' && oa[i] != '\n' && oa[i] != '\0') | |
{ | |
if (j>0)u = 10; | |
o = o*u + atoi(&oa[i]); i = i + 2; j++; | |
} | |
i = 0; j = 0; u = 1; | |
while (fa[i] != ' ' && fa[i] != '\n' && fa[i] != '\0') | |
{ | |
if (j>0)u = 10; | |
f = f*u + atoi(&fa[i]); i = i + 2; j++; | |
} | |
i = 0; j = 0; u = 1; | |
while (Ra[i] != ' ' && Ra[i] != '\n' && Ra[i] != '\0') | |
{ | |
if (j>0)u = 10; | |
R = R*u + atoi(&Ra[i]); i = i + 2; j++; | |
} | |
M[0][0] = -sin(o*PI / 180); M[0][1] = -cos(f*PI / 180)*cos(o*PI / 180); M[0][2] = -sin(f*PI / 180)*cos(o*PI / 180); M[0][3] = 0; | |
M[1][0] = cos(o*PI / 180); M[1][1] = -cos(f*PI / 180)*sin(o*PI / 180); M[1][2] = -sin(f*PI / 180)*sin(o*PI / 180); M[1][3] = 0; | |
M[2][0] = 0; M[2][1] = sin(f*PI / 180); M[2][2] = -cos(f*PI / 180); M[2][3] = 0; | |
M[3][0] = 0; M[3][1] = 0; M[3][2] = R; M[3][3] = 0; | |
if (key1 == 0)key1 = 1; | |
for (u = 0; u<12; u++) | |
for (i = 0; i<4; i++) | |
{ | |
P[u][i] = 0; | |
for (j = 0; j<4; j++) | |
P[u][i] = P[u][i] + Q[u][j] * M[j][i]; | |
} | |
UpdateWindow(hDlg); InvalidateRect(hDlg, NULL, true); | |
break; | |
case IDC_BUT2: | |
if (key2 == 0)key2 = 1; | |
else if (key2 == 1)key2 = 0; | |
InvalidateRect(hDlg, NULL, true); | |
break; | |
break; | |
} | |
case WM_PAINT: | |
hdc = BeginPaint(hDlg, &ps); | |
TextOut(hdc, 440, 20, L"A", 1); | |
TextOut(hdc, 440, 60, L"B", 1); | |
TextOut(hdc, 440, 100, L"R", 1); | |
if (key1 == 1) | |
{ | |
key1 = 0; | |
Draw(P, hdc); | |
} | |
if (key2 == 1) | |
{ | |
Draw(Q, hdc); | |
} | |
EndPaint(hDlg, &ps); | |
break; | |
case WM_DESTROY: | |
PostQuitMessage(0); | |
break; | |
} | |
return 0; | |
} | |
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) | |
{ | |
DialogBox(hInstance, MAKEINTRESOURCE(IDD_ABOUTBOX), 0, About); | |
return 1; | |
} | |
void Draw(int mas[12][4], HDC hdc) | |
{ | |
int offset1 = 100; | |
MoveToEx(hdc, mas[0][0] + 300, mas[0][2] + offset1, 0); | |
LineTo(hdc, mas[1][0] + 300, mas[1][2] + offset1); | |
LineTo(hdc, mas[2][0] + 300, mas[2][2] + offset1); | |
LineTo(hdc, mas[3][0] + 300, mas[3][2] + offset1); | |
LineTo(hdc, mas[4][0] + 300, mas[4][2] + offset1); | |
LineTo(hdc, mas[5][0] + 300, mas[5][2] + offset1); | |
LineTo(hdc, mas[0][0] + 300, mas[0][2] + offset1); | |
LineTo(hdc, mas[6][0] + 300, mas[6][2] + offset1); | |
MoveToEx(hdc, mas[6][0] + 300, mas[6][2] + offset1, 0); | |
LineTo(hdc, mas[1][0] + 300, mas[1][2] + offset1); | |
MoveToEx(hdc, mas[6][0] + 300, mas[6][2] + offset1, 0); | |
LineTo(hdc, mas[2][0] + 300, mas[2][2] + offset1); | |
MoveToEx(hdc, mas[6][0] + 300, mas[6][2] + offset1, 0); | |
LineTo(hdc, mas[3][0] + 300, mas[3][2] + offset1); | |
MoveToEx(hdc, mas[6][0] + 300, mas[6][2] + offset1, 0); | |
LineTo(hdc, mas[4][0] + 300, mas[4][2] + offset1); | |
MoveToEx(hdc, mas[6][0] + 300, mas[6][2] + offset1, 0); | |
LineTo(hdc, mas[5][0] + 300, mas[5][2] + offset1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment