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

Generated on Fri Dec 23 05:19:54 2005 for Particles by doxygen1.2.15