Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

main.cpp

Go to the documentation of this file.
00001 /*
00002  *              This Code Was Created By Jeff Molofee 2000
00003  *              A HUGE Thanks To Fredric Echols For Cleaning Up
00004  *              And Optimizing The Base Code, Making It More Flexible!
00005  *              If You've Found This Code Useful, Please Let Me Know.
00006  *              Visit My Site At nehe.gamedev.net
00007  */
00008 
00009 #include <windows.h>            // Header File For Windows
00010 #include <gl\gl.h>                      // Header File For The OpenGL32 Library
00011 #include <gl\glu.h>                     // Header File For The GLu32 Library
00012 
00013 #include "gl_init.h"        // All initialization code is in here now
00014 #include "renderer.h"
00015 #include "PhysSystem.h"
00016 
00017 #include "TglText.h"
00018 
00019 Renderer *renderer;
00020 PhysSystem *world;
00021 bool start, mouse_free;
00022 int pause_mode;  
00023 
00024 
00025 int DrawGLScene(GLvoid)                                                                 // Here's Where We Do All The Drawing
00026 {
00027         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);     // Clear Screen And Depth Buffer
00028     glDisable(GL_LIGHTING);
00029         glLoadIdentity();                                                                       // Reset The Current Modelview Matrix
00030 
00031     glColor3f(1,1,1);
00032     TglText tmp_text;
00033     glTranslatef(0.0f,0.0f,-1.0f);
00034     glRasterPos2f(-.55, .38);
00035     tmp_text.glPrint("%f %f %f: %f",world->obj_list[1].qrot_velocity.v.data[0],
00036                                     world->obj_list[1].qrot_velocity.v.data[1],
00037                                     world->obj_list[1].qrot_velocity.v.data[2],
00038                                     world->obj_list[1].qrot_velocity.n);
00039     glRasterPos2f(-.55, .365);
00040     tmp_text.glPrint("%f %f %f: %f",world->obj_list[1].center->rot.v.data[0],
00041                                     world->obj_list[1].center->rot.v.data[1],
00042                                     world->obj_list[1].center->rot.v.data[2],
00043                                     world->obj_list[1].center->rot.n);
00044     glTranslatef(0.0f,0.0f,1.0f);
00045     glEnable(GL_LIGHTING);
00046 
00047         renderer->Draw();
00048         if(pause_mode == 0)
00049         world->UpdateAll();
00050 
00051         return TRUE;                                                                            // Keep Going
00052 }
00053 
00054 
00055 int WINAPI WinMain(     HINSTANCE       hInstance,                      // Instance
00056                                         HINSTANCE       hPrevInstance,          // Previous Instance
00057                                         LPSTR           lpCmdLine,                      // Command Line Parameters
00058                                         int                     nCmdShow)                       // Window Show State
00059 
00060 {
00061     start = false;                             // For delaying start until user is ready
00062     mouse_free = false;
00063     pause_mode = 1;                         // 0=normal, 1=paused, 2=paused w/ free mouse
00064     bool mp2 = true;
00065     MSG         msg;                                                                    // Windows Message Structure
00066         BOOL    done=FALSE;                                                             // Bool Variable To Exit Loop
00067     POINT pt;                                       // For Mouse Control
00068     int mode;                                       // Render Mode
00069     bool mp = true;                                 // Render Bool
00070     bool cull = true;
00071     const int dim[2] = {1024, 768};
00072 
00073         // Ask The User Which Screen Mode They Prefer
00074         if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
00075                 fullscreen=FALSE;                                                       // Windowed Mode
00076         // Create Our OpenGL Window
00077         if (!CreateGLWindow("BRE",dim[0],dim[1],16,fullscreen))
00078                 return 0;                                                                       // Quit If Window Was Not Created
00079 
00080     renderer = new Renderer(); 
00081     renderer->Main_Cam->rot = Quaternion(0, 0, 0);
00082     renderer->Main_Cam->SetPos(glVector (0,0,40));
00083     renderer->LoadWorld("world2");
00084     
00085     world = new PhysSystem;
00086     world->AddObjects(renderer->object_list);
00087 //    world->obj_list[0].qrot_velocity = Quaternion(0, 0, -1);
00088 //    world->obj_list[0].velocity = glVector(40, 0, 0);
00089     
00090     world->physics_timer.Init();
00091 
00092     SetCursorPos(dim[0]/2,dim[1]/2);                // To avoid inital rotations
00093         while(!done)                                                                    // Loop That Runs While done=FALSE
00094         {
00095                 if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))       // Is There A Message Waiting?
00096                 {
00097                         if (msg.message==WM_QUIT)                               // Have We Received A Quit Message?
00098                         {
00099                                 done=TRUE;                                                      // If So done=TRUE
00100                         }
00101                         else                                                                    // If Not, Deal With Window Messages
00102                         {
00103                                 TranslateMessage(&msg);                         // Translate The Message
00104                                 DispatchMessage(&msg);                          // Dispatch The Message
00105                         }
00106                 }
00107                 else                                                                            // If There Are No Messages
00108                 {
00109                         // Draw The Scene.  Watch For ESC Key And Quit Messages From DrawGLScene()
00110             if ((active && !DrawGLScene()) || keys[VK_ESCAPE])  // Active?  Was There A Quit Received?
00111                         {
00112                                 done=TRUE;                                                      // ESC or DrawGLScene Signalled A Quit
00113                         }
00114                         else                                                                    // Not Time To Quit, Update Screen
00115                         {
00116                                 SwapBuffers(hDC);                                       // Swap Buffers (Double Buffering)
00117                         }
00118             if(pause_mode != 2)
00119             {
00120                 GetCursorPos(&pt);
00121                 if(pt.x != dim[0]/2)
00122                     renderer->Control_Point->rot = renderer->Control_Point->rot * Quaternion(float(dim[0]/2 - pt.x)/200.0,glVector(0,1,0));
00123                 if(pt.y != dim[1]/2)
00124                     renderer->Control_Point->rot = renderer->Control_Point->rot * Quaternion(float(dim[1]/2 - pt.y)/200.0,glVector(1,0,0));
00125                 SetCursorPos(dim[0]/2,dim[1]/2);
00126             }
00127     
00128 
00129             if(keys[VK_SPACE] && !mp2)
00130             {
00131                 world->physics_timer.Init();
00132                 start = !start;
00133                 pause_mode++;
00134                 if(pause_mode > 1)  pause_mode = 0;
00135                 SetCursorPos(dim[0]/2,dim[1]/2);
00136                 mp2=TRUE;
00137             }
00138             if(!keys[VK_SPACE])
00139             {
00140                 if(mp2 && pause_mode != 2)
00141                     SetCursorPos(dim[0]/2,dim[1]/2);
00142                 mp2=FALSE;
00143             }
00144 
00145                         if (keys[VK_UP])
00146                                 renderer->Control_Point->Slide(glVector(0,0,-1.8));
00147             if (keys[VK_DOWN])
00148                                 renderer->Control_Point->Slide(glVector(0,0,1.8));
00149                         if (keys[VK_RIGHT])
00150                                 renderer->Control_Point->Slide(glVector(1.8,0,0));
00151                         if (keys[VK_LEFT])
00152                                 renderer->Control_Point->Slide(glVector(-1.8,0,0));
00153 
00154                         if (keys[VK_F1])                                                // Is F1 Being Pressed?
00155                         {
00156                                 keys[VK_F1]=FALSE;                                      // If So Make Key FALSE
00157                                 KillGLWindow();                                         // Kill Our Current Window
00158                                 fullscreen=!fullscreen;                         // Toggle Fullscreen / Windowed Mode
00159                                 // Recreate Our OpenGL Window
00160                                 if (!CreateGLWindow("BRE",dim[0],dim[1],16,fullscreen))
00161                                 {
00162                                         return 0;                                               // Quit If Window Was Not Created
00163                                 }
00164                         }
00165                         if (keys['M'] && !mp)
00166                         {
00167                                 mode+=1;
00168                                 if (mode>2)
00169                                         mode=0;
00170                                 switch (mode)
00171                                 {
00172                                 case 0:
00173                                         glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
00174                                         break;
00175                                 case 1:
00176                                         glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
00177                                         break;
00178                                 case 2:
00179                                         glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
00180                                 }
00181                                 mp=TRUE;
00182                         }
00183                         if (!keys['M'])
00184                         {
00185                                 mp=FALSE;
00186                         }
00187                         if (keys['C'])
00188                         {
00189                 cull = !cull;
00190                 if(cull)
00191                     glEnable(GL_CULL_FACE);
00192                 else
00193                     glDisable(GL_CULL_FACE);
00194             }
00195 /*            if (keys['A'])
00196                 world->obj_list[0].center->rot = world->obj_list[0].center->rot * Quaternion(0.1, 0, 0);
00197             if (keys['S'])
00198                 world->obj_list[0].center->rot = world->obj_list[0].center->rot * Quaternion(0, .1, 0);
00199             if (keys['D'])
00200                 world->obj_list[0].center->rot = world->obj_list[0].center->rot * Quaternion(0, 0, .1);
00201 */
00202                 }
00203         }
00204 
00205         // Shutdown
00206         KillGLWindow();                                                                 // Kill The Window
00207         return (msg.wParam);                                                    // Exit The Program
00208 }

Generated on Thu Apr 21 18:06:30 2005 for Basic Rendering Engine by  doxygen 1.4.1