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

Generated on Fri Dec 23 05:15:47 2005 for Constructive Solid Geometry by doxygen1.2.15