00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <windows.h>
00010 #include <gl\gl.h>
00011 #include <gl\glu.h>
00012
00013 #include "gl_init.h"
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)
00026 {
00027 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00028 glDisable(GL_LIGHTING);
00029 glLoadIdentity();
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;
00052 }
00053
00054
00055 int WINAPI WinMain( HINSTANCE hInstance,
00056 HINSTANCE hPrevInstance,
00057 LPSTR lpCmdLine,
00058 int nCmdShow)
00059
00060 {
00061 start = false;
00062 mouse_free = false;
00063 pause_mode = 1;
00064 bool mp2 = true;
00065 MSG msg;
00066 BOOL done=FALSE;
00067 POINT pt;
00068 int mode;
00069 bool mp = true;
00070 bool cull = true;
00071 const int dim[2] = {1024, 768};
00072
00073
00074 if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
00075 fullscreen=FALSE;
00076
00077 if (!CreateGLWindow("BRE",dim[0],dim[1],16,fullscreen))
00078 return 0;
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
00088
00089
00090 world->physics_timer.Init();
00091
00092 SetCursorPos(dim[0]/2,dim[1]/2);
00093 while(!done)
00094 {
00095 if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
00096 {
00097 if (msg.message==WM_QUIT)
00098 {
00099 done=TRUE;
00100 }
00101 else
00102 {
00103 TranslateMessage(&msg);
00104 DispatchMessage(&msg);
00105 }
00106 }
00107 else
00108 {
00109
00110 if ((active && !DrawGLScene()) || keys[VK_ESCAPE])
00111 {
00112 done=TRUE;
00113 }
00114 else
00115 {
00116 SwapBuffers(hDC);
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])
00155 {
00156 keys[VK_F1]=FALSE;
00157 KillGLWindow();
00158 fullscreen=!fullscreen;
00159
00160 if (!CreateGLWindow("BRE",dim[0],dim[1],16,fullscreen))
00161 {
00162 return 0;
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
00196
00197
00198
00199
00200
00201
00202 }
00203 }
00204
00205
00206 KillGLWindow();
00207 return (msg.wParam);
00208 }