Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

main.cpp

Go to the documentation of this file.
00001 // ~~~ OpenGL & Win32 ~~~
00002 // Tutorial No.13 - Portals
00003 // Alan Baylis 30/01/2002
00004 
00005 #include <windows.h>
00006 #include "shared.h"
00007 #include "general.h"   // GetEdgeIntersection() and new frustum routines have been added
00008 #include "listnode.h"  // Wraps the BSP_node to allow the nodes to be included in a linked list
00009 #include "locmath.h"
00010 #include "vector.h"
00011 #include "vertex.h"
00012 #include "quat.h"
00013 #include "matrix.h"
00014 #include "texture.h"
00015 #include "polygon.h"   // SplitPolygon() has been moved to here
00016 #include "plane.h"     // New plane class
00017 #include "object.h"
00018 #include "camera.h"
00019 #include "light.h"
00020 #include "collision.h"
00021 #include "glfont.h"
00022 #include "bspline.h"
00023 #include "bsp.h"
00024 #include "portal.h"    // The portal class and routines
00025 #include "tga.h"
00026 #include "lightmap.h"
00027 #include "winfuncs.h"
00028 #include "tll.h"
00029 #include "console.h"
00030 #include "log.h"
00031 #include "mmgr.h"
00032 #include "resource.rh"
00033 
00034 // Console
00035 ConsoleWindow Console;
00036 
00037 // Windows
00038 static HGLRC hRC;
00039 static HDC hDC;
00040 HWND hWnd;
00041 HINSTANCE g_hInst;
00042 RECT screen;
00043 PAINTSTRUCT ps;
00044 char AppDirectory[MAX_PATH];
00045 float ApplicationStartTime;
00046 
00047 // Math
00048 float pi = 3.141592;
00049 float radian = pi / 180;
00050 float epsilon = 0.05;
00051 
00052 // Input
00053 bool key[256];
00054 bool released_key[256];
00055 
00056 // Cameras
00057 int currentCamera = 0;
00058 int numCameras = 4;
00059 float step = 30.0;
00060 
00061 // Timing
00062 float lasttime;
00063 float multiplier;
00064 const int average = 20;
00065 float lastmultiplier[average];
00066 int fps;
00067 
00068 // Lights
00069 int GL_LIGHT[8] = {GL_LIGHT0, GL_LIGHT1, GL_LIGHT2, GL_LIGHT3, GL_LIGHT4, GL_LIGHT5, GL_LIGHT6, GL_LIGHT7};
00070 int currentLight = 0;
00071 int numLights = 0;
00072 
00073 // Planes
00074 PLANE frustum[6];
00075 
00076 // World vertices
00077 int numVertices = 37;
00078 VERTEX* vertex = new VERTEX[numVertices];
00079 
00080 // World polygons
00081 int numPolygons = 58;
00082 POLYGON* polygon = new POLYGON[numPolygons];
00083 POLYGON* bsppolygon = new POLYGON[numPolygons];
00084 
00085 // Texture
00086 TEXTURE* texture = new TEXTURE[4];
00087 
00088 // Camera
00089 CAMERA* camera = new CAMERA[numCameras + 1];
00090 CAMERA LastCam;
00091 
00092 // Lighting
00093 LIGHT* light = new LIGHT[numLights + 1];
00094 float lightColor[3] = {1.0, 1.0, 1.0};
00095 
00096 // Dialogs
00097 HWND hWndStartDlg;
00098 int DialogInUse = 0;
00099 char szText[BUFFER_SIZE];
00100 
00101 // Font
00102 GLFONT myFont;
00103 
00104 // Bounding box variables
00105 float Min_X, Min_Y, Min_Z, Max_X, Max_Y, Max_Z; // The bounding box will be useful in many situations so I have made it global
00106 
00107 // Test variables
00108 int showportals = 1;              // Flag used to toggle the rendering of the portals
00109 int numlistleaves = 0;            // Number of leaves in the LeafList (created in bsp.cpp)
00110 int numlistpartitions = 0;        // Number of partitions in the PartitionList (created in bsp.cpp)
00111 int numcurrentportals = 0;        // Number of portals in the currentleaf
00112 
00113 // BSP
00114 int numleaves = 0;                // Total number of leaves in the bsp
00115 int currentleaf = 0;              // Current leaf based on camera position
00116 int numpartitions = 0;            // Total number of partitions in the bsp
00117 bool BuiltBSP = false;
00118 BSP_node* root = new BSP_node;
00119 
00120 // Portals
00121 LinkedList<PORTAL> PortalList;    // Portal list
00122 int numportals = 0;               // The number of portals in the PortalList
00123 PORTAL* portal;                   // Global pointer for working with the portals
00124 
00125 // Static Lights
00126 int numStaticLights = 9;
00127 StaticLight* staticlight = new StaticLight[numStaticLights];
00128 
00129 // Lightmap
00130 int numLightmaps = 0;
00131 Lightmap* lightmap = new Lightmap[numPolygons];
00132 
00133 // Splines
00134 int visible = 0;                // Toggle flag for viewing the splines
00135 int numSplines = 0;             // Not zero based
00136 int cameraMode = 2;             // Camera mode (0 = Free, 1 = Look, 2 = Follow)
00137 int currentSpline = 0;          // Current spline to work with or use for a path
00138 int lookAtPath = 0;             // Spline to look at when in Follow mode
00139 char SplineFileName[MAX_PATH];  // filename and path to the spline data
00140 SPLINE* spline;                 // Global pointer for working with the splines from list
00141 LinkedList<SPLINE> SplineList;  // Spline list. Note that you can't make this a pointer.
00142 
00143 // Linked Lists of leaf, partition and portal nodes
00144 LinkedList<ListNode> LeafList;
00145 LinkedList<ListNode> PartitionList;
00146 ListNode* listnode;
00147 
00148 int InitGL(int Width, int Height)
00149 {
00150     CLog::addLine("--- Program Start ---");
00151 
00152     int ReturnValue;
00153     ApplicationStartTime = (float)GetTickCount();
00154 
00155     SetGLProperties();
00156     SetGLMaterial();
00157     SetGLLighting(light);
00158     SetGLCamera(camera);
00159     cameraMode = 2;
00160     SetSplines(SplineList);
00161 
00162     if (!SetGLTexture(texture))
00163         ReturnValue = 0;
00164     else
00165         ReturnValue = 1;
00166 
00167     // Create the font texture
00168     glFontCreate(&myFont, "roman.glf", 600);
00169 
00170     SetGLWorld(polygon, texture, vertex);
00171 
00172     // Find the bounding box of the data set
00173     Min_X = polygon[0].Vertex[0].x;
00174     Min_Y = polygon[0].Vertex[0].y;
00175     Min_Z = polygon[0].Vertex[0].z;
00176     Max_X = polygon[0].Vertex[0].x;
00177     Max_Y = polygon[0].Vertex[0].y;
00178     Max_Z = polygon[0].Vertex[0].z;
00179     for (int loop = 0; loop < numPolygons; loop++)
00180     {
00181         for (int i = 0; i < 3; i++)
00182         {
00183             if (polygon[loop].Vertex[i].x < Min_X )
00184                 Min_X = polygon[loop].Vertex[i].x;
00185             if (polygon[loop].Vertex[i].y < Min_Y )
00186                 Min_Y = polygon[loop].Vertex[i].y;
00187             if (polygon[loop].Vertex[i].z < Min_Z )
00188                 Min_Z = polygon[loop].Vertex[i].z;
00189             if (polygon[loop].Vertex[i].x > Max_X )
00190                 Max_X = polygon[loop].Vertex[i].x;
00191             if (polygon[loop].Vertex[i].y > Max_Y )
00192                 Max_Y = polygon[loop].Vertex[i].y;
00193             if (polygon[loop].Vertex[i].z > Max_Z )
00194                 Max_Z = polygon[loop].Vertex[i].z;
00195         }
00196     }
00197 
00198     // BSP initialization
00199     for (int i = 0; i < numPolygons; i++)
00200         bsppolygon[i] = polygon[i];
00201 
00202     root->nodeid = 0;
00203     root->leaf = 0;
00204     root->visible = 0;
00205     root->numpolys = numPolygons;
00206     root->nodepolylist = bsppolygon;
00207     root->nodelightmaplist = lightmap;
00208     
00209     BuildBSP(root);
00210     BuiltBSP = true;
00211 
00212     MakeNodeLists(root);      // Create lists of the partition and leaf nodes
00213     MakePortalList();         // Create the large portals and add them to a portal list
00214 
00215     AddPortalsToLeaves(root); // Add the portals to the bsp tree
00216     FindTruePortals(root);    // Remove the excess portals
00217 
00218     // initialize static lights
00219     SetStaticLights(staticlight);
00220 
00221     // Create the lightmaps
00222     CreateBSPLightmaps(root);
00223     LoadBSPLightmaps(root);
00224 
00225     return ReturnValue;
00226 }
00227 
00228 void ReSizeGLScene(int Width, int Height)
00229 {
00230     SetGLView(Width, Height);
00231 }
00232 
00233 void DrawGLScene(void)
00234 {
00235     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00236 
00237     LastCam = camera[currentCamera];
00238     camera[currentCamera].Update();
00239 
00240     CollisionPacket cp;
00241     cp.eRadius.x = 1.0;
00242     cp.eRadius.y = 1.0;
00243     cp.eRadius.z = 1.0;
00244     cp.sourcePoint.x = LastCam.Position.x;
00245     cp.sourcePoint.y = LastCam.Position.y;
00246     cp.sourcePoint.z = LastCam.Position.z;
00247     cp.velocity.x = camera[currentCamera].Position.x - LastCam.Position.x;
00248     cp.velocity.y = camera[currentCamera].Position.y - LastCam.Position.y;
00249     cp.velocity.z = camera[currentCamera].Position.z - LastCam.Position.z;
00250 
00251     CheckForCollision(polygon, &camera[currentCamera].Position, &cp);
00252 
00253     camera[currentCamera].Apply();
00254 
00255     for(int loop = 0; loop <= numLights; loop++)
00256         light[loop].Apply();
00257 
00258     currentleaf = FindCurrentLeaf(camera[currentCamera].Position, root);
00259 
00260     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
00261     DrawWorld(root);
00262     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
00263 
00264 /*
00265     glPushMatrix();
00266     glDisable(GL_TEXTURE_2D);
00267     glDisable(GL_LIGHTING);
00268 
00269     // Draw bounding box of data set
00270     glColor3f(1.0, 0.0, 0.0);
00271     glBegin(GL_LINES);
00272         glVertex3f(Min_X, Min_Y, Min_Z);
00273         glVertex3f(Min_X, Max_Y, Min_Z);
00274 
00275         glVertex3f(Min_X, Min_Y, Min_Z);
00276         glVertex3f(Max_X, Min_Y, Min_Z);
00277 
00278         glVertex3f(Min_X, Max_Y, Min_Z);
00279         glVertex3f(Max_X, Max_Y, Min_Z);
00280 
00281         glVertex3f(Max_X, Max_Y, Min_Z);
00282         glVertex3f(Max_X, Min_Y, Min_Z);
00283 
00284         glVertex3f(Min_X, Min_Y, Min_Z);
00285         glVertex3f(Min_X, Min_Y, Max_Z);
00286 
00287         glVertex3f(Max_X, Min_Y, Min_Z);
00288         glVertex3f(Max_X, Min_Y, Max_Z);
00289 
00290         glVertex3f(Min_X, Max_Y, Min_Z);
00291         glVertex3f(Min_X, Max_Y, Max_Z);
00292 
00293         glVertex3f(Max_X, Max_Y, Min_Z);
00294         glVertex3f(Max_X, Max_Y, Max_Z);
00295 
00296         glVertex3f(Min_X, Min_Y, Max_Z);
00297         glVertex3f(Min_X, Max_Y, Max_Z);
00298 
00299         glVertex3f(Min_X, Min_Y, Max_Z);
00300         glVertex3f(Max_X, Min_Y, Max_Z);
00301 
00302         glVertex3f(Min_X, Max_Y, Max_Z);
00303         glVertex3f(Max_X, Max_Y, Max_Z);
00304 
00305         glVertex3f(Max_X, Max_Y, Max_Z);
00306         glVertex3f(Max_X, Min_Y, Max_Z);
00307     glEnd();
00308 
00309     glEnable(GL_TEXTURE_2D);
00310     glEnable(GL_LIGHTING);
00311     glPopMatrix();
00312 //*/
00313 
00314     DrawSplines(SplineList);           // Required to calculate the camera path
00315     DrawMyText();
00316 }
00317 
00318 LRESULT CALLBACK WndProc(    HWND    hWnd,
00319                             UINT    message,
00320                             WPARAM    wParam,
00321                             LPARAM    lParam)
00322 {
00323     GLuint    PixelFormat;
00324     static    PIXELFORMATDESCRIPTOR pfd=
00325     {
00326            sizeof(PIXELFORMATDESCRIPTOR),
00327         1,
00328         PFD_DRAW_TO_WINDOW |
00329         PFD_SUPPORT_OPENGL |
00330         PFD_DOUBLEBUFFER,
00331         PFD_TYPE_RGBA,
00332         16,
00333         0, 0, 0, 0, 0, 0,
00334         0,
00335         0,
00336         0,
00337         0, 0, 0, 0,
00338         16,
00339         0,
00340         0,
00341         PFD_MAIN_PLANE,
00342         0,
00343         0, 0, 0
00344     };
00345 
00346 
00347     switch (message)
00348     {
00349         case WM_CREATE:
00350             hDC = GetDC(hWnd);
00351 
00352             PixelFormat = ChoosePixelFormat(hDC, &pfd);
00353 
00354             if (!PixelFormat)
00355             {
00356                 MessageBox(NULL,"Can't find a suitable PixelFormat.","Error",MB_OK|MB_ICONERROR);
00357                 PostQuitMessage(0);
00358                 break;
00359             }
00360 
00361             if(!SetPixelFormat(hDC,PixelFormat,&pfd))
00362             {
00363                 MessageBox(NULL,"Can't set the PixelFormat.","Error",MB_OK|MB_ICONERROR);
00364                 PostQuitMessage(0);
00365                 break;
00366             }
00367 
00368             hRC = wglCreateContext(hDC);
00369             if(!hRC)
00370             {
00371                 MessageBox(NULL,"Can't create a GL Rendering Context.","Error",MB_OK|MB_ICONERROR);
00372                 PostQuitMessage(0);
00373                 break;
00374             }
00375 
00376             if(!wglMakeCurrent(hDC, hRC))
00377             {
00378                 MessageBox(NULL,"Can't activate the GL Rendering Context.","Error",MB_OK|MB_ICONERROR);
00379                 PostQuitMessage(0);
00380                 break;
00381             }
00382         break;
00383 
00384         case WM_SYSCOMMAND:
00385         {
00386             switch (wParam)
00387             {
00388                 case SC_SCREENSAVE:
00389                 case SC_MONITORPOWER:
00390                     return 0;
00391             }
00392             break;
00393         }
00394 
00395         if (DialogInUse)
00396         {
00397             case WM_PAINT:
00398                 BeginPaint(hWnd,&ps);
00399                 DrawGLScene();
00400                 glFlush();
00401                 SwapBuffers(hDC);
00402                 EndPaint(hWnd,&ps);
00403             break;
00404         }
00405 
00406         case WM_CLOSE:
00407             delete[] lightmap;
00408             delete[] staticlight;
00409             delete[] texture;
00410             delete[] vertex;
00411             delete[] camera;
00412             delete[] light;
00413             delete[] polygon;
00414 
00415             for (int i = numSplines - 1; i >= 0; i--)
00416                 DeleteSpline(i, SplineList);
00417 
00418             if (BuiltBSP)
00419                 DeleteBSP(root);
00420             delete root;
00421 
00422             for (int i = numportals; i > 0; i--)
00423             {
00424                 portal = PortalList.Get(i);
00425                 delete[] portal->Vertex;
00426             }
00427             
00428             glFontDestroy(&myFont);
00429             
00430             CLog::addLine("--- End of Program ---");
00431             Console.Close();
00432 
00433             ChangeDisplaySettings(NULL, 0);
00434             wglMakeCurrent(hDC,NULL);
00435             wglDeleteContext(hRC);
00436             ReleaseDC(hWnd,hDC);
00437             DestroyWindow(hWnd);
00438         break;
00439 
00440         case WM_DESTROY:
00441             PostQuitMessage(0);
00442         break;
00443 
00444         case WM_KEYDOWN:
00445             key[wParam] = TRUE;
00446         break;
00447 
00448         case WM_KEYUP:
00449             key[wParam] = FALSE;
00450         break;
00451 
00452         case WM_SIZE:
00453             SetCursorPos((int)(screen.right * 0.5), (int)(screen.bottom * 0.5));
00454             ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));
00455         break;
00456 
00457         case WM_MOUSEMOVE:
00458             if (cameraMode == 0)
00459             {
00460                 camera[currentCamera].Delta_x = float(HIWORD(lParam) - screen.bottom * 0.5) * 10;
00461                 camera[currentCamera].Delta_y = float(LOWORD(lParam) - screen.right * 0.5) * 10;
00462             }
00463         break;
00464 
00465         case WM_LBUTTONDOWN:
00466             camera[currentCamera].Delta_z = -120.0;
00467         break;
00468 
00469         case WM_RBUTTONDOWN:
00470             camera[currentCamera].Delta_z = 120.0;
00471         break;
00472 
00473         case WM_LBUTTONUP:
00474             if (wParam != MK_RBUTTON)
00475                 camera[currentCamera].Delta_z = 0.0;
00476         break;
00477 
00478         case WM_RBUTTONUP:
00479             if (wParam != MK_LBUTTON)
00480                 camera[currentCamera].Delta_z = 0.0;
00481         break;
00482 
00483         default:
00484             return (DefWindowProc(hWnd, message, wParam, lParam));
00485     }
00486 return (0);
00487 }
00488 
00489 int WINAPI WinMain(    HINSTANCE    hInstance,
00490                     HINSTANCE,
00491                     LPSTR,
00492                     int)
00493 {
00494     MSG        msg;
00495     g_hInst = hInstance;
00496     GetWindowRect(GetDesktopWindow(), &screen);
00497 
00498     WNDCLASSEX    wc;
00499     wc.cbSize = sizeof(WNDCLASSEX);
00500     wc.style            = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_SAVEBITS;
00501     wc.lpfnWndProc        = (WNDPROC) WndProc;
00502     wc.cbClsExtra        = 0;
00503     wc.cbWndExtra        = 0;
00504     wc.hInstance        = hInstance;
00505     wc.hIcon            = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYICON));
00506     wc.hIconSm          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYICON));
00507     wc.hCursor            = LoadCursor(NULL, IDC_ARROW);
00508     wc.hbrBackground    = NULL;
00509     wc.lpszMenuName        = NULL;
00510     wc.lpszClassName    = "OpenGL WinClass";
00511 
00512 
00513     if(!RegisterClassEx(&wc))
00514     {
00515         MessageBox(NULL,"Failed To Register The Window Class.","Error",MB_OK|MB_ICONERROR);
00516         return FALSE;
00517     }
00518 
00519     hWnd = CreateWindowEx(
00520     WS_EX_LEFT,
00521     "OpenGL WinClass",
00522     "OpenGL & Win32 Tutorial No.13",
00523     WS_MAXIMIZE |
00524     WS_CLIPCHILDREN |
00525     WS_CLIPSIBLINGS |
00526     WS_POPUPWINDOW |
00527     WS_VISIBLE,
00528     0, 0,
00529     screen.right, screen.bottom,
00530     NULL,
00531     NULL,
00532     hInstance,
00533     NULL);
00534 
00535     if(!hWnd)
00536     {
00537         MessageBox(NULL,"Window Creation Error.","Error",MB_OK|MB_ICONERROR);
00538         return FALSE;
00539     }
00540 
00541     DEVMODE dmScreenSettings;
00542     memset(&dmScreenSettings, 0, sizeof(DEVMODE));
00543     dmScreenSettings.dmSize        = sizeof(DEVMODE);
00544     dmScreenSettings.dmPelsWidth    = screen.right;
00545     dmScreenSettings.dmPelsHeight    = screen.bottom;
00546     dmScreenSettings.dmFields    = DM_PELSWIDTH | DM_PELSHEIGHT;
00547     ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);
00548 
00549     ShowWindow(hWnd, SW_HIDE);
00550 
00551     GetCurrentDirectory(MAX_PATH, AppDirectory);
00552 
00553     Console.Open();
00554 
00555     if(DialogBox(hInstance, "STARTDLG", hWnd, (DLGPROC)StartProc) == IDOK)
00556     {
00557         if (!InitGL(screen.right, screen.bottom))
00558         {
00559             Console.Close();
00560             SendMessage(hWnd,WM_CLOSE,0,0);
00561         }
00562         else
00563         {
00564             ShowWindow(hWnd, SW_SHOW);
00565             UpdateWindow(hWnd);
00566             SetFocus(hWnd);
00567             wglMakeCurrent(hDC,hRC);
00568             SetCursorPos((int)(screen.right * 0.5), (int)(screen.bottom * 0.5));
00569             ShowCursor(0);
00570         }
00571     }
00572     else
00573     {
00574         delete[] lightmap;
00575         delete[] staticlight;
00576         delete[] texture;
00577         delete[] vertex;
00578         delete[] camera;
00579         delete[] light;
00580         delete[] polygon;
00581         delete[] bsppolygon;
00582         delete root;
00583         PostQuitMessage(0);            
00584     }
00585     
00586     while (1)
00587     {
00588         while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
00589         {
00590             if (GetMessage(&msg, NULL, 0, 0))
00591             {
00592                 TranslateMessage(&msg);
00593                 DispatchMessage(&msg);
00594             }
00595             else
00596             {
00597                 return TRUE;
00598             }
00599         }
00600 
00601         if(!DialogInUse)
00602         {
00603             SetCursorPos((int)(screen.right * 0.5), (int)(screen.bottom * 0.5));
00604             DrawGLScene();
00605             glFlush();
00606               SwapBuffers(hDC);
00607         }
00608 
00609         multiplier = GetTimePassed(lasttime, average, lastmultiplier);
00610         camera[currentCamera].Multiplier = multiplier;
00611         light[currentLight].Multiplier = multiplier;
00612 
00613         if (key['C'] && released_key['C'] == 0)
00614         {
00615             if (currentCamera < numCameras)
00616                 currentCamera++;
00617             else
00618                 currentCamera = 0;
00619             released_key['C'] = 1;
00620         }
00621 
00622         if (!key['C'])
00623             released_key['C'] = 0;
00624 
00625         if (key['L'] && released_key['L'] == 0)
00626         {
00627             if (currentLight < numLights)
00628                 currentLight++;
00629             else
00630                 currentLight = 0;
00631             released_key['L'] = 1;
00632         }
00633 
00634         if (!key['L'])
00635             released_key['L'] = 0;
00636 /*
00637         if (key['I'] && released_key['I'] == 0)
00638         {
00639             DialogInUse = 1;
00640             lightColor[0] = light[currentLight].Ambient[0];
00641             lightColor[1] = light[currentLight].Ambient[1];
00642             lightColor[2] = light[currentLight].Ambient[2];
00643             ShowCursor(1);
00644             GetLightColor();
00645             key['I'] = 0;
00646             ShowCursor(0);
00647             SetCursorPos(screen.right * 0.5, screen.bottom * 0.5);
00648             light[currentLight].Ambient[0] = lightColor[0];
00649             light[currentLight].Ambient[1] = lightColor[1];
00650             light[currentLight].Ambient[2] = lightColor[2];
00651             light[currentLight].Update();
00652             DialogInUse = 0;
00653         }
00654 
00655         if (!key['I'])
00656             released_key['I'] = 0;
00657 
00658         if (key['O'] && released_key['O'] == 0)
00659         {
00660             DialogInUse = 2;
00661             lightColor[0] = light[currentLight].Diffuse[0];
00662             lightColor[1] = light[currentLight].Diffuse[1];
00663             lightColor[2] = light[currentLight].Diffuse[2];
00664             ShowCursor(1);
00665             GetLightColor();
00666             key['O'] = 0;
00667             ShowCursor(0);
00668             SetCursorPos(screen.right * 0.5, screen.bottom * 0.5);
00669             light[currentLight].Diffuse[0] = lightColor[0];
00670             light[currentLight].Diffuse[1] = lightColor[1];
00671             light[currentLight].Diffuse[2] = lightColor[2];
00672             light[currentLight].Update();
00673             DialogInUse = 0;
00674         }
00675 
00676         if (!key['O'])
00677             released_key['O'] = 0;
00678 
00679         if (key['P'] && released_key['P'] == 0)
00680         {
00681             DialogInUse = 3;
00682             lightColor[0] = light[currentLight].Specular[0];
00683             lightColor[1] = light[currentLight].Specular[1];
00684             lightColor[2] = light[currentLight].Specular[2];
00685             ShowCursor(1);
00686             GetLightColor();
00687             key['P'] = 0;
00688             ShowCursor(0);
00689             SetCursorPos(screen.right * 0.5, screen.bottom * 0.5);
00690             light[currentLight].Specular[0] = lightColor[0];
00691             light[currentLight].Specular[1] = lightColor[1];
00692             light[currentLight].Specular[2] = lightColor[2];
00693             light[currentLight].Update();
00694             DialogInUse = 0;
00695         }
00696 
00697         if (!key['P'])
00698             released_key['P'] = 0;
00699 */
00700         if (key['P'] && released_key['P'] == 0)
00701         {
00702             if (showportals)
00703                 showportals = 0;
00704             else
00705                 showportals = 1;
00706             released_key['P'] = 1;
00707         }
00708 
00709         if (!key['P'])
00710             released_key['P'] = 0;
00711 /*
00712         if (key['H'] && released_key['H'] == 0)
00713         {
00714             if (visible)
00715                 visible = 0;
00716             else
00717                 visible = 1;
00718             released_key['H'] = 1;
00719         }
00720 
00721         if (!key['H'])
00722             released_key['H'] = 0;
00723 
00724         if (key['S'] && released_key['S'] == 0)
00725         {
00726             if (currentSpline < numSplines - 1)
00727                 currentSpline++;
00728             else
00729                 currentSpline = 0;
00730             released_key['S'] = 1;
00731         }
00732 
00733         if (!key['S'])
00734             released_key['S'] = 0;
00735 
00736         if (key['T'] && released_key['T'] == 0)
00737         {
00738             if (lookAtPath < numSplines - 1)
00739                 lookAtPath++;
00740             else
00741                 lookAtPath = 0;
00742             released_key['T'] = 1;
00743         }
00744 
00745         if (!key['T'])
00746             released_key['T'] = 0;
00747 //*/
00748         if (key['M'] && released_key['M'] == 0)
00749         {
00750 /*
00751             if (cameraMode < 2)
00752                 cameraMode++;
00753             else
00754                 cameraMode = 0;
00755 */
00756             if (cameraMode == 2)
00757                 cameraMode = 0;
00758             else
00759                 cameraMode = 2;
00760             released_key['M'] = 1;
00761         }
00762 
00763         if (!key['M'])
00764             released_key['M'] = 0;
00765 
00766         if (key[49])
00767         {
00768             step = 10.0;
00769         }
00770 
00771         if (key[50])
00772         {
00773             step = 20.0;
00774         }
00775 
00776         if (key[51])
00777         {
00778             step = 30.0;
00779         }
00780 
00781         if (key[52])
00782         {
00783             step = 40.0;
00784         }
00785 
00786         if (key[53])
00787         {
00788             step = 50.0;
00789         }
00790 
00791         if (key[54])
00792         {
00793             step = 60.0;
00794         }
00795 
00796         if (key[55])
00797         {
00798             step = 70.0;
00799         }
00800 
00801         if (key[56])
00802         {
00803             step = 80.0;
00804         }
00805 
00806         if (key[57])
00807         {
00808             step = 90.0;
00809         }
00810 
00811         if (key[VK_NUMPAD6])
00812         {
00813             light[currentLight].Movement_x += step;
00814         }
00815 
00816         if (key[VK_NUMPAD4])
00817         {
00818             light[currentLight].Movement_x -= step;
00819         }
00820 
00821         if (key[VK_NUMPAD2])
00822         {
00823             light[currentLight].Movement_z += step;
00824         }
00825 
00826         if (key[VK_NUMPAD8])
00827         {
00828             light[currentLight].Movement_z -= step;
00829         }
00830 
00831         if (key[VK_NUMPAD7])
00832         {
00833             light[currentLight].Movement_y += step;
00834         }
00835 
00836         if (key[VK_NUMPAD9])
00837         {
00838             light[currentLight].Movement_y -= step;
00839         }
00840 
00841         if (key[VK_NUMPAD5] && released_key[VK_NUMPAD5] == 0)
00842         {
00843             if (light[currentLight].Positional == FALSE)
00844                 light[currentLight].Positional = TRUE;
00845             else
00846                 light[currentLight].Positional = FALSE;
00847             released_key[VK_NUMPAD5] = 1;
00848         }
00849 
00850         if (!key[VK_NUMPAD5])
00851             released_key[VK_NUMPAD5] = 0;
00852 
00853         if (key[VK_RIGHT])
00854         {
00855             camera[currentCamera].Movement_x += step;
00856         }
00857 
00858         if (key[VK_LEFT])
00859         {
00860             camera[currentCamera].Movement_x -= step;
00861         }
00862 
00863         if (key[VK_DOWN])
00864         {
00865             camera[currentCamera].Movement_z += step;
00866         }
00867 
00868         if (key[VK_UP])
00869         {
00870             camera[currentCamera].Movement_z -= step;
00871         }
00872 
00873         if (key[VK_PRIOR])
00874         {
00875             camera[currentCamera].Movement_y += step;
00876         }
00877 
00878         if (key[VK_NEXT])
00879         {
00880             camera[currentCamera].Movement_y -= step;
00881         }
00882 
00883         if (key[VK_SPACE])
00884         {
00885             camera[currentCamera].Reset();
00886         }
00887 
00888         if (key[VK_ESCAPE] || key['Q'])
00889             SendMessage(hWnd,WM_CLOSE,0,0);
00890     }
00891 }
00892 
00893 
00894 
00895                                       
00896 
00897 

Generated on Fri Dec 23 05:20:18 2005 for Portals by doxygen1.2.15