00001
00002
00003
00004
00005
00006
00007 #include <windows.h>
00008 #include "shared.h"
00009 #include "vector.h"
00010 #include "vertex.h"
00011 #include "quat.h"
00012 #include "matrix.h"
00013 #include "texture.h"
00014 #include "general.h"
00015 #include "object.h"
00016 #include "camera.h"
00017 #include "polygon.h"
00018 #include "locmath.h"
00019 #include "console.h"
00020 #include "log.h"
00021 #include "mmgr.h"
00022 #include "resource.rh"
00023
00024
00025 float pi = 3.141592;
00026 float radians = pi / 180;
00027
00028
00029 COLORREF colorRGB;
00030 RECT MainRect;
00031 LOGFONT LogFont;
00032 HFONT hFont;
00033 HFONT hOldFont;
00034
00035
00036 TEXTURE* texture = new TEXTURE[1];
00037
00038
00039 VERTEX* vertex = new VERTEX[8];
00040
00041
00042 POLYGON* polygon = new POLYGON[12];
00043
00044 char g_szMainClassName[] = "MainWindow";
00045 char g_szChild3DClassName[] = "3DOpenGL";
00046 char g_szChild2DClassName[] = "2DOpenGL";
00047 HINSTANCE g_hInst;
00048 HWND g_hMDIClient;
00049 HWND g_hMainWindow;
00050 RECT g_rectChild;
00051
00052 float g_fCubeRotationX, g_fCubeRotationY;
00053 float Zoom = 0.025;
00054 bool key[256];
00055 bool released_key[256];
00056 int VerticalShift = 0;
00057 int HorizontalShift = 0;
00058 bool g_bMouseDrag = 0;
00059 int g_iMouseLastX;
00060 int g_iMouseLastY;
00061 int g_iMouseDeltaX;
00062 int g_iMouseDeltaY;
00063 int VertexNumber;
00064 int ShortestDistance = 10000;
00065 int MouseX;
00066 int MouseY;
00067 float FrontDepth = 90;
00068 float TopDepth = -90;
00069 float LeftDepth = -90;
00070 GLUquadricObj * sphere = gluNewQuadric();
00071
00072 bool g_bMouseDrag2 = 0;
00073 int g_iMouseLastX2;
00074 int g_iMouseLastY2;
00075 int g_iMouseDeltaX2;
00076 int g_iMouseDeltaY2;
00077
00078 typedef struct CHILD
00079 {
00080 int iType;
00081 HDC hDC;
00082 HGLRC hRC;
00083 HWND hWnd;
00084 } CHILD;
00085
00086 int g_iMaxChild = 50;
00087 int g_iNumChild = 0;
00088 CHILD* g_child = new CHILD[g_iMaxChild];
00089
00090 void SetTextures()
00091 {
00092 sprintf(texture[0].TexName, "%s", "tile1.tga");
00093 texture[0].LoadTGA();
00094 }
00095
00096 void SetVertices()
00097 {
00098
00099
00100 vertex[0].x = -100;
00101 vertex[0].y = -100;
00102 vertex[0].z = 100;
00103
00104 vertex[1].x = 100;
00105 vertex[1].y = -100;
00106 vertex[1].z = 100;
00107
00108 vertex[2].x = 100;
00109 vertex[2].y = 100;
00110 vertex[2].z = 100;
00111
00112 vertex[3].x = -100;
00113 vertex[3].y = 100;
00114 vertex[3].z = 100;
00115
00116 vertex[4].x = -100;
00117 vertex[4].y = -100;
00118 vertex[4].z = -100;
00119
00120 vertex[5].x = 100;
00121 vertex[5].y = -100;
00122 vertex[5].z = -100;
00123
00124 vertex[6].x = 100;
00125 vertex[6].y = 100;
00126 vertex[6].z = -100;
00127
00128 vertex[7].x = -100;
00129 vertex[7].y = 100;
00130 vertex[7].z = -100;
00131 }
00132
00133 void SetPolygons()
00134 {
00135
00136
00137
00138 polygon[0].Vertex[0] = vertex[0];
00139 polygon[0].Vertex[1] = vertex[1];
00140 polygon[0].Vertex[2] = vertex[2];
00141
00142 polygon[1].Vertex[0] = vertex[0];
00143 polygon[1].Vertex[1] = vertex[2];
00144 polygon[1].Vertex[2] = vertex[3];
00145
00146 polygon[2].Vertex[0] = vertex[5];
00147 polygon[2].Vertex[1] = vertex[4];
00148 polygon[2].Vertex[2] = vertex[7];
00149
00150 polygon[3].Vertex[0] = vertex[5];
00151 polygon[3].Vertex[1] = vertex[7];
00152 polygon[3].Vertex[2] = vertex[6];
00153
00154 polygon[4].Vertex[0] = vertex[4];
00155 polygon[4].Vertex[1] = vertex[0];
00156 polygon[4].Vertex[2] = vertex[3];
00157
00158 polygon[5].Vertex[0] = vertex[4];
00159 polygon[5].Vertex[1] = vertex[3];
00160 polygon[5].Vertex[2] = vertex[7];
00161
00162 polygon[6].Vertex[0] = vertex[1];
00163 polygon[6].Vertex[1] = vertex[5];
00164 polygon[6].Vertex[2] = vertex[6];
00165
00166 polygon[7].Vertex[0] = vertex[1];
00167 polygon[7].Vertex[1] = vertex[6];
00168 polygon[7].Vertex[2] = vertex[2];
00169
00170 polygon[8].Vertex[0] = vertex[3];
00171 polygon[8].Vertex[1] = vertex[2];
00172 polygon[8].Vertex[2] = vertex[6];
00173
00174 polygon[9].Vertex[0] = vertex[3];
00175 polygon[9].Vertex[1] = vertex[6];
00176 polygon[9].Vertex[2] = vertex[7];
00177
00178 polygon[10].Vertex[0] = vertex[5];
00179 polygon[10].Vertex[1] = vertex[1];
00180 polygon[10].Vertex[2] = vertex[0];
00181
00182 polygon[11].Vertex[0] = vertex[5];
00183 polygon[11].Vertex[1] = vertex[0];
00184 polygon[11].Vertex[2] = vertex[4];
00185
00186 polygon[0].SetNormal();
00187 polygon[1].SetNormal();
00188 polygon[2].SetNormal();
00189 polygon[3].SetNormal();
00190 polygon[4].SetNormal();
00191 polygon[5].SetNormal();
00192 polygon[6].SetNormal();
00193 polygon[7].SetNormal();
00194 polygon[8].SetNormal();
00195 polygon[9].SetNormal();
00196 polygon[10].SetNormal();
00197 polygon[11].SetNormal();
00198 }
00199
00200
00201 void InitGL()
00202 {
00203 glCullFace(GL_BACK);
00204 glEnable(GL_CULL_FACE);
00205 glClearColor(0.0, 0.0, 0.0, 0.0);
00206 glClearDepth(1.0);
00207 glDepthFunc(GL_LESS);
00208 glEnable(GL_DEPTH_TEST);
00209 glShadeModel(GL_SMOOTH);
00210 glEnable(GL_NORMALIZE);
00211
00212 float fMatAmbient[] = {0.8, 0.8, 0.8, 1.0};
00213 float fMatDiffuse[] = {0.8, 0.8, 0.8, 1.0};
00214 float fMatSpecular[] = {0.9, 0.9, 0.9, 1.0};
00215 float fMatEmmision[] = {0.0, 0.0, 0.0, 1.0};
00216 float fMatShininess[] = {100.0};
00217
00218 glMaterialfv(GL_FRONT, GL_AMBIENT, fMatAmbient);
00219 glMaterialfv(GL_FRONT, GL_DIFFUSE, fMatDiffuse);
00220 glMaterialfv(GL_FRONT, GL_SPECULAR, fMatSpecular);
00221 glMaterialfv(GL_FRONT, GL_EMISSION, fMatEmmision);
00222 glMaterialfv(GL_FRONT, GL_SHININESS, fMatShininess);
00223
00224 float fLightAmbient[] = {0.2, 0.2, 0.2, 1.0};
00225 glLightfv(GL_LIGHT0, GL_AMBIENT, fLightAmbient);
00226 float fLightPosition[] = {200.0, 0.0, 0.0, 1.0};
00227 glLightfv(GL_LIGHT0, GL_POSITION, fLightPosition);
00228
00229 glEnable(GL_LIGHTING);
00230 glEnable(GL_LIGHT0);
00231
00232 SetTextures();
00233
00234 glEnable(GL_TEXTURE_2D);
00235 }
00236
00237
00238 void Set3DProjection(int iWidth, int iHeight)
00239 {
00240 if(iHeight == 0)
00241 {
00242 iHeight = 1;
00243 }
00244 glViewport(0, 0, iWidth, iHeight);
00245 glMatrixMode(GL_PROJECTION);
00246 glLoadIdentity();
00247 gluPerspective(45.0,(float)iWidth/(float)iHeight, 1, 1000.0);
00248 }
00249
00250
00251 void Set2DProjection(int iWidth, int iHeight)
00252 {
00253 if(iHeight == 0)
00254 {
00255 iHeight = 1;
00256 }
00257 glViewport(0, 0, iWidth, iHeight);
00258 glMatrixMode(GL_PROJECTION);
00259 glLoadIdentity();
00260 glOrtho(-iWidth * 0.5, iWidth * 0.5, -iHeight * 0.5, iHeight * 0.5, -2000, 2000);
00261 }
00262
00263 void Draw3DScene(void)
00264 {
00265 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00266 glMatrixMode(GL_MODELVIEW);
00267 glLoadIdentity();
00268
00269 if(g_bMouseDrag)
00270 {
00271 g_fCubeRotationX += (float)g_iMouseDeltaY * 0.5;
00272 g_fCubeRotationY += (float)g_iMouseDeltaX * 0.5;
00273 }
00274
00275 glTranslatef(0.0,0.0,-500.0);
00276 glRotatef(g_fCubeRotationX,1.0,0.0,0.0);
00277 glRotatef(g_fCubeRotationY,0.0,1.0,0.0);
00278
00279 glBindTexture(GL_TEXTURE_2D, texture[0].TexID);
00280 glPushMatrix();
00281 glBegin(GL_TRIANGLES);
00282
00283 glNormal3fv(&polygon[0].Vertex[0].nx);
00284 glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[0].Vertex[0].x);
00285 glTexCoord2f(1.0f, 0.0f); glVertex3fv(&polygon[0].Vertex[1].x);
00286 glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[0].Vertex[2].x);
00287
00288 glNormal3fv(&polygon[1].Vertex[0].nx);
00289 glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[1].Vertex[0].x);
00290 glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[1].Vertex[1].x);
00291 glTexCoord2f(0.0f, 1.0f); glVertex3fv(&polygon[1].Vertex[2].x);
00292
00293 glNormal3fv(&polygon[2].Vertex[0].nx);
00294 glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[2].Vertex[0].x);
00295 glTexCoord2f(1.0f, 0.0f); glVertex3fv(&polygon[2].Vertex[1].x);
00296 glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[2].Vertex[2].x);
00297
00298 glNormal3fv(&polygon[3].Vertex[0].nx);
00299 glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[3].Vertex[0].x);
00300 glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[3].Vertex[1].x);
00301 glTexCoord2f(0.0f, 1.0f); glVertex3fv(&polygon[3].Vertex[2].x);
00302
00303 glNormal3fv(&polygon[4].Vertex[0].nx);
00304 glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[4].Vertex[0].x);
00305 glTexCoord2f(1.0f, 0.0f); glVertex3fv(&polygon[4].Vertex[1].x);
00306 glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[4].Vertex[2].x);
00307
00308 glNormal3fv(&polygon[5].Vertex[0].nx);
00309 glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[5].Vertex[0].x);
00310 glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[5].Vertex[1].x);
00311 glTexCoord2f(0.0f, 1.0f); glVertex3fv(&polygon[5].Vertex[2].x);
00312
00313 glNormal3fv(&polygon[6].Vertex[0].nx);
00314 glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[6].Vertex[0].x);
00315 glTexCoord2f(1.0f, 0.0f); glVertex3fv(&polygon[6].Vertex[1].x);
00316 glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[6].Vertex[2].x);
00317
00318 glNormal3fv(&polygon[7].Vertex[0].nx);
00319 glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[7].Vertex[0].x);
00320 glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[7].Vertex[1].x);
00321 glTexCoord2f(0.0f, 1.0f); glVertex3fv(&polygon[7].Vertex[2].x);
00322
00323 glNormal3fv(&polygon[8].Vertex[0].nx);
00324 glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[8].Vertex[0].x);
00325 glTexCoord2f(1.0f, 0.0f); glVertex3fv(&polygon[8].Vertex[1].x);
00326 glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[8].Vertex[2].x);
00327
00328 glNormal3fv(&polygon[9].Vertex[0].nx);
00329 glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[9].Vertex[0].x);
00330 glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[9].Vertex[1].x);
00331 glTexCoord2f(0.0f, 1.0f); glVertex3fv(&polygon[9].Vertex[2].x);
00332
00333 glNormal3fv(&polygon[10].Vertex[0].nx);
00334 glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[10].Vertex[0].x);
00335 glTexCoord2f(1.0f, 0.0f); glVertex3fv(&polygon[10].Vertex[1].x);
00336 glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[10].Vertex[2].x);
00337
00338 glNormal3fv(&polygon[11].Vertex[0].nx);
00339 glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[11].Vertex[0].x);
00340 glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[11].Vertex[1].x);
00341 glTexCoord2f(0.0f, 1.0f); glVertex3fv(&polygon[11].Vertex[2].x);
00342 glEnd();
00343 glPopMatrix();
00344 }
00345
00346 void Draw2DSceneFront(HWND hWnd)
00347 {
00348 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00349 glMatrixMode(GL_MODELVIEW);
00350 glLoadIdentity();
00351 RECT WindowRect;
00352 GetClientRect(hWnd, &WindowRect);
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378 glDisable(GL_TEXTURE_2D);
00379 glDisable(GL_LIGHTING);
00380 glColor4f(1.0, 0.0, 0.0, 1.0);
00381 glPushMatrix();
00382 glBegin(GL_LINES);
00383
00384 glNormal3fv(&polygon[0].Vertex[0].nx);
00385 glVertex3fv(&polygon[0].Vertex[0].x);
00386 glVertex3fv(&polygon[0].Vertex[1].x);
00387 glVertex3fv(&polygon[0].Vertex[1].x);
00388 glVertex3fv(&polygon[0].Vertex[2].x);
00389 glVertex3fv(&polygon[0].Vertex[2].x);
00390 glVertex3fv(&polygon[0].Vertex[0].x);
00391
00392 glVertex3fv(&polygon[1].Vertex[0].x);
00393 glVertex3fv(&polygon[1].Vertex[1].x);
00394 glVertex3fv(&polygon[1].Vertex[1].x);
00395 glVertex3fv(&polygon[1].Vertex[2].x);
00396 glVertex3fv(&polygon[1].Vertex[2].x);
00397 glVertex3fv(&polygon[1].Vertex[0].x);
00398
00399 glNormal3fv(&polygon[2].Vertex[0].nx);
00400 glVertex3fv(&polygon[2].Vertex[0].x);
00401 glVertex3fv(&polygon[2].Vertex[1].x);
00402 glVertex3fv(&polygon[2].Vertex[1].x);
00403 glVertex3fv(&polygon[2].Vertex[2].x);
00404 glVertex3fv(&polygon[2].Vertex[2].x);
00405 glVertex3fv(&polygon[2].Vertex[0].x);
00406
00407 glVertex3fv(&polygon[3].Vertex[0].x);
00408 glVertex3fv(&polygon[3].Vertex[1].x);
00409 glVertex3fv(&polygon[3].Vertex[1].x);
00410 glVertex3fv(&polygon[3].Vertex[2].x);
00411 glVertex3fv(&polygon[3].Vertex[2].x);
00412 glVertex3fv(&polygon[3].Vertex[0].x);
00413
00414 glNormal3fv(&polygon[4].Vertex[0].nx);
00415 glVertex3fv(&polygon[4].Vertex[0].x);
00416 glVertex3fv(&polygon[4].Vertex[1].x);
00417 glVertex3fv(&polygon[4].Vertex[1].x);
00418 glVertex3fv(&polygon[4].Vertex[2].x);
00419 glVertex3fv(&polygon[4].Vertex[2].x);
00420 glVertex3fv(&polygon[4].Vertex[0].x);
00421
00422 glVertex3fv(&polygon[5].Vertex[0].x);
00423 glVertex3fv(&polygon[5].Vertex[1].x);
00424 glVertex3fv(&polygon[5].Vertex[1].x);
00425 glVertex3fv(&polygon[5].Vertex[2].x);
00426 glVertex3fv(&polygon[5].Vertex[2].x);
00427 glVertex3fv(&polygon[5].Vertex[0].x);
00428
00429 glNormal3fv(&polygon[6].Vertex[0].nx);
00430 glVertex3fv(&polygon[6].Vertex[0].x);
00431 glVertex3fv(&polygon[6].Vertex[1].x);
00432 glVertex3fv(&polygon[6].Vertex[1].x);
00433 glVertex3fv(&polygon[6].Vertex[2].x);
00434 glVertex3fv(&polygon[6].Vertex[2].x);
00435 glVertex3fv(&polygon[6].Vertex[0].x);
00436
00437 glVertex3fv(&polygon[7].Vertex[0].x);
00438 glVertex3fv(&polygon[7].Vertex[1].x);
00439 glVertex3fv(&polygon[7].Vertex[1].x);
00440 glVertex3fv(&polygon[7].Vertex[2].x);
00441 glVertex3fv(&polygon[7].Vertex[2].x);
00442 glVertex3fv(&polygon[7].Vertex[0].x);
00443
00444 glNormal3fv(&polygon[8].Vertex[0].nx);
00445 glVertex3fv(&polygon[8].Vertex[0].x);
00446 glVertex3fv(&polygon[8].Vertex[1].x);
00447 glVertex3fv(&polygon[8].Vertex[1].x);
00448 glVertex3fv(&polygon[8].Vertex[2].x);
00449 glVertex3fv(&polygon[8].Vertex[2].x);
00450 glVertex3fv(&polygon[8].Vertex[0].x);
00451
00452 glVertex3fv(&polygon[9].Vertex[0].x);
00453 glVertex3fv(&polygon[9].Vertex[1].x);
00454 glVertex3fv(&polygon[9].Vertex[1].x);
00455 glVertex3fv(&polygon[9].Vertex[2].x);
00456 glVertex3fv(&polygon[9].Vertex[2].x);
00457 glVertex3fv(&polygon[9].Vertex[0].x);
00458
00459 glNormal3fv(&polygon[10].Vertex[0].nx);
00460 glVertex3fv(&polygon[10].Vertex[0].x);
00461 glVertex3fv(&polygon[10].Vertex[1].x);
00462 glVertex3fv(&polygon[10].Vertex[1].x);
00463 glVertex3fv(&polygon[10].Vertex[2].x);
00464 glVertex3fv(&polygon[10].Vertex[2].x);
00465 glVertex3fv(&polygon[10].Vertex[0].x);
00466
00467 glVertex3fv(&polygon[11].Vertex[0].x);
00468 glVertex3fv(&polygon[11].Vertex[1].x);
00469 glVertex3fv(&polygon[11].Vertex[1].x);
00470 glVertex3fv(&polygon[11].Vertex[2].x);
00471 glVertex3fv(&polygon[11].Vertex[2].x);
00472 glVertex3fv(&polygon[11].Vertex[0].x);
00473 glEnd();
00474 glPopMatrix();
00475 glEnable(GL_LIGHTING);
00476 glEnable(GL_TEXTURE_2D);
00477
00478 float mat_ambient[] = { 0.8, 0.5, 0.1, 1.0 };
00479 float mat_diffuse[] = { 0.8, 0.5, 0.1, 1.0 };
00480 glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
00481 glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
00482 glDisable(GL_TEXTURE_2D);
00483 glPushMatrix();
00484 glTranslatef(vertex[VertexNumber].x, vertex[VertexNumber].y, vertex[VertexNumber].z);
00485 gluQuadricOrientation(sphere, GLU_OUTSIDE);
00486 gluSphere(sphere,10.0,20,20);
00487 glPopMatrix();
00488 glEnable(GL_TEXTURE_2D);
00489
00490 }
00491
00492 void Draw2DSceneTop(HWND hWnd)
00493 {
00494 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00495 glMatrixMode(GL_MODELVIEW);
00496 glLoadIdentity();
00497 glRotatef(90, 1, 0, 0);
00498 RECT WindowRect;
00499 GetClientRect(hWnd, &WindowRect);
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525 glDisable(GL_TEXTURE_2D);
00526 glDisable(GL_LIGHTING);
00527 glColor4f(0.0, 1.0, 0.0, 1.0);
00528 glPushMatrix();
00529 glBegin(GL_LINES);
00530
00531 glNormal3fv(&polygon[0].Vertex[0].nx);
00532 glVertex3fv(&polygon[0].Vertex[0].x);
00533 glVertex3fv(&polygon[0].Vertex[1].x);
00534 glVertex3fv(&polygon[0].Vertex[1].x);
00535 glVertex3fv(&polygon[0].Vertex[2].x);
00536 glVertex3fv(&polygon[0].Vertex[2].x);
00537 glVertex3fv(&polygon[0].Vertex[0].x);
00538
00539 glVertex3fv(&polygon[1].Vertex[0].x);
00540 glVertex3fv(&polygon[1].Vertex[1].x);
00541 glVertex3fv(&polygon[1].Vertex[1].x);
00542 glVertex3fv(&polygon[1].Vertex[2].x);
00543 glVertex3fv(&polygon[1].Vertex[2].x);
00544 glVertex3fv(&polygon[1].Vertex[0].x);
00545
00546 glNormal3fv(&polygon[2].Vertex[0].nx);
00547 glVertex3fv(&polygon[2].Vertex[0].x);
00548 glVertex3fv(&polygon[2].Vertex[1].x);
00549 glVertex3fv(&polygon[2].Vertex[1].x);
00550 glVertex3fv(&polygon[2].Vertex[2].x);
00551 glVertex3fv(&polygon[2].Vertex[2].x);
00552 glVertex3fv(&polygon[2].Vertex[0].x);
00553
00554 glVertex3fv(&polygon[3].Vertex[0].x);
00555 glVertex3fv(&polygon[3].Vertex[1].x);
00556 glVertex3fv(&polygon[3].Vertex[1].x);
00557 glVertex3fv(&polygon[3].Vertex[2].x);
00558 glVertex3fv(&polygon[3].Vertex[2].x);
00559 glVertex3fv(&polygon[3].Vertex[0].x);
00560
00561 glNormal3fv(&polygon[4].Vertex[0].nx);
00562 glVertex3fv(&polygon[4].Vertex[0].x);
00563 glVertex3fv(&polygon[4].Vertex[1].x);
00564 glVertex3fv(&polygon[4].Vertex[1].x);
00565 glVertex3fv(&polygon[4].Vertex[2].x);
00566 glVertex3fv(&polygon[4].Vertex[2].x);
00567 glVertex3fv(&polygon[4].Vertex[0].x);
00568
00569 glVertex3fv(&polygon[5].Vertex[0].x);
00570 glVertex3fv(&polygon[5].Vertex[1].x);
00571 glVertex3fv(&polygon[5].Vertex[1].x);
00572 glVertex3fv(&polygon[5].Vertex[2].x);
00573 glVertex3fv(&polygon[5].Vertex[2].x);
00574 glVertex3fv(&polygon[5].Vertex[0].x);
00575
00576 glNormal3fv(&polygon[6].Vertex[0].nx);
00577 glVertex3fv(&polygon[6].Vertex[0].x);
00578 glVertex3fv(&polygon[6].Vertex[1].x);
00579 glVertex3fv(&polygon[6].Vertex[1].x);
00580 glVertex3fv(&polygon[6].Vertex[2].x);
00581 glVertex3fv(&polygon[6].Vertex[2].x);
00582 glVertex3fv(&polygon[6].Vertex[0].x);
00583
00584 glVertex3fv(&polygon[7].Vertex[0].x);
00585 glVertex3fv(&polygon[7].Vertex[1].x);
00586 glVertex3fv(&polygon[7].Vertex[1].x);
00587 glVertex3fv(&polygon[7].Vertex[2].x);
00588 glVertex3fv(&polygon[7].Vertex[2].x);
00589 glVertex3fv(&polygon[7].Vertex[0].x);
00590
00591 glNormal3fv(&polygon[8].Vertex[0].nx);
00592 glVertex3fv(&polygon[8].Vertex[0].x);
00593 glVertex3fv(&polygon[8].Vertex[1].x);
00594 glVertex3fv(&polygon[8].Vertex[1].x);
00595 glVertex3fv(&polygon[8].Vertex[2].x);
00596 glVertex3fv(&polygon[8].Vertex[2].x);
00597 glVertex3fv(&polygon[8].Vertex[0].x);
00598
00599 glVertex3fv(&polygon[9].Vertex[0].x);
00600 glVertex3fv(&polygon[9].Vertex[1].x);
00601 glVertex3fv(&polygon[9].Vertex[1].x);
00602 glVertex3fv(&polygon[9].Vertex[2].x);
00603 glVertex3fv(&polygon[9].Vertex[2].x);
00604 glVertex3fv(&polygon[9].Vertex[0].x);
00605
00606 glNormal3fv(&polygon[10].Vertex[0].nx);
00607 glVertex3fv(&polygon[10].Vertex[0].x);
00608 glVertex3fv(&polygon[10].Vertex[1].x);
00609 glVertex3fv(&polygon[10].Vertex[1].x);
00610 glVertex3fv(&polygon[10].Vertex[2].x);
00611 glVertex3fv(&polygon[10].Vertex[2].x);
00612 glVertex3fv(&polygon[10].Vertex[0].x);
00613
00614 glVertex3fv(&polygon[11].Vertex[0].x);
00615 glVertex3fv(&polygon[11].Vertex[1].x);
00616 glVertex3fv(&polygon[11].Vertex[1].x);
00617 glVertex3fv(&polygon[11].Vertex[2].x);
00618 glVertex3fv(&polygon[11].Vertex[2].x);
00619 glVertex3fv(&polygon[11].Vertex[0].x);
00620 glEnd();
00621 glPopMatrix();
00622 glEnable(GL_LIGHTING);
00623 glEnable(GL_TEXTURE_2D);
00624
00625 float mat_ambient[] = { 0.8, 0.5, 0.1, 1.0 };
00626 float mat_diffuse[] = { 0.8, 0.5, 0.1, 1.0 };
00627 glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
00628 glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
00629 glDisable(GL_TEXTURE_2D);
00630 glPushMatrix();
00631 glTranslatef(vertex[VertexNumber].x, vertex[VertexNumber].y, vertex[VertexNumber].z);
00632 gluQuadricOrientation(sphere, GLU_OUTSIDE);
00633 gluSphere(sphere,10.0,20,20);
00634 glPopMatrix();
00635 glEnable(GL_TEXTURE_2D);
00636
00637 }
00638
00639 void Draw2DSceneLeft(HWND hWnd)
00640 {
00641 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00642 glMatrixMode(GL_MODELVIEW);
00643 glLoadIdentity();
00644 glRotatef(90, 0, 1, 0);
00645 RECT WindowRect;
00646 GetClientRect(hWnd, &WindowRect);
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672 glDisable(GL_TEXTURE_2D);
00673 glDisable(GL_LIGHTING);
00674 glColor4f(0.0, 0.0, 1.0, 1.0);
00675 glPushMatrix();
00676 glBegin(GL_LINES);
00677
00678 glNormal3fv(&polygon[0].Vertex[0].nx);
00679 glVertex3fv(&polygon[0].Vertex[0].x);
00680 glVertex3fv(&polygon[0].Vertex[1].x);
00681 glVertex3fv(&polygon[0].Vertex[1].x);
00682 glVertex3fv(&polygon[0].Vertex[2].x);
00683 glVertex3fv(&polygon[0].Vertex[2].x);
00684 glVertex3fv(&polygon[0].Vertex[0].x);
00685
00686 glVertex3fv(&polygon[1].Vertex[0].x);
00687 glVertex3fv(&polygon[1].Vertex[1].x);
00688 glVertex3fv(&polygon[1].Vertex[1].x);
00689 glVertex3fv(&polygon[1].Vertex[2].x);
00690 glVertex3fv(&polygon[1].Vertex[2].x);
00691 glVertex3fv(&polygon[1].Vertex[0].x);
00692
00693 glNormal3fv(&polygon[2].Vertex[0].nx);
00694 glVertex3fv(&polygon[2].Vertex[0].x);
00695 glVertex3fv(&polygon[2].Vertex[1].x);
00696 glVertex3fv(&polygon[2].Vertex[1].x);
00697 glVertex3fv(&polygon[2].Vertex[2].x);
00698 glVertex3fv(&polygon[2].Vertex[2].x);
00699 glVertex3fv(&polygon[2].Vertex[0].x);
00700
00701 glVertex3fv(&polygon[3].Vertex[0].x);
00702 glVertex3fv(&polygon[3].Vertex[1].x);
00703 glVertex3fv(&polygon[3].Vertex[1].x);
00704 glVertex3fv(&polygon[3].Vertex[2].x);
00705 glVertex3fv(&polygon[3].Vertex[2].x);
00706 glVertex3fv(&polygon[3].Vertex[0].x);
00707
00708 glNormal3fv(&polygon[4].Vertex[0].nx);
00709 glVertex3fv(&polygon[4].Vertex[0].x);
00710 glVertex3fv(&polygon[4].Vertex[1].x);
00711 glVertex3fv(&polygon[4].Vertex[1].x);
00712 glVertex3fv(&polygon[4].Vertex[2].x);
00713 glVertex3fv(&polygon[4].Vertex[2].x);
00714 glVertex3fv(&polygon[4].Vertex[0].x);
00715
00716 glVertex3fv(&polygon[5].Vertex[0].x);
00717 glVertex3fv(&polygon[5].Vertex[1].x);
00718 glVertex3fv(&polygon[5].Vertex[1].x);
00719 glVertex3fv(&polygon[5].Vertex[2].x);
00720 glVertex3fv(&polygon[5].Vertex[2].x);
00721 glVertex3fv(&polygon[5].Vertex[0].x);
00722
00723 glNormal3fv(&polygon[6].Vertex[0].nx);
00724 glVertex3fv(&polygon[6].Vertex[0].x);
00725 glVertex3fv(&polygon[6].Vertex[1].x);
00726 glVertex3fv(&polygon[6].Vertex[1].x);
00727 glVertex3fv(&polygon[6].Vertex[2].x);
00728 glVertex3fv(&polygon[6].Vertex[2].x);
00729 glVertex3fv(&polygon[6].Vertex[0].x);
00730
00731 glVertex3fv(&polygon[7].Vertex[0].x);
00732 glVertex3fv(&polygon[7].Vertex[1].x);
00733 glVertex3fv(&polygon[7].Vertex[1].x);
00734 glVertex3fv(&polygon[7].Vertex[2].x);
00735 glVertex3fv(&polygon[7].Vertex[2].x);
00736 glVertex3fv(&polygon[7].Vertex[0].x);
00737
00738 glNormal3fv(&polygon[8].Vertex[0].nx);
00739 glVertex3fv(&polygon[8].Vertex[0].x);
00740 glVertex3fv(&polygon[8].Vertex[1].x);
00741 glVertex3fv(&polygon[8].Vertex[1].x);
00742 glVertex3fv(&polygon[8].Vertex[2].x);
00743 glVertex3fv(&polygon[8].Vertex[2].x);
00744 glVertex3fv(&polygon[8].Vertex[0].x);
00745
00746 glVertex3fv(&polygon[9].Vertex[0].x);
00747 glVertex3fv(&polygon[9].Vertex[1].x);
00748 glVertex3fv(&polygon[9].Vertex[1].x);
00749 glVertex3fv(&polygon[9].Vertex[2].x);
00750 glVertex3fv(&polygon[9].Vertex[2].x);
00751 glVertex3fv(&polygon[9].Vertex[0].x);
00752
00753 glNormal3fv(&polygon[10].Vertex[0].nx);
00754 glVertex3fv(&polygon[10].Vertex[0].x);
00755 glVertex3fv(&polygon[10].Vertex[1].x);
00756 glVertex3fv(&polygon[10].Vertex[1].x);
00757 glVertex3fv(&polygon[10].Vertex[2].x);
00758 glVertex3fv(&polygon[10].Vertex[2].x);
00759 glVertex3fv(&polygon[10].Vertex[0].x);
00760
00761 glVertex3fv(&polygon[11].Vertex[0].x);
00762 glVertex3fv(&polygon[11].Vertex[1].x);
00763 glVertex3fv(&polygon[11].Vertex[1].x);
00764 glVertex3fv(&polygon[11].Vertex[2].x);
00765 glVertex3fv(&polygon[11].Vertex[2].x);
00766 glVertex3fv(&polygon[11].Vertex[0].x);
00767 glEnd();
00768 glPopMatrix();
00769 glEnable(GL_LIGHTING);
00770 glEnable(GL_TEXTURE_2D);
00771
00772 float mat_ambient[] = { 0.8, 0.5, 0.1, 1.0 };
00773 float mat_diffuse[] = { 0.8, 0.5, 0.1, 1.0 };
00774 glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
00775 glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
00776 glDisable(GL_TEXTURE_2D);
00777 glPushMatrix();
00778 glTranslatef(vertex[VertexNumber].x, vertex[VertexNumber].y, vertex[VertexNumber].z);
00779 gluQuadricOrientation(sphere, GLU_OUTSIDE);
00780 gluSphere(sphere,10.0,20,20);
00781 glPopMatrix();
00782 glEnable(GL_TEXTURE_2D);
00783
00784 }
00785
00786 LRESULT CALLBACK WndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
00787 {
00788 switch(uMessage)
00789 {
00790 case WM_CREATE:
00791 {
00792 CLIENTCREATESTRUCT ccs;
00793
00794 ccs.hWindowMenu = NULL;
00795
00796
00797 ccs.idFirstChild = ID_MDI_FIRSTCHILD;
00798
00799 g_hMDIClient = CreateWindowEx(WS_EX_CLIENTEDGE, "MDICLIENT", NULL,
00800 WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
00801 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
00802 hWnd, (HMENU)ID_MDI_CLIENT, g_hInst, (LPVOID)&ccs);
00803
00804 ShowWindow(g_hMDIClient, SW_SHOW);
00805 return 0;
00806 }
00807 case WM_COMMAND:
00808 {
00809 switch(LOWORD(wParam))
00810 {
00811 case CM_FILE_EXIT:
00812 PostMessage(hWnd, WM_CLOSE, 0, 0);
00813 break;
00814
00815 case CM_FILE_NEW_3D:
00816 {
00817 HWND hChild;
00818
00819 if(g_iNumChild < g_iMaxChild)
00820 g_iNumChild++;
00821 else
00822 break;
00823
00824 char szWindowTitle[] = "3D";
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847 CREATESTRUCT cs;
00848 ZeroMemory(&cs, sizeof(CREATESTRUCT));
00849
00850 hChild = CreateWindowEx(
00851 WS_EX_MDICHILD,
00852 g_szChild3DClassName,
00853 szWindowTitle,
00854 WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW,
00855 CW_USEDEFAULT,
00856 CW_USEDEFAULT,
00857 CW_USEDEFAULT,
00858 CW_USEDEFAULT,
00859 g_hMDIClient,
00860 NULL,
00861 g_hInst,
00862 &cs
00863 );
00864
00865 if(!hChild)
00866 {
00867 MessageBox(NULL, "3D Child creation failed.", "Error",
00868 MB_ICONEXCLAMATION | MB_OK);
00869 }
00870
00871 g_child[g_iNumChild - 1].iType = 1;
00872 g_child[g_iNumChild - 1].hWnd = hChild;
00873 g_child[g_iNumChild - 1].hDC = GetDC(hChild);
00874
00875 PIXELFORMATDESCRIPTOR pfd;
00876 ZeroMemory(&pfd, sizeof(pfd));
00877 pfd.nSize = sizeof(pfd);
00878 pfd.nVersion = 1;
00879 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
00880 pfd.iPixelType = PFD_TYPE_RGBA;
00881 pfd.cColorBits = 24;
00882 pfd.cDepthBits = 16;
00883 pfd.iLayerType = PFD_MAIN_PLANE;
00884 int iFormat = ChoosePixelFormat(g_child[g_iNumChild - 1].hDC, &pfd);
00885 SetPixelFormat(g_child[g_iNumChild - 1].hDC, iFormat, &pfd);
00886
00887 g_child[g_iNumChild - 1].hRC = wglCreateContext(g_child[g_iNumChild - 1].hDC);
00888 wglMakeCurrent(g_child[g_iNumChild - 1].hDC, g_child[g_iNumChild - 1].hRC);
00889 InitGL();
00890 }
00891 break;
00892
00893 case CM_FILE_NEW_FRONT:
00894 {
00895 HWND hChild;
00896
00897 if(g_iNumChild < g_iMaxChild)
00898 g_iNumChild++;
00899 else
00900 break;
00901
00902 char szWindowTitle[] = "Front";
00903
00904
00905 CREATESTRUCT cs;
00906 ZeroMemory(&cs, sizeof(CREATESTRUCT));
00907
00908 hChild = CreateWindowEx(
00909 WS_EX_MDICHILD,
00910 g_szChild2DClassName,
00911 szWindowTitle,
00912 WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW,
00913 CW_USEDEFAULT,
00914 CW_USEDEFAULT,
00915 CW_USEDEFAULT,
00916 CW_USEDEFAULT,
00917 g_hMDIClient,
00918 NULL,
00919 g_hInst,
00920 &cs
00921 );
00922
00923 if(!hChild)
00924 {
00925 MessageBox(NULL, "2D Child creation failed.", "Error",
00926 MB_ICONEXCLAMATION | MB_OK);
00927 }
00928
00929 g_child[g_iNumChild - 1].iType = 2;
00930 g_child[g_iNumChild - 1].hWnd = hChild;
00931 g_child[g_iNumChild - 1].hDC = GetDC(hChild);
00932
00933 PIXELFORMATDESCRIPTOR pfd;
00934 ZeroMemory(&pfd, sizeof(pfd));
00935 pfd.nSize = sizeof(pfd);
00936 pfd.nVersion = 1;
00937 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
00938 pfd.iPixelType = PFD_TYPE_RGBA;
00939 pfd.cColorBits = 24;
00940 pfd.cDepthBits = 16;
00941 pfd.iLayerType = PFD_MAIN_PLANE;
00942 int iFormat = ChoosePixelFormat(g_child[g_iNumChild - 1].hDC, &pfd);
00943 SetPixelFormat(g_child[g_iNumChild - 1].hDC, iFormat, &pfd);
00944
00945 g_child[g_iNumChild - 1].hRC = wglCreateContext(g_child[g_iNumChild - 1].hDC);
00946 wglMakeCurrent(g_child[g_iNumChild - 1].hDC, g_child[g_iNumChild - 1].hRC);
00947 InitGL();
00948 }
00949 break;
00950
00951 case CM_FILE_NEW_TOP:
00952 {
00953 HWND hChild;
00954
00955 if(g_iNumChild < g_iMaxChild)
00956 g_iNumChild++;
00957 else
00958 break;
00959
00960 char szWindowTitle[] = "Top";
00961
00962
00963 CREATESTRUCT cs;
00964 ZeroMemory(&cs, sizeof(CREATESTRUCT));
00965
00966 hChild = CreateWindowEx(
00967 WS_EX_MDICHILD,
00968 g_szChild2DClassName,
00969 szWindowTitle,
00970 WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW,
00971 CW_USEDEFAULT,
00972 CW_USEDEFAULT,
00973 CW_USEDEFAULT,
00974 CW_USEDEFAULT,
00975 g_hMDIClient,
00976 NULL,
00977 g_hInst,
00978 &cs
00979 );
00980
00981 if(!hChild)
00982 {
00983 MessageBox(NULL, "2D Child creation failed.", "Error",
00984 MB_ICONEXCLAMATION | MB_OK);
00985 }
00986
00987 g_child[g_iNumChild - 1].iType = 3;
00988 g_child[g_iNumChild - 1].hWnd = hChild;
00989 g_child[g_iNumChild - 1].hDC = GetDC(hChild);
00990
00991 PIXELFORMATDESCRIPTOR pfd;
00992 ZeroMemory(&pfd, sizeof(pfd));
00993 pfd.nSize = sizeof(pfd);
00994 pfd.nVersion = 1;
00995 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
00996 pfd.iPixelType = PFD_TYPE_RGBA;
00997 pfd.cColorBits = 24;
00998 pfd.cDepthBits = 16;
00999 pfd.iLayerType = PFD_MAIN_PLANE;
01000 int iFormat = ChoosePixelFormat(g_child[g_iNumChild - 1].hDC, &pfd);
01001 SetPixelFormat(g_child[g_iNumChild - 1].hDC, iFormat, &pfd);
01002
01003 g_child[g_iNumChild - 1].hRC = wglCreateContext(g_child[g_iNumChild - 1].hDC);
01004 wglMakeCurrent(g_child[g_iNumChild - 1].hDC, g_child[g_iNumChild - 1].hRC);
01005 InitGL();
01006 }
01007 break;
01008
01009 case CM_FILE_NEW_LEFT:
01010 {
01011 HWND hChild;
01012
01013 if(g_iNumChild < g_iMaxChild)
01014 g_iNumChild++;
01015 else
01016 break;
01017
01018 char szWindowTitle[] = "Left";
01019
01020
01021 CREATESTRUCT cs;
01022 ZeroMemory(&cs, sizeof(CREATESTRUCT));
01023
01024 hChild = CreateWindowEx(
01025 WS_EX_MDICHILD,
01026 g_szChild2DClassName,
01027 szWindowTitle,
01028 WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW,
01029 CW_USEDEFAULT,
01030 CW_USEDEFAULT,
01031 CW_USEDEFAULT,
01032 CW_USEDEFAULT,
01033 g_hMDIClient,
01034 NULL,
01035 g_hInst,
01036 &cs
01037 );
01038
01039 if(!hChild)
01040 {
01041 MessageBox(NULL, "2D Child creation failed.", "Error",
01042 MB_ICONEXCLAMATION | MB_OK);
01043 }
01044
01045 g_child[g_iNumChild - 1].iType = 4;
01046 g_child[g_iNumChild - 1].hWnd = hChild;
01047 g_child[g_iNumChild - 1].hDC = GetDC(hChild);
01048
01049 PIXELFORMATDESCRIPTOR pfd;
01050 ZeroMemory(&pfd, sizeof(pfd));
01051 pfd.nSize = sizeof(pfd);
01052 pfd.nVersion = 1;
01053 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
01054 pfd.iPixelType = PFD_TYPE_RGBA;
01055 pfd.cColorBits = 24;
01056 pfd.cDepthBits = 16;
01057 pfd.iLayerType = PFD_MAIN_PLANE;
01058 int iFormat = ChoosePixelFormat(g_child[g_iNumChild - 1].hDC, &pfd);
01059 SetPixelFormat(g_child[g_iNumChild - 1].hDC, iFormat, &pfd);
01060
01061 g_child[g_iNumChild - 1].hRC = wglCreateContext(g_child[g_iNumChild - 1].hDC);
01062 wglMakeCurrent(g_child[g_iNumChild - 1].hDC, g_child[g_iNumChild - 1].hRC);
01063 InitGL();
01064 }
01065 break;
01066
01067 case CM_WINDOW_TILEHORZ:
01068 PostMessage(g_hMDIClient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
01069 break;
01070
01071 case CM_WINDOW_TILEVERT:
01072 PostMessage(g_hMDIClient, WM_MDITILE, MDITILE_VERTICAL, 0);
01073 break;
01074
01075 case CM_WINDOW_CASCADE:
01076 PostMessage(g_hMDIClient, WM_MDICASCADE, 0, 0);
01077 break;
01078
01079 case CM_WINDOW_ARRANGE:
01080 PostMessage(g_hMDIClient, WM_MDIICONARRANGE, 0, 0);
01081 break;
01082
01083 default:
01084 {
01085 if(LOWORD(wParam) >= ID_MDI_FIRSTCHILD)
01086 {
01087 DefFrameProc(hWnd, g_hMDIClient, uMessage, wParam, lParam);
01088 }
01089 else
01090 {
01091 HWND hChild;
01092 hChild = (HWND)SendMessage(g_hMDIClient, WM_MDIGETACTIVE, 0, 0);
01093 if(hChild)
01094 {
01095 SendMessage(hChild, WM_COMMAND, wParam, lParam);
01096 }
01097 }
01098 }
01099 }
01100 }
01101 break;
01102
01103 case WM_CLOSE:
01104 {
01105 int iLoop;
01106 if(g_iNumChild)
01107 {
01108 for(iLoop = 0; iLoop < g_iNumChild; iLoop++)
01109 {
01110 SendMessage(g_child[iLoop].hWnd, WM_CLOSE, 0, 0);
01111 }
01112 }
01113 delete[] g_child;
01114 delete[] texture;
01115 delete[] vertex;
01116 delete[] polygon;
01117 DestroyWindow(hWnd);
01118 }
01119 break;
01120
01121 case WM_DESTROY:
01122 PostQuitMessage(0);
01123 break;
01124
01125 default:
01126 return DefFrameProc(hWnd, g_hMDIClient, uMessage, wParam, lParam);
01127 }
01128 return 0;
01129 }
01130
01131 LRESULT CALLBACK Child3DWndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
01132 {
01133 switch(uMessage)
01134 {
01135 case WM_KEYDOWN:
01136 key[wParam] = TRUE;
01137 break;
01138
01139 case WM_KEYUP:
01140 key[wParam] = FALSE;
01141 break;
01142 case WM_LBUTTONDOWN:
01143 g_bMouseDrag = 1;
01144 g_iMouseLastX = LOWORD(lParam);
01145 g_iMouseLastY = HIWORD(lParam);
01146 SetCapture(hWnd);
01147 break;
01148
01149 case WM_MOUSEMOVE:
01150 if(g_bMouseDrag)
01151 {
01152 g_iMouseDeltaX = LOWORD(lParam) - g_iMouseLastX;
01153 g_iMouseDeltaY = HIWORD(lParam) - g_iMouseLastY;
01154 g_iMouseLastX = LOWORD(lParam);
01155 g_iMouseLastY = HIWORD(lParam);
01156 }
01157 break;
01158
01159 case WM_LBUTTONUP:
01160 g_bMouseDrag = 0;
01161 ReleaseCapture();
01162 break;
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202 case WM_CLOSE:
01203 g_iNumChild--;
01204 if(g_iNumChild == 0)
01205 {
01206 wglMakeCurrent( NULL, NULL );
01207 ReleaseDC(g_child[0].hWnd, g_child[0].hDC);
01208 wglDeleteContext(g_child[0].hRC);
01209 }
01210 else
01211 {
01212 int iLoop;
01213 int iThisChild;
01214 char szWindowTitle[20];
01215 iThisChild = GetDlgCtrlID(hWnd) - ID_MDI_FIRSTCHILD;
01216 ReleaseDC(g_child[iThisChild].hWnd, g_child[iThisChild].hDC);
01217 wglDeleteContext(g_child[iThisChild].hRC);
01218 if(iThisChild != g_iNumChild)
01219 {
01220 for (iLoop = iThisChild; iLoop < (g_iNumChild); iLoop++)
01221 {
01222 g_child[iLoop] = g_child[iLoop + 1];
01223 sprintf(szWindowTitle, "%d", iLoop);
01224 SetWindowText(g_child[iLoop].hWnd, szWindowTitle);
01225 }
01226 }
01227 }
01228 break;
01229
01230 case WM_MDIACTIVATE:
01231 {
01232 HMENU hMenu, hFileMenu;
01233 UINT uEnableFlag;
01234
01235 hMenu = GetMenu(g_hMainWindow);
01236 if(hWnd == (HWND)lParam)
01237 {
01238 uEnableFlag = MF_ENABLED;
01239 }
01240 else
01241 {
01242 uEnableFlag = MF_GRAYED;
01243 }
01244 EnableMenuItem(hMenu, 1, MF_BYPOSITION | uEnableFlag);
01245 EnableMenuItem(hMenu, 2, MF_BYPOSITION | uEnableFlag);
01246
01247 hFileMenu = GetSubMenu(hMenu, 0);
01248 EnableMenuItem(hFileMenu, CM_FILE_SAVE, MF_BYCOMMAND | uEnableFlag);
01249 EnableMenuItem(hFileMenu, CM_FILE_SAVEAS, MF_BYCOMMAND | uEnableFlag);
01250
01251 DrawMenuBar(g_hMainWindow);
01252 }
01253 break;
01254
01255 case WM_COMMAND:
01256 switch(LOWORD(wParam))
01257 {
01258
01259 }
01260 return 0;
01261 }
01262 return DefMDIChildProc(hWnd, uMessage, wParam, lParam);
01263 }
01264
01265 void DrawWin32Text(HDC hDC, int right, int bottom, int x, int y)
01266 {
01267 colorRGB = RGB(255, 255, 255);
01268 SetTextColor(hDC, colorRGB);
01269 SetBkMode(hDC, TRANSPARENT);
01270 MainRect.left = 0;
01271 MainRect.top = 0;
01272 MainRect.bottom = bottom;
01273 MainRect.right = right;
01274 ZeroMemory(&LogFont, sizeof(LogFont));
01275 LogFont.lfHeight = 14;
01276 LogFont.lfWidth = 8;
01277 LogFont.lfEscapement = 0;
01278 LogFont.lfOrientation = 0;
01279 LogFont.lfWeight = FW_NORMAL;
01280 LogFont.lfItalic = 0;
01281 LogFont.lfUnderline = 0;
01282 LogFont.lfStrikeOut = 0;
01283 LogFont.lfCharSet = DEFAULT_CHARSET;
01284 LogFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
01285 LogFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
01286 LogFont.lfQuality = DEFAULT_QUALITY;
01287 LogFont.lfPitchAndFamily = DEFAULT_PITCH;
01288 sprintf(LogFont.lfFaceName, "%s", "Arial");
01289 hFont = CreateFontIndirect(&LogFont);
01290 SaveDC(hDC);
01291 hOldFont = (HFONT)SelectObject(hDC, (HFONT)hFont);
01292 char tempstring[20];
01293 sprintf(tempstring, "%d", MouseX);
01294 DrawText(hDC, tempstring, 11, &MainRect, DT_NOCLIP | DT_LEFT | DT_BOTTOM | DT_WORDBREAK | DT_EDITCONTROL);
01295 SelectObject(hDC, (HFONT)hOldFont);
01296 DeleteObject(hFont);
01297 RestoreDC(hDC, -1);
01298 }
01299
01300 LRESULT CALLBACK Child2DWndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
01301 {
01302 switch(uMessage)
01303 {
01304 case WM_SIZE:
01305 {
01306 if(wParam != SIZE_MINIMIZED)
01307 {
01308 RECT WindowRect;
01309 GetClientRect(hWnd, &WindowRect);
01310 int iThisChild = GetDlgCtrlID(hWnd) - ID_MDI_FIRSTCHILD;
01311 if(g_child[iThisChild].iType == 2)
01312 {
01313 TopDepth = -0.5 * WindowRect.bottom + 10;
01314 LeftDepth = -0.5 * WindowRect.right + 10;
01315 }
01316 if(g_child[iThisChild].iType == 3)
01317 {
01318 FrontDepth = 0.5 * WindowRect.bottom - 10;
01319 LeftDepth = -0.5 * WindowRect.right + 10;
01320 }
01321 if(g_child[iThisChild].iType == 4)
01322 {
01323 FrontDepth = -0.5 * WindowRect.right + 10;
01324 TopDepth = -0.5 * WindowRect.bottom + 10;
01325 }
01326 }
01327 }
01328 break;
01329
01330 case WM_KEYDOWN:
01331 key[wParam] = TRUE;
01332 break;
01333
01334 case WM_KEYUP:
01335 key[wParam] = FALSE;
01336 break;
01337
01338 case WM_LBUTTONDOWN:
01339 g_bMouseDrag2 = 1;
01340 g_iMouseLastX2 = LOWORD(lParam);
01341 g_iMouseLastY2 = HIWORD(lParam);
01342 SetCapture(hWnd);
01343 break;
01344
01345 case WM_LBUTTONUP:
01346 g_bMouseDrag2 = 0;
01347 ReleaseCapture();
01348 break;
01349
01350 case WM_MOUSEMOVE:
01351 {
01352 RECT WindowRect;
01353 GetClientRect(hWnd, &WindowRect);
01354 MouseX = LOWORD(lParam);
01355 MouseY = HIWORD(lParam);
01356 int iThisChild = GetDlgCtrlID(hWnd) - ID_MDI_FIRSTCHILD;
01357 if(g_bMouseDrag2)
01358 {
01359 if (MouseX < WindowRect.left || MouseX > WindowRect.right)
01360 {
01361 MouseX = g_iMouseLastX2;
01362 }
01363 if (MouseY < WindowRect.top || MouseY > WindowRect.bottom)
01364 {
01365 MouseY = g_iMouseLastY2;
01366 }
01367 g_iMouseDeltaX2 = MouseX - g_iMouseLastX2;
01368 g_iMouseDeltaY2 = MouseY - g_iMouseLastY2;
01369 g_iMouseLastX2 = MouseX;
01370 g_iMouseLastY2 = MouseY;
01371 if(g_child[iThisChild].iType == 2)
01372 {
01373 vertex[VertexNumber].x += (float)g_iMouseDeltaX2 * 1.0;
01374 vertex[VertexNumber].y -= (float)g_iMouseDeltaY2 * 1.0;
01375 }
01376 if(g_child[iThisChild].iType == 3)
01377 {
01378 vertex[VertexNumber].x += (float)g_iMouseDeltaX2 * 1.0;
01379 vertex[VertexNumber].z += (float)g_iMouseDeltaY2 * 1.0;
01380 }
01381 if(g_child[iThisChild].iType == 4)
01382 {
01383 vertex[VertexNumber].z += (float)g_iMouseDeltaX2 * 1.0;
01384 vertex[VertexNumber].y -= (float)g_iMouseDeltaY2 * 1.0;
01385 }
01386 SetPolygons();
01387 }
01388
01389 if(!g_bMouseDrag2)
01390 {
01391 MouseX = (int)(LOWORD(lParam) + (-0.5 * WindowRect.right));
01392 if(g_child[iThisChild].iType == 3)
01393 MouseY = (int)(HIWORD(lParam) + (-0.5 * WindowRect.bottom));
01394 else
01395 MouseY = (int)(-1 * (HIWORD(lParam) + (-0.5 * WindowRect.bottom)));
01396 ShortestDistance = 10000;
01397 int Loop;
01398 int TempX;
01399 int TempY;
01400 for(Loop = 0; Loop < 8; Loop++)
01401 {
01402 iThisChild = GetDlgCtrlID(hWnd) - ID_MDI_FIRSTCHILD;
01403 if(g_child[iThisChild].iType == 2)
01404 {
01405 TempX = (int)(MouseX - vertex[Loop].x);
01406 TempY = (int)(MouseY - vertex[Loop].y);
01407 }
01408 if(g_child[iThisChild].iType == 3)
01409 {
01410 TempX = (int)(MouseX - vertex[Loop].x);
01411 TempY = (int)(MouseY - vertex[Loop].z);
01412 }
01413 if(g_child[iThisChild].iType == 4)
01414 {
01415 TempX = (int)(MouseX - vertex[Loop].z);
01416 TempY = (int)(MouseY - vertex[Loop].y);
01417 }
01418 if(sqrt((TempX * TempX) + (TempY * TempY)) < ShortestDistance)
01419 {
01420 ShortestDistance = (int)(sqrt((TempX * TempX) + (TempY * TempY)));
01421 VertexNumber = Loop;
01422 }
01423 }
01424
01425
01426
01427 }
01428 }
01429 break;
01430
01431 case WM_CLOSE:
01432 g_iNumChild--;
01433 if(g_iNumChild == 0)
01434 {
01435 wglMakeCurrent( NULL, NULL );
01436 ReleaseDC(g_child[0].hWnd, g_child[0].hDC);
01437 wglDeleteContext(g_child[0].hRC);
01438 }
01439 else
01440 {
01441 int iLoop;
01442 int iThisChild;
01443 char szWindowTitle[20];
01444 iThisChild = GetDlgCtrlID(hWnd) - ID_MDI_FIRSTCHILD;
01445 ReleaseDC(g_child[iThisChild].hWnd, g_child[iThisChild].hDC);
01446 wglDeleteContext(g_child[iThisChild].hRC);
01447 if(iThisChild != g_iNumChild)
01448 {
01449 for (iLoop = iThisChild; iLoop < (g_iNumChild); iLoop++)
01450 {
01451 g_child[iLoop] = g_child[iLoop + 1];
01452 sprintf(szWindowTitle, "%d", iLoop);
01453 SetWindowText(g_child[iLoop].hWnd, szWindowTitle);
01454 }
01455 }
01456 }
01457 break;
01458
01459 case WM_MDIACTIVATE:
01460 {
01461 HMENU hMenu, hFileMenu;
01462 UINT uEnableFlag;
01463
01464 hMenu = GetMenu(g_hMainWindow);
01465 if(hWnd == (HWND)lParam)
01466 {
01467 uEnableFlag = MF_ENABLED;
01468 }
01469 else
01470 {
01471 uEnableFlag = MF_GRAYED;
01472 }
01473 EnableMenuItem(hMenu, 1, MF_BYPOSITION | uEnableFlag);
01474 EnableMenuItem(hMenu, 2, MF_BYPOSITION | uEnableFlag);
01475
01476 hFileMenu = GetSubMenu(hMenu, 0);
01477 EnableMenuItem(hFileMenu, CM_FILE_SAVE, MF_BYCOMMAND | uEnableFlag);
01478 EnableMenuItem(hFileMenu, CM_FILE_SAVEAS, MF_BYCOMMAND | uEnableFlag);
01479
01480 DrawMenuBar(g_hMainWindow);
01481 }
01482 break;
01483
01484 case WM_COMMAND:
01485 switch(LOWORD(wParam))
01486 {
01487
01488 }
01489 return 0;
01490 }
01491 return DefMDIChildProc(hWnd, uMessage, wParam, lParam);
01492 }
01493
01494 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow)
01495 {
01496 MSG Msg;
01497 WNDCLASSEX wc;
01498 g_hInst = hInstance;
01499
01500
01501 wc.cbSize = sizeof(WNDCLASSEX);
01502 wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS;
01503 wc.lpfnWndProc = (WNDPROC)Child3DWndProc;
01504 wc.cbClsExtra = 0;
01505 wc.cbWndExtra = 0;
01506 wc.hInstance = hInstance;
01507 wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_CHILDICON));
01508 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
01509 wc.hbrBackground = (HBRUSH)(COLOR_3DSHADOW+1);
01510 wc.lpszMenuName = NULL;
01511 wc.lpszClassName = g_szChild3DClassName;
01512 wc.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_CHILDICON));
01513
01514 if(!RegisterClassEx(&wc))
01515 {
01516 MessageBox(NULL,"Failed to register the child window.","Error",MB_OK|MB_ICONEXCLAMATION);
01517 return FALSE;
01518 }
01519
01520
01521 wc.cbSize = sizeof(WNDCLASSEX);
01522 wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS;
01523 wc.lpfnWndProc = (WNDPROC)Child2DWndProc;
01524 wc.cbClsExtra = 0;
01525 wc.cbWndExtra = 0;
01526 wc.hInstance = hInstance;
01527 wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_CHILDICON));
01528 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
01529 wc.hbrBackground = (HBRUSH)(COLOR_3DSHADOW+1);
01530 wc.lpszMenuName = NULL;
01531 wc.lpszClassName = g_szChild2DClassName;
01532 wc.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_CHILDICON));
01533
01534 if(!RegisterClassEx(&wc))
01535 {
01536 MessageBox(NULL,"Failed to register the child window.","Error",MB_OK|MB_ICONEXCLAMATION);
01537 return FALSE;
01538 }
01539
01540
01541 wc.cbSize = sizeof(WNDCLASSEX);
01542 wc.style = CS_HREDRAW | CS_VREDRAW;
01543 wc.lpfnWndProc = (WNDPROC)WndProc;
01544 wc.cbClsExtra = 0;
01545 wc.cbWndExtra = 0;
01546 wc.hInstance = hInstance;
01547 wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYICON));
01548 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
01549 wc.hbrBackground = (HBRUSH)(COLOR_3DSHADOW+1);
01550 wc.lpszMenuName = "MAIN";
01551 wc.lpszClassName = g_szMainClassName;
01552 wc.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYICON));
01553
01554 if(!RegisterClassEx(&wc))
01555 {
01556 MessageBox(0, "Failed to register the main window.", "Error",
01557 MB_ICONEXCLAMATION | MB_OK);
01558 return -1;
01559 }
01560
01561 g_hMainWindow = CreateWindowEx(WS_EX_LEFT, g_szMainClassName, "Al's OpenGL MDI Example",
01562 WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
01563 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
01564 NULL, NULL, hInstance, NULL);
01565
01566 if(g_hMainWindow == NULL)
01567 {
01568 MessageBox(0, "Failed to create window.", "ERROR", MB_ICONEXCLAMATION | MB_OK);
01569 return -1;
01570 }
01571
01572 ShowWindow(g_hMainWindow, nCmdShow);
01573 UpdateWindow(g_hMainWindow);
01574 SetVertices();
01575 SetPolygons();
01576
01577 int iLoop;
01578 while(GetMessage(&Msg, NULL, 0, 0))
01579 {
01580 if(!TranslateMDISysAccel(g_hMDIClient, &Msg))
01581 {
01582 TranslateMessage(&Msg);
01583 DispatchMessage(&Msg);
01584 }
01585
01586 if(g_iNumChild)
01587 {
01588 for(iLoop = 0; iLoop < g_iNumChild; iLoop++)
01589 {
01590 if(!IsIconic(g_child[iLoop].hWnd))
01591 {
01592 wglMakeCurrent(g_child[iLoop].hDC, g_child[iLoop].hRC);
01593 GetClientRect(g_child[iLoop].hWnd, &g_rectChild);
01594 if(g_rectChild.right > 0 && g_rectChild.bottom > 0)
01595 {
01596 if(g_child[iLoop].iType == 1)
01597 {
01598 Set3DProjection(g_rectChild.right, g_rectChild.bottom);
01599 Draw3DScene();
01600 }
01601 else
01602 {
01603 Set2DProjection(g_rectChild.right, g_rectChild.bottom);
01604 switch(g_child[iLoop].iType)
01605 {
01606 case 2:
01607 Draw2DSceneFront(g_child[iLoop].hWnd);
01608 break;
01609
01610 case 3:
01611 Draw2DSceneTop(g_child[iLoop].hWnd);
01612 break;
01613
01614 case 4:
01615 Draw2DSceneLeft(g_child[iLoop].hWnd);
01616 break;
01617 }
01618 }
01619 }
01620 glFlush();
01621 SwapBuffers(g_child[iLoop].hDC);
01622
01623 if (key[49])
01624 {
01625 if (Zoom < 1)
01626 Zoom += 0.001;
01627 }
01628
01629 if (key[50])
01630 {
01631 if (Zoom > 0)
01632 Zoom -= 0.001;
01633 }
01634
01635 if (key[51])
01636 {
01637 VerticalShift += 1;
01638 }
01639
01640 if (key[52])
01641 {
01642 VerticalShift -= 1;
01643 }
01644
01645 if (key[53])
01646 {
01647 HorizontalShift += 1;
01648 }
01649
01650 if (key[54])
01651 {
01652 HorizontalShift -= 1;
01653 }
01654
01655 if (key[VK_SPACE])
01656 {
01657 SetVertices();
01658 SetPolygons();
01659 }
01660
01661 }
01662 }
01663 }
01664 }
01665 return Msg.wParam;
01666 }
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687
01688
01689
01690