Al's Programming Resource Homepage  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.10 - Bezier Splines
00003 // Alan Baylis 2001
00004 
00005 // This program demonstrates how to add support for splines created by my spline editor
00006 // called Spline_Ed. The spline calculating code was adapted from Keith Vertanen's
00007 // original source code which I have added for reference as 'original bspline.cpp'
00008 
00009 #include <windows.h>
00010 #include "shared.h"
00011 #include "general.h"          // added the spline data loading functions
00012 #include "tll.h"
00013 #include "vector.h"
00014 #include "vertex.h"
00015 #include "quat.h"
00016 #include "matrix.h"
00017 #include "texture.h"
00018 #include "locmath.h"
00019 #include "polygon.h"
00020 #include "object.h"
00021 #include "camera.h"
00022 #include "light.h"
00023 #include "collision.h"
00024 #include "glfont.h"
00025 #include "bspline.h"          // Spline class & functions
00026 #include "winfuncs.h"         // changed the start dialog process
00027 #include "mmgr.h"
00028 #include "resource.rh"
00029 
00030 // Windows
00031 static HGLRC hRC;
00032 static HDC hDC;
00033 HWND hWnd;
00034 HWND hWndStartDlg;
00035 HINSTANCE g_hInst;
00036 RECT screen;
00037 PAINTSTRUCT ps;
00038 char AppDirectory[MAX_PATH];               // This application's directory
00039 float ApplicationStartTime;              // Start time required for spline timing
00040 
00041 // Math
00042 float pi = 3.141592;
00043 float radian = pi / 180;
00044 float epsilon = 0.05;
00045 
00046 // Input
00047 bool key[256];
00048 bool released_key[256];
00049 
00050 // Cameras
00051 int currentCamera = 0;
00052 int numCameras = 4;
00053 float step = 5.0;
00054 
00055 // Timing
00056 float lasttime;
00057 float multiplier;
00058 const int average = 20;
00059 float lastmultiplier[average];
00060 int fps;
00061 
00062 // Lights
00063 int GL_LIGHT[8] = {GL_LIGHT0, GL_LIGHT1, GL_LIGHT2, GL_LIGHT3, GL_LIGHT4, GL_LIGHT5, GL_LIGHT6, GL_LIGHT7};
00064 int currentLight = 0;
00065 int numLights = 0;
00066 
00067 // Cube polygons
00068 POLYGON * polygon = new POLYGON[12];
00069 
00070 // Texture
00071 TEXTURE * texture = new TEXTURE[3];
00072 char HaloTypeName[MAX_PATH] = {"halo.tga"};
00073 char FireTypeName[MAX_PATH] = {"fire.tga"};
00074 
00075 // Camera
00076 CAMERA * camera = new CAMERA[numCameras + 1];
00077 CAMERA LastCam;
00078 
00079 // Lighting
00080 LIGHT * light = new LIGHT[numLights + 1];
00081 float lightColor[3] = {1.0, 1.0, 1.0};
00082 
00083 // Dialogs
00084 int DialogInUse = 0;
00085 char szText[BUFFER_SIZE];
00086 
00087 // Font
00088 GLFONT myFont;
00089 
00090 // Splines
00091 int visible = 1;                // Toggle flag for viewing the curves
00092 int numSplines = 2;             // Not zero based
00093 int cameraMode = 2;             // Camera mode (0 = Free, 1 = Look, 2 = Follow)
00094 int currentSpline = 0;          // Current spline to work with or use for a path
00095 int lookAtPath = 0;             // Spline to look at when in Follow mode
00096 char SplineFileName[MAX_PATH];  // filename and path to the spline data
00097 SPLINE* spline;                 // Global pointer for working with the splines from list
00098 LinkedList<SPLINE> SplineList;  // Spline list. Note that you can't make this a pointer.
00099                                 // Also note that the class declaration of objects you want to
00100                                 // put in the list must have the default constructor and destructor.
00101 
00102 int InitGL(int Width, int Height)
00103 {
00104     ApplicationStartTime = (float)GetTickCount();
00105     SetGLProperties();
00106     SetGLMaterial();
00107     SetGLLighting(light);
00108     SetGLWorld(polygon);
00109     SetGLCamera(camera);
00110     SetSplines(SplineList);                              // Create/Load splines from data file
00111 
00112     // Create the font texture
00113     glFontCreate(&myFont, "roman.glf", 4);
00114 
00115     if (!SetGLTexture(texture))
00116         return 0;
00117     else
00118         return 1;
00119 }
00120 
00121 void ReSizeGLScene(int Width, int Height)
00122 {
00123     SetGLView(Width, Height);
00124 }
00125 
00126 void DrawGLScene(void)
00127 {
00128       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00129 
00130     LastCam = camera[currentCamera];
00131     camera[currentCamera].Update();
00132 
00133     CollisionPacket cp;
00134     cp.eRadius.x = 1.0;
00135     cp.eRadius.y = 1.0;
00136     cp.eRadius.z = 1.0;
00137     cp.sourcePoint.x = LastCam.Position.x;
00138     cp.sourcePoint.y = LastCam.Position.y;
00139     cp.sourcePoint.z = LastCam.Position.z;
00140     cp.velocity.x = camera[currentCamera].Position.x - LastCam.Position.x;
00141     cp.velocity.y = camera[currentCamera].Position.y - LastCam.Position.y;
00142     cp.velocity.z = camera[currentCamera].Position.z - LastCam.Position.z;
00143 
00144     CheckForCollision(polygon, &camera[currentCamera].Position, &cp);
00145 
00146     camera[currentCamera].Apply();
00147 
00148     int loop;
00149     for(loop = 0; loop <= numLights; loop++)
00150         light[loop].Apply();
00151 
00152     GLUquadricObj * sphere = gluNewQuadric();      // sphere for control points
00153 
00154     for (int loop = 0; loop < numSplines; loop++)     // loop through all splines
00155     {
00156         spline = SplineList.Get(loop);               // get the spline from the linked list
00157 
00158         if (visible)                                 // if the curves are visible
00159         {
00160             // draw the control points
00161             glDisable(GL_TEXTURE_2D);
00162             float mat_ambient[] = {spline->Red, spline->Green, spline->Blue, 1.0 };
00163             float mat_diffuse[] = {spline->Red, spline->Green, spline->Blue, 1.0 };
00164             float mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
00165             glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
00166             glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
00167             glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
00168             for (int i=0; i <= spline->NumControl; i++)
00169             {
00170                 glPushMatrix();
00171                 glTranslatef(spline->Control[i].x, spline->Control[i].y, spline->Control[i].z);
00172                 gluSphere(sphere,0.4,10,10);
00173                 glPopMatrix();
00174             }
00175             glEnable(GL_TEXTURE_2D);
00176 
00177             // get the output point of this spline
00178             VECTOR Output = bsplinepoint(spline);
00179 
00180             // draw the point
00181             glPointSize(5.0);
00182             glColor3f(0.0, 1.0 ,0.0);
00183             glDisable(GL_TEXTURE_2D);
00184             glDisable(GL_LIGHTING);
00185             glPushMatrix();
00186             glBegin(GL_POINTS);
00187             glVertex3f(Output.x, Output.y, Output.z);
00188             glEnd();
00189             glPopMatrix();
00190             glEnable(GL_TEXTURE_2D);
00191             glEnable(GL_LIGHTING);
00192 
00193             if (cameraMode > 0 && currentSpline == loop) // if the camera mode is not free and this is the current spline
00194             {
00195                 VECTOR LookAt;
00196                 if (cameraMode == 2 && (currentSpline != lookAtPath)) // if the camera mode is follow
00197                 {
00198                     SPLINE* spline2 = SplineList.Get(lookAtPath);
00199                     LookAt = bsplinepoint(spline2);
00200                 }
00201                 camera[currentCamera].Position.x = Output.x;  // set the camera position to the current spline output
00202                 camera[currentCamera].Position.y = Output.y;
00203                 camera[currentCamera].Position.z = Output.z;
00204                 MATRIX mat;
00205                 glPushMatrix();
00206                 glLoadIdentity();
00207                 if (cameraMode == 2 && (currentSpline != lookAtPath)) // if the camera mode is follow
00208                     gluLookAt(Output.x, Output.y, Output.z, LookAt.x, LookAt.y, LookAt.z, 0, 1, 0);
00209                 else
00210                                                                       // else make the camera look at another position
00211                     gluLookAt(Output.x, Output.y, Output.z, light[currentLight].Position.x, light[currentLight].Position.y, light[currentLight].Position.z, 0, 1, 0);
00212                 glGetFloatv(GL_MODELVIEW_MATRIX, mat.Element);       // get the gluLookAt matrix
00213                 glPopMatrix();
00214 
00215                 float mat2[4][4];
00216                 mat2[0][0] = mat.Element[0];
00217                 mat2[0][1] = mat.Element[1];
00218                 mat2[0][2] = mat.Element[2];
00219                 mat2[0][3] = mat.Element[3];
00220                 mat2[1][0] = mat.Element[4];
00221                 mat2[1][1] = mat.Element[5];
00222                 mat2[1][2] = mat.Element[6];
00223                 mat2[1][3] = mat.Element[7];
00224                 mat2[2][0] = mat.Element[8];
00225                 mat2[2][1] = mat.Element[9];
00226                 mat2[2][2] = mat.Element[10];
00227                 mat2[2][3] = mat.Element[11];
00228                 mat2[3][0] = mat.Element[12];
00229                 mat2[3][1] = mat.Element[13];
00230                 mat2[3][2] = mat.Element[14];
00231                 mat2[3][3] = mat.Element[15];
00232 
00233                 camera[currentCamera].Orientation.MatrixToQuat(mat2);  // set the camera orientation to the gluLookAt matrix
00234             }
00235 
00236             bspline(spline);             // get the output points of this spline
00237 
00238             // draw the curve along to the output points
00239             glColor3f(spline->Red, spline->Green, spline->Blue);
00240             glDisable(GL_TEXTURE_2D);
00241             glDisable(GL_LIGHTING);
00242             glPushMatrix();
00243             glBegin(GL_LINE_STRIP);
00244             for (int i=0; i < spline->NumPoints; i++)
00245             {
00246                 glVertex3fv(&spline->Output[i].x);
00247             }
00248             glEnd();
00249             glPopMatrix();
00250             glEnable(GL_TEXTURE_2D);
00251             glEnable(GL_LIGHTING);
00252         }
00253 
00254         else if (cameraMode > 0) // if the curves are not visible and the camera mode is not free
00255         {
00256             VECTOR Output = bsplinepoint(spline);
00257 
00258             VECTOR LookAt;
00259             if (cameraMode == 2 && currentSpline != lookAtPath)
00260             {
00261                 SPLINE* spline2 = SplineList.Get(lookAtPath);
00262                 LookAt = bsplinepoint(spline2);
00263             }
00264             camera[currentCamera].Position.x = Output.x;
00265             camera[currentCamera].Position.y = Output.y;
00266             camera[currentCamera].Position.z = Output.z;
00267             MATRIX mat;
00268             glPushMatrix();
00269             glLoadIdentity();
00270             if (cameraMode == 2 && currentSpline != lookAtPath)
00271                 gluLookAt(Output.x, Output.y, Output.z, LookAt.x, LookAt.y, LookAt.z, 0, 1, 0);
00272             else
00273                 gluLookAt(Output.x, Output.y, Output.z, light[currentLight].Position.x, light[currentLight].Position.y, light[currentLight].Position.z, 0, 1, 0);
00274             glGetFloatv(GL_MODELVIEW_MATRIX, mat.Element);
00275             glPopMatrix();
00276 
00277             float mat2[4][4];
00278             mat2[0][0] = mat.Element[0];
00279             mat2[0][1] = mat.Element[1];
00280             mat2[0][2] = mat.Element[2];
00281             mat2[0][3] = mat.Element[3];
00282             mat2[1][0] = mat.Element[4];
00283             mat2[1][1] = mat.Element[5];
00284             mat2[1][2] = mat.Element[6];
00285             mat2[1][3] = mat.Element[7];
00286             mat2[2][0] = mat.Element[8];
00287             mat2[2][1] = mat.Element[9];
00288             mat2[2][2] = mat.Element[10];
00289             mat2[2][3] = mat.Element[11];
00290             mat2[3][0] = mat.Element[12];
00291             mat2[3][1] = mat.Element[13];
00292             mat2[3][2] = mat.Element[14];
00293             mat2[3][3] = mat.Element[15];
00294 
00295             camera[currentCamera].Orientation.MatrixToQuat(mat2);
00296         }
00297     }
00298 
00299     DrawGrid();
00300     DrawCube(polygon, texture);
00301     DrawBillboards(texture, light, camera);
00302     DrawMyText();   // Draw text last
00303 }
00304 
00305 LRESULT CALLBACK WndProc(    HWND    hWnd,
00306                             UINT    message,
00307                             WPARAM    wParam,
00308                             LPARAM    lParam)
00309 {
00310     GLuint    PixelFormat;
00311     static    PIXELFORMATDESCRIPTOR pfd=
00312     {
00313            sizeof(PIXELFORMATDESCRIPTOR),
00314         1,
00315         PFD_DRAW_TO_WINDOW |
00316         PFD_SUPPORT_OPENGL |
00317         PFD_DOUBLEBUFFER,
00318         PFD_TYPE_RGBA,
00319         16,
00320         0, 0, 0, 0, 0, 0,
00321         0,
00322         0,
00323         0,
00324         0, 0, 0, 0,
00325         16,
00326         0,
00327         0,
00328         PFD_MAIN_PLANE,
00329         0,
00330         0, 0, 0
00331     };
00332 
00333 
00334     switch (message)
00335     {
00336         case WM_CREATE:
00337             hDC = GetDC(hWnd);
00338 
00339             PixelFormat = ChoosePixelFormat(hDC, &pfd);
00340 
00341             if (!PixelFormat)
00342             {
00343                    MessageBox(NULL,"Can't find a suitable PixelFormat.","Error",MB_OK|MB_ICONERROR);
00344                 PostQuitMessage(0);
00345                 break;
00346             }
00347 
00348             if(!SetPixelFormat(hDC,PixelFormat,&pfd))
00349             {
00350                 MessageBox(NULL,"Can't set the PixelFormat.","Error",MB_OK|MB_ICONERROR);
00351                 PostQuitMessage(0);
00352                 break;
00353             }
00354 
00355             hRC = wglCreateContext(hDC);
00356             if(!hRC)
00357             {
00358                 MessageBox(NULL,"Can't create a GL Rendering Context.","Error",MB_OK|MB_ICONERROR);
00359                 PostQuitMessage(0);
00360                 break;
00361             }
00362 
00363             if(!wglMakeCurrent(hDC, hRC))
00364             {
00365                 MessageBox(NULL,"Can't activate the GL Rendering Context.","Error",MB_OK|MB_ICONERROR);
00366                 PostQuitMessage(0);
00367                 break;
00368             }
00369         break;
00370 
00371         case WM_SYSCOMMAND:
00372         {
00373             switch (wParam)
00374             {
00375                 case SC_SCREENSAVE:
00376                 case SC_MONITORPOWER:
00377                     return 0;
00378             }
00379             break;
00380         }
00381 
00382         if (DialogInUse)
00383         {
00384             case WM_PAINT:
00385                 BeginPaint(hWnd,&ps);
00386                 DrawGLScene();
00387                 glFlush();
00388                 SwapBuffers(hDC);
00389                 EndPaint(hWnd,&ps);
00390             break;
00391         }
00392 
00393         case WM_CLOSE:
00394             glFontDestroy(&myFont);
00395 
00396             delete[] texture;
00397             delete[] polygon;
00398             delete[] camera;
00399             delete[] light;
00400 
00401             for (int i = numSplines - 1; i >= 0; i--)
00402                 DeleteSpline(i, SplineList);
00403 
00404             ChangeDisplaySettings(NULL, 0);
00405             wglMakeCurrent(hDC,NULL);
00406             wglDeleteContext(hRC);
00407             ReleaseDC(hWnd,hDC);
00408             DestroyWindow(hWnd);
00409         break;
00410 
00411         case WM_DESTROY:
00412             PostQuitMessage(0);
00413         break;
00414 
00415         case WM_KEYDOWN:
00416             key[wParam] = TRUE;
00417         break;
00418 
00419         case WM_KEYUP:
00420             key[wParam] = FALSE;
00421         break;
00422 
00423         case WM_SIZE:
00424             SetCursorPos((int)(screen.right * 0.5), (int)(screen.bottom * 0.5));
00425             ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));
00426         break;
00427 
00428         case WM_MOUSEMOVE:
00429             if (cameraMode == 0)
00430             {
00431                 camera[currentCamera].Delta_x = float(HIWORD(lParam) - screen.bottom * 0.5) * 10;
00432                 camera[currentCamera].Delta_y = float(LOWORD(lParam) - screen.right * 0.5) * 10;
00433             }
00434         break;
00435 
00436         case WM_LBUTTONDOWN:
00437             camera[currentCamera].Delta_z = -120.0;
00438         break;
00439 
00440         case WM_RBUTTONDOWN:
00441             camera[currentCamera].Delta_z = 120.0;
00442         break;
00443 
00444         case WM_LBUTTONUP:
00445             if (wParam != MK_RBUTTON)
00446                 camera[currentCamera].Delta_z = 0.0;
00447         break;
00448 
00449         case WM_RBUTTONUP:
00450             if (wParam != MK_LBUTTON)
00451                 camera[currentCamera].Delta_z = 0.0;
00452         break;
00453 
00454         default:
00455             return (DefWindowProc(hWnd, message, wParam, lParam));
00456     }
00457 return (0);
00458 }
00459 
00460 int WINAPI WinMain(    HINSTANCE    hInstance,
00461                     HINSTANCE,
00462                     LPSTR,
00463                     int)
00464 {
00465     MSG        msg;
00466     g_hInst = hInstance;
00467     GetWindowRect(GetDesktopWindow(), &screen);
00468 
00469     WNDCLASSEX    wc;
00470     wc.cbSize = sizeof(WNDCLASSEX);
00471     wc.style            = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_SAVEBITS;
00472     wc.lpfnWndProc        = (WNDPROC) WndProc;
00473     wc.cbClsExtra        = 0;
00474     wc.cbWndExtra        = 0;
00475     wc.hInstance        = hInstance;
00476     wc.hIcon            = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYICON));
00477     wc.hIconSm          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYICON));
00478     wc.hCursor            = LoadCursor(NULL, IDC_ARROW);
00479     wc.hbrBackground    = NULL;
00480     wc.lpszMenuName        = NULL;
00481     wc.lpszClassName    = "OpenGL WinClass";
00482 
00483 
00484     if(!RegisterClassEx(&wc))
00485     {
00486         MessageBox(NULL,"Failed To Register The Window Class.","Error",MB_OK|MB_ICONERROR);
00487         return FALSE;
00488     }
00489 
00490     hWnd = CreateWindowEx(
00491     WS_EX_LEFT,
00492     "OpenGL WinClass",
00493     "OpenGL & Win32 Tutorial No.10",
00494     WS_MAXIMIZE |
00495     WS_CLIPCHILDREN |
00496     WS_CLIPSIBLINGS |
00497     WS_POPUPWINDOW |
00498     WS_VISIBLE,
00499     0, 0,
00500     screen.right, screen.bottom,
00501     NULL,
00502     NULL,
00503     hInstance,
00504     NULL);
00505 
00506     if(!hWnd)
00507     {
00508         MessageBox(NULL,"Window Creation Error.","Error",MB_OK|MB_ICONERROR);
00509         return FALSE;
00510     }
00511 
00512     DEVMODE dmScreenSettings;
00513     memset(&dmScreenSettings, 0, sizeof(DEVMODE));
00514     dmScreenSettings.dmSize        = sizeof(DEVMODE);
00515     dmScreenSettings.dmPelsWidth    = screen.right;
00516     dmScreenSettings.dmPelsHeight    = screen.bottom;
00517     dmScreenSettings.dmFields    = DM_PELSWIDTH | DM_PELSHEIGHT;
00518     ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);
00519 
00520     ShowWindow(hWnd, SW_HIDE);
00521 
00522     GetCurrentDirectory(MAX_PATH, AppDirectory);     // Get the application directory
00523 
00524     if(DialogBox(hInstance, "STARTDLG", hWnd, (DLGPROC)StartProc) == IDOK)
00525     {
00526         if (!InitGL(screen.right, screen.bottom))    // Moved the InitGL call to here (fails if the images did not load)
00527             SendMessage(hWnd, WM_CLOSE, 0, 0);
00528         else
00529         {
00530             ShowWindow(hWnd, SW_SHOW);
00531             UpdateWindow(hWnd);
00532             SetFocus(hWnd);
00533             wglMakeCurrent(hDC,hRC);
00534             SetCursorPos((int)(screen.right * 0.5), (int)(screen.bottom * 0.5));
00535             ShowCursor(0);
00536         }
00537     }
00538     else
00539     {
00540         delete[] texture;
00541         delete[] polygon;
00542         delete[] camera;
00543         delete[] light;    
00544         PostQuitMessage(0);
00545     }
00546     
00547     while (1)
00548     {
00549         while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
00550         {
00551             if (GetMessage(&msg, NULL, 0, 0))
00552             {
00553                 TranslateMessage(&msg);
00554                 DispatchMessage(&msg);
00555             }
00556             else
00557             {
00558                 return TRUE;
00559             }
00560         }
00561 
00562         if(!DialogInUse)
00563         {
00564             SetCursorPos((int)(screen.right * 0.5), (int)(screen.bottom * 0.5));
00565             DrawGLScene();
00566             glFlush();
00567               SwapBuffers(hDC);
00568         }
00569 
00570         multiplier = GetTimePassed(lasttime, average, lastmultiplier);
00571         camera[currentCamera].Multiplier = multiplier;
00572         light[currentLight].Multiplier = multiplier;
00573 
00574         if (key['C'] && released_key['C'] == 0)
00575         {
00576             if (currentCamera < numCameras)
00577                 currentCamera++;
00578             else
00579                 currentCamera = 0;
00580             released_key['C'] = 1;
00581         }
00582 
00583         if (!key['C'])
00584             released_key['C'] = 0;
00585 
00586         if (key['L'] && released_key['L'] == 0)
00587         {
00588             if (currentLight < numLights)
00589                 currentLight++;
00590             else
00591                 currentLight = 0;
00592             released_key['L'] = 1;
00593         }
00594 
00595         if (!key['L'])
00596             released_key['L'] = 0;
00597 
00598         if (key['I'] && released_key['I'] == 0)
00599         {
00600             DialogInUse = 1;
00601             lightColor[0] = light[currentLight].Ambient[0];
00602             lightColor[1] = light[currentLight].Ambient[1];
00603             lightColor[2] = light[currentLight].Ambient[2];
00604             ShowCursor(1);
00605             GetLightColor();
00606             key['I'] = 0;
00607             ShowCursor(0);
00608             SetCursorPos((int)(screen.right * 0.5), (int)(screen.bottom * 0.5));
00609             light[currentLight].Ambient[0] = lightColor[0];
00610             light[currentLight].Ambient[1] = lightColor[1];
00611             light[currentLight].Ambient[2] = lightColor[2];
00612             light[currentLight].Update();
00613             DialogInUse = 0;
00614         }
00615 
00616         if (!key['I'])
00617             released_key['I'] = 0;
00618 
00619         if (key['O'] && released_key['O'] == 0)
00620         {
00621             DialogInUse = 2;
00622             lightColor[0] = light[currentLight].Diffuse[0];
00623             lightColor[1] = light[currentLight].Diffuse[1];
00624             lightColor[2] = light[currentLight].Diffuse[2];
00625             ShowCursor(1);
00626             GetLightColor();
00627             key['O'] = 0;
00628             ShowCursor(0);
00629             SetCursorPos((int)(screen.right * 0.5), (int)(screen.bottom * 0.5));
00630             light[currentLight].Diffuse[0] = lightColor[0];
00631             light[currentLight].Diffuse[1] = lightColor[1];
00632             light[currentLight].Diffuse[2] = lightColor[2];
00633             light[currentLight].Update();
00634             DialogInUse = 0;
00635         }
00636 
00637         if (!key['O'])
00638             released_key['O'] = 0;
00639 
00640         if (key['P'] && released_key['P'] == 0)
00641         {
00642             DialogInUse = 3;
00643             lightColor[0] = light[currentLight].Specular[0];
00644             lightColor[1] = light[currentLight].Specular[1];
00645             lightColor[2] = light[currentLight].Specular[2];
00646             ShowCursor(1);
00647             GetLightColor();
00648             key['P'] = 0;
00649             ShowCursor(0);
00650             SetCursorPos((int)(screen.right * 0.5), (int)(screen.bottom * 0.5));
00651             light[currentLight].Specular[0] = lightColor[0];
00652             light[currentLight].Specular[1] = lightColor[1];
00653             light[currentLight].Specular[2] = lightColor[2];
00654             light[currentLight].Update();
00655             DialogInUse = 0;
00656         }
00657 
00658         if (!key['P'])
00659             released_key['P'] = 0;
00660 
00661         if (key['H'] && released_key['H'] == 0)
00662         {
00663             if (visible)
00664                 visible = 0;
00665             else
00666                 visible = 1;
00667             released_key['H'] = 1;
00668         }
00669 
00670         if (!key['H'])
00671             released_key['H'] = 0;
00672 
00673         if (key['S'] && released_key['S'] == 0)
00674         {
00675             if (currentSpline < numSplines - 1)
00676                 currentSpline++;
00677             else
00678                 currentSpline = 0;
00679             released_key['S'] = 1;
00680         }
00681 
00682         if (!key['S'])
00683             released_key['S'] = 0;
00684 
00685         if (key['T'] && released_key['T'] == 0)
00686         {
00687             if (lookAtPath < numSplines - 1)
00688                 lookAtPath++;
00689             else
00690                 lookAtPath = 0;
00691             released_key['T'] = 1;
00692         }
00693 
00694         if (!key['T'])
00695             released_key['T'] = 0;
00696 
00697         if (key['M'] && released_key['M'] == 0)
00698         {
00699             if (cameraMode < 2)
00700                 cameraMode++;
00701             else
00702                 cameraMode = 0;
00703             released_key['M'] = 1;
00704         }
00705 
00706         if (!key['M'])
00707             released_key['M'] = 0;
00708 
00709         if (key[49])
00710         {
00711             step = 1.0;
00712         }
00713 
00714         if (key[50])
00715         {
00716             step = 2.0;
00717         }
00718 
00719         if (key[51])
00720         {
00721             step = 3.0;
00722         }
00723 
00724         if (key[52])
00725         {
00726             step = 4.0;
00727         }
00728 
00729         if (key[53])
00730         {
00731             step = 5.0;
00732         }
00733 
00734         if (key[54])
00735         {
00736             step = 6.0;
00737         }
00738 
00739         if (key[55])
00740         {
00741             step = 7.0;
00742         }
00743 
00744         if (key[56])
00745         {
00746             step = 8.0;
00747         }
00748 
00749         if (key[57])
00750         {
00751             step = 9.0;
00752         }
00753 
00754         if (key[VK_NUMPAD6])
00755         {
00756             light[currentLight].Movement_x += step;
00757         }
00758 
00759         if (key[VK_NUMPAD4])
00760         {
00761             light[currentLight].Movement_x -= step;
00762         }
00763 
00764         if (key[VK_NUMPAD2])
00765         {
00766             light[currentLight].Movement_z += step;
00767         }
00768 
00769         if (key[VK_NUMPAD8])
00770         {
00771             light[currentLight].Movement_z -= step;
00772         }
00773 
00774         if (key[VK_NUMPAD7])
00775         {
00776             light[currentLight].Movement_y += step;
00777         }
00778 
00779         if (key[VK_NUMPAD9])
00780         {
00781             light[currentLight].Movement_y -= step;
00782         }
00783 
00784         if (key[VK_NUMPAD5] && released_key[VK_NUMPAD5] == 0)
00785         {
00786             if (light[currentLight].Positional == FALSE)
00787                 light[currentLight].Positional = TRUE;
00788             else
00789                 light[currentLight].Positional = FALSE;
00790             released_key[VK_NUMPAD5] = 1;
00791         }
00792 
00793         if (!key[VK_NUMPAD5])
00794             released_key[VK_NUMPAD5] = 0;
00795 
00796         if (key[VK_RIGHT])
00797         {
00798             camera[currentCamera].Movement_x += step;
00799         }
00800 
00801         if (key[VK_LEFT])
00802         {
00803             camera[currentCamera].Movement_x -= step;
00804         }
00805 
00806         if (key[VK_DOWN])
00807         {
00808             camera[currentCamera].Movement_z += step;
00809         }
00810 
00811         if (key[VK_UP])
00812         {
00813             camera[currentCamera].Movement_z -= step;
00814         }
00815 
00816         if (key[VK_PRIOR])
00817         {
00818             camera[currentCamera].Movement_y += step;
00819         }
00820 
00821         if (key[VK_NEXT])
00822         {
00823             camera[currentCamera].Movement_y -= step;
00824         }
00825 
00826         if (key[VK_SPACE])
00827         {
00828             camera[currentCamera].Reset();
00829         }
00830 
00831         if (key[VK_ESCAPE] || key['Q'])
00832             SendMessage(hWnd,WM_CLOSE,0,0);
00833     }
00834 }

Generated on Fri Dec 23 05:22:05 2005 for Splines by doxygen1.2.15