1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
| #include <windows.h>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#pragma comment (lib, "user32.lib")
#pragma comment (lib, "kernel32.lib")
#pragma comment (lib, "gdi32.lib")
#define MAX_LOADSTRING 100
using namespace std;
// Global Variables:
HINSTANCE hInst; // current instance
char szTitle[MAX_LOADSTRING]; // The title bar text
char szWindowClass[MAX_LOADSTRING]; // the main window class name
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
class Vertex
{
public:
Vertex();
~Vertex();
float x,y,z,w;
};
Vertex::Vertex()
{
w = 1;
}
Vertex::~Vertex()
{
}
Vertex matCalc(float m[4][4], Vertex tempVertex)
{
Vertex vertex;
vertex.x=m[0][0]*tempVertex.x + m[0][1]*tempVertex.y + m[0][2]*tempVertex.z + m[0][3]*tempVertex.w;
vertex.y=m[1][0]*tempVertex.x + m[1][1]*tempVertex.y + m[1][2]*tempVertex.z + m[1][3]*tempVertex.w;
vertex.z=m[2][0]*tempVertex.x + m[2][1]*tempVertex.y + m[2][2]*tempVertex.z + m[2][3]*tempVertex.w;
return vertex;
}
class Matrix
{
public:
Matrix();
~Matrix();
Vertex TMatrix(Vertex vertex);
Vertex VMatrix(Vertex vertex);
Vertex PMatrix(Vertex vertex);
float m[4][4];
};
Matrix::Matrix()
{
}
Matrix::~Matrix()
{
}
Vertex Matrix::TMatrix(Vertex tempVertex)
{
Matrix _Matrix;
_Matrix.m[0][0]=5;
_Matrix.m[0][1]=0;
_Matrix.m[0][2]=0;
_Matrix.m[0][3]=5;
_Matrix.m[1][0]=0;
_Matrix.m[1][1]=0;
_Matrix.m[1][2]=-5;
_Matrix.m[1][3]=-5;
_Matrix.m[2][0]=0;
_Matrix.m[2][1]=5;
_Matrix.m[2][2]=0;
_Matrix.m[2][3]=5;
_Matrix.m[3][0]=0;
_Matrix.m[3][1]=0;
_Matrix.m[3][2]=0;
_Matrix.m[3][3]=1;
Vertex vertex=matCalc(_Matrix.m,tempVertex);
return vertex;
}
Vertex Matrix::VMatrix(Vertex tempVertex)
{
Matrix _Matrix;
_Matrix.m[0][0]=1;
_Matrix.m[0][1]=0;
_Matrix.m[0][2]=0;
_Matrix.m[0][3]=0;
_Matrix.m[1][0]=0;
_Matrix.m[1][1]=-1;
_Matrix.m[1][2]=0;
_Matrix.m[1][3]=0;
_Matrix.m[2][0]=0;
_Matrix.m[2][1]=0;
_Matrix.m[2][2]=-1;
_Matrix.m[2][3]=0;
_Matrix.m[3][0]=0;
_Matrix.m[3][1]=0;
_Matrix.m[3][2]=0;
_Matrix.m[3][3]=1;
Vertex vertex=matCalc(_Matrix.m,tempVertex);
return vertex;
}
Vertex Matrix::PMatrix(Vertex tempVertex)
{
Matrix _Matrix;
_Matrix.m[0][0]=5;
_Matrix.m[0][1]=0;
_Matrix.m[0][2]=0;
_Matrix.m[0][3]=0;
_Matrix.m[1][0]=0;
_Matrix.m[1][1]=5;
_Matrix.m[1][2]=0;
_Matrix.m[1][3]=0;
_Matrix.m[2][0]=0;
_Matrix.m[2][1]=0;
_Matrix.m[2][2]=0;
_Matrix.m[2][3]=0;
_Matrix.m[3][0]=0;
_Matrix.m[3][1]=0;
_Matrix.m[3][2]=0;
_Matrix.m[3][3]=1;
Vertex vertex=matCalc(_Matrix.m,tempVertex);
return vertex;
}
const int size_to_read=50;
int fchoose[10000][3];
char buffer[size_to_read];
float readX[10000];
float readY[10000];
float readZ[10000];
char op='v';
int vcount=0;
int wmId, wmEvent;
float x[3],y[3];
Matrix matrixx;
Vertex myVertex[3];
int i=0;
int fcount=0;
POINT Pt[4];
DWORD lpPts[] = { 4};
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
ifstream infile("tie_fighter.obj", ifstream::in);
while(!infile.eof())
{
infile.getline(buffer, size_to_read);
istringstream iss(buffer, istringstream::in);
iss>>op;
if (op=='v')
{
iss>>readX[vcount]>>readY[vcount]>>readZ[vcount];
vcount++;
}
else if (op=='f')
{
iss>>fchoose[fcount][0]>>fchoose[fcount][1]>>fchoose[fcount][2];
fcount++;
}
}
infile.close();
MSG msg;
MyRegisterClass(hInstance);
if (!InitInstance (hInstance, nCmdShow))
return FALSE;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = "menu";
wcex.lpszClassName = "class";
wcex.hIconSm = NULL;
return RegisterClassEx(&wcex);
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance;
hWnd = CreateWindow("class", "title", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
return FALSE;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
for (int j=0;j<fcount-1;j++)
{
for (int i=0;i<3;i++)
{
int a=fchoose[j][i]-1;
myVertex[i].x=readX[a];
myVertex[i].y=readY[a];
myVertex[i].z=readZ[a];
//myVertex[i].z=readZ[fchoose[j][i]-1];
myVertex[i]=matrixx.TMatrix(myVertex[i]);
myVertex[i]=matrixx.VMatrix(myVertex[i]);
myVertex[i]=matrixx.PMatrix(myVertex[i]);
x[i]=myVertex[i].x;
y[i]=myVertex[i].y;
}
Pt[0].x = x[0];
Pt[0].y = y[0];
Pt[1].x = x[1];
Pt[1].y = y[1];
Pt[2].x = x[2];
Pt[2].y = y[2];
Pt[3].x = x[0];
Pt[3].y = y[0];
PolyPolyline(hdc, Pt, lpPts, 1);
//InvalidateRect(hWnd, 0, false);
}
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
} |