Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

general.cpp

Go to the documentation of this file.
00001 #include <windows.h>
00002 #include "shared.h"
00003 #include "polygon.h"
00004 #include "camera.h"
00005 #include "texture.h"
00006 #include "light.h"
00007 #include "locmath.h"
00008 #include "bspline.h"
00009 #include "glFont.h"
00010 #include "bsp.h"
00011 #include "tll.h"
00012 #include "plane.h"
00013 #include "mmgr.h"
00014 
00015 extern int numPolygons;
00016 extern int numCameras;
00017 extern int cameraMode;
00018 extern int currentCamera;
00019 extern int numLights;
00020 extern int currentLight;
00021 extern int fps;
00022 extern float multiplier;
00023 extern GLFONT myFont;
00024 extern char HaloTypeName[MAX_PATH];
00025 extern char FireTypeName[MAX_PATH];
00026 extern int numSplines;
00027 extern int lookAtPath;
00028 extern int currentSpline;
00029 extern SPLINE* spline;
00030 extern char SplineFileName[MAX_PATH];
00031 extern PLANE frustum[6];
00032 extern int showportals;
00033 extern int currentleaf;
00034 extern int numcurrentportals;
00035 
00036 VECTOR GetEdgeIntersection(VECTOR point0, VECTOR point1, POLYGON planePolygon)
00037 {
00038     VECTOR edge1, edge2, planeNormal, pointOnPlane, intersection, temp;
00039     float numerator, denominator, t;
00040 
00041     // get a point on the plane
00042     pointOnPlane.x = planePolygon.Vertex[0].x;
00043     pointOnPlane.y = planePolygon.Vertex[0].y;
00044     pointOnPlane.z = planePolygon.Vertex[0].z;
00045 
00046     // get the splitting planes normal
00047     edge1.x = planePolygon.Vertex[1].x - planePolygon.Vertex[0].x;
00048     edge1.y = planePolygon.Vertex[1].y - planePolygon.Vertex[0].y;
00049     edge1.z = planePolygon.Vertex[1].z - planePolygon.Vertex[0].z;
00050     edge2.x = planePolygon.Vertex[2].x - planePolygon.Vertex[0].x;
00051     edge2.y = planePolygon.Vertex[2].y - planePolygon.Vertex[0].y;
00052     edge2.z = planePolygon.Vertex[2].z - planePolygon.Vertex[0].z;
00053     planeNormal = CrossVector(edge1, edge2);
00054 
00055 // find edge intersection:
00056 // intersection = p0 + (p1 - p0) * t
00057 // where t = (planeNormal . (pointOnPlane - p0)) / (planeNormal . (p1 - p0))
00058 
00059     //planeNormal . (pointOnPlane - point0)
00060     temp.x = pointOnPlane.x - point0.x;
00061     temp.y = pointOnPlane.y - point0.y;
00062     temp.z = pointOnPlane.z - point0.z;
00063     numerator = DotProduct(planeNormal, temp);
00064 
00065     //planeNormal . (point1 - point0)
00066     temp.x = point1.x - point0.x;
00067     temp.y = point1.y - point0.y;
00068     temp.z = point1.z - point0.z;
00069     denominator = DotProduct(planeNormal, temp);
00070 
00071     if (denominator)
00072         t = numerator / denominator;
00073     else
00074         t = 0.0;
00075 
00076     intersection.x = point0.x + temp.x * t;
00077     intersection.y = point0.y + temp.y * t;
00078     intersection.z = point0.z + temp.z * t;
00079 
00080     return intersection;
00081 }
00082 
00083 int SphereInFrustum(VECTOR point, float radius )
00084 {
00085    int p;
00086    int c = 0;
00087    float d;
00088 
00089    for( p = 0; p < 6; p++ )
00090    {
00091       d = frustum[p].nx * point.x + frustum[p].ny * point.y + frustum[p].nz * point.z + frustum[p].Distance;
00092       if( d <= -radius )
00093          return 0;
00094       if( d > radius )
00095          c++;
00096    }
00097    return (c == 6) ? 2 : 1;
00098 }
00099 
00100 bool PointInFrustum(VECTOR point)
00101 {
00102    int p;
00103 
00104    for( p = 0; p < 6; p++ )
00105       if( frustum[p].nx * point.x + frustum[p].ny * point.y + frustum[p].nz * point.z + frustum[p].Distance <= 0 )
00106          return false;
00107    return true;
00108 }
00109 
00110 void ExtractFrustum()
00111 {
00112     float proj[16];
00113     float modl[16];
00114     float clip[16];
00115     float t;
00116     /* Get the current PROJECTION matrix from OpenGL */
00117     glGetFloatv( GL_PROJECTION_MATRIX, proj );
00118     /* Get the current MODELVIEW matrix from OpenGL */
00119     glGetFloatv( GL_MODELVIEW_MATRIX, modl );
00120     /* Combine the two matrices (multiply projection by modelview) */
00121     clip[ 0] = modl[ 0] * proj[ 0] + modl[ 1] * proj[ 4] + modl[ 2] * proj[ 8] + modl[ 3] * proj[12];
00122     clip[ 1] = modl[ 0] * proj[ 1] + modl[ 1] * proj[ 5] + modl[ 2] * proj[ 9] + modl[ 3] * proj[13];
00123     clip[ 2] = modl[ 0] * proj[ 2] + modl[ 1] * proj[ 6] + modl[ 2] * proj[10] + modl[ 3] * proj[14];
00124     clip[ 3] = modl[ 0] * proj[ 3] + modl[ 1] * proj[ 7] + modl[ 2] * proj[11] + modl[ 3] * proj[15];
00125     clip[ 4] = modl[ 4] * proj[ 0] + modl[ 5] * proj[ 4] + modl[ 6] * proj[ 8] + modl[ 7] * proj[12];
00126     clip[ 5] = modl[ 4] * proj[ 1] + modl[ 5] * proj[ 5] + modl[ 6] * proj[ 9] + modl[ 7] * proj[13];
00127     clip[ 6] = modl[ 4] * proj[ 2] + modl[ 5] * proj[ 6] + modl[ 6] * proj[10] + modl[ 7] * proj[14];
00128     clip[ 7] = modl[ 4] * proj[ 3] + modl[ 5] * proj[ 7] + modl[ 6] * proj[11] + modl[ 7] * proj[15];
00129     clip[ 8] = modl[ 8] * proj[ 0] + modl[ 9] * proj[ 4] + modl[10] * proj[ 8] + modl[11] * proj[12];
00130     clip[ 9] = modl[ 8] * proj[ 1] + modl[ 9] * proj[ 5] + modl[10] * proj[ 9] + modl[11] * proj[13];
00131     clip[10] = modl[ 8] * proj[ 2] + modl[ 9] * proj[ 6] + modl[10] * proj[10] + modl[11] * proj[14];
00132     clip[11] = modl[ 8] * proj[ 3] + modl[ 9] * proj[ 7] + modl[10] * proj[11] + modl[11] * proj[15];
00133     clip[12] = modl[12] * proj[ 0] + modl[13] * proj[ 4] + modl[14] * proj[ 8] + modl[15] * proj[12];
00134     clip[13] = modl[12] * proj[ 1] + modl[13] * proj[ 5] + modl[14] * proj[ 9] + modl[15] * proj[13];
00135     clip[14] = modl[12] * proj[ 2] + modl[13] * proj[ 6] + modl[14] * proj[10] + modl[15] * proj[14];
00136     clip[15] = modl[12] * proj[ 3] + modl[13] * proj[ 7] + modl[14] * proj[11] + modl[15] * proj[15];
00137 
00138     /* Extract the numbers for the RIGHT plane */
00139     frustum[0].nx = clip[ 3] - clip[ 0];
00140     frustum[0].ny = clip[ 7] - clip[ 4];
00141     frustum[0].nz = clip[11] - clip[ 8];
00142     frustum[0].Distance = clip[15] - clip[12];
00143     /* Normalize the result */
00144     t = sqrt( frustum[0].nx * frustum[0].nx + frustum[0].ny * frustum[0].ny + frustum[0].nz * frustum[0].nz);
00145     frustum[0].nx /= t;
00146     frustum[0].ny /= t;
00147     frustum[0].nz /= t;
00148     frustum[0].Distance /= t;
00149     /* Extract the numbers for the LEFT plane */
00150     frustum[1].nx = clip[ 3] + clip[ 0];
00151     frustum[1].ny = clip[ 7] + clip[ 4];
00152     frustum[1].nz = clip[11] + clip[ 8];
00153     frustum[1].Distance = clip[15] + clip[12];
00154     /* Normalize the result */
00155     t = sqrt( frustum[1].nx * frustum[1].nx + frustum[1].ny * frustum[1].ny + frustum[1].nz * frustum[1].nz);
00156     frustum[1].nx /= t;
00157     frustum[1].ny /= t;
00158     frustum[1].nz /= t;
00159     frustum[1].Distance /= t;
00160     /* Extract the BOTTOM plane */
00161     frustum[2].nx = clip[ 3] + clip[ 1];
00162     frustum[2].ny = clip[ 7] + clip[ 5];
00163     frustum[2].nz = clip[11] + clip[ 9];
00164     frustum[2].Distance = clip[15] + clip[13];
00165     /* Normalize the result */
00166     t = sqrt( frustum[2].nx * frustum[2].nx + frustum[2].ny * frustum[2].ny + frustum[2].nz * frustum[2].nz);
00167     frustum[2].nx /= t;
00168     frustum[2].ny /= t;
00169     frustum[2].nz /= t;
00170     frustum[2].Distance /= t;
00171     /* Extract the TOP plane */
00172     frustum[3].nx = clip[ 3] - clip[ 1];
00173     frustum[3].ny = clip[ 7] - clip[ 5];
00174     frustum[3].nz = clip[11] - clip[ 9];
00175     frustum[3].Distance = clip[15] - clip[13];
00176     /* Normalize the result */
00177     t = sqrt( frustum[3].nx * frustum[3].nx + frustum[3].ny * frustum[3].ny + frustum[3].nz * frustum[3].nz);
00178     frustum[3].nx /= t;
00179     frustum[3].ny /= t;
00180     frustum[3].nz /= t;
00181     frustum[3].Distance /= t;
00182     /* Extract the FAR plane */
00183     frustum[4].nx = clip[ 3] - clip[ 2];
00184     frustum[4].ny = clip[ 7] - clip[ 6];
00185     frustum[4].nz = clip[11] - clip[10];
00186     frustum[4].Distance = clip[15] - clip[14];
00187     /* Normalize the result */
00188     t = sqrt( frustum[4].nx * frustum[4].nx + frustum[4].ny * frustum[4].ny + frustum[4].nz * frustum[4].nz);
00189     frustum[4].nx /= t;
00190     frustum[4].ny /= t;
00191     frustum[4].nz /= t;
00192     frustum[4].Distance /= t;
00193     /* Extract the NEAR plane */
00194     frustum[5].nx = clip[ 3] + clip[ 2];
00195     frustum[5].ny = clip[ 7] + clip[ 6];
00196     frustum[5].nz = clip[11] + clip[10];
00197     frustum[5].Distance = clip[15] + clip[14];
00198     /* Normalize the result */
00199     t = sqrt( frustum[5].nx * frustum[5].nx + frustum[5].ny * frustum[5].ny + frustum[5].nz * frustum[5].nz);
00200     frustum[5].nx /= t;
00201     frustum[5].ny /= t;
00202     frustum[5].nz /= t;
00203     frustum[5].Distance /= t;
00204 }
00205 
00206 void AddSpline(int Number, LinkedList<SPLINE>& SplineList)
00207 {
00208     SPLINE* spline2 = new SPLINE;
00209     spline2->Active = 1;
00210     spline2->Repeat = 1;
00211     spline2->Degree = 3;
00212     spline2->NumControl = 7;
00213     spline2->NumPoints = 100;
00214     spline2->Control = new VECTOR[100];
00215     spline2->Output = new VECTOR[1000];
00216     spline2->StartTime = 5000;
00217     spline2->EndTime = 25000;
00218     spline2->CopyOfStartTime = spline2->StartTime;
00219     spline2->CopyOfEndTime = spline2->EndTime;
00220 
00221     spline2->Red = ((float)(rand()%226) + 30.0) / 255;
00222     spline2->Green = ((float)(rand()%226) + 30.0) / 255;
00223     spline2->Blue = ((float)(rand()%266) + 30.0) / 255;
00224 
00225     for (int loop = 0; loop < 100; loop++)
00226     {
00227         spline2->Control[loop].x = rand()%60 - 29;  spline2->Control[loop].y = rand()%60 - 29;  spline2->Control[loop].z = rand()%60 - 29;
00228     }
00229 
00230     spline2->linkPosition = Number;   //Set the link position of the spline
00231     SplineList.Insert(spline2);       //Insert spline in linked list
00232 }
00233 
00234 void DeleteSpline(int Number, LinkedList<SPLINE>& SplineList)
00235 {
00236     SPLINE* temp = SplineList.Get(Number);
00237     delete[] temp->Control;
00238     delete[] temp->Output;
00239     SplineList.Delete(Number);
00240     delete temp;
00241 }
00242 
00243 int LoadSplines(char* SplineFileName, LinkedList<SPLINE>& SplineList)
00244 {
00245     const int stringLength = 33;
00246     char tempString[stringLength];
00247     FILE* SplineFile;
00248     SplineFile = fopen(SplineFileName, "rt");
00249     if (!SplineFile)
00250     {
00251         MessageBox(NULL, "Spline File didn't open", "Error", MB_OK | MB_ICONERROR);
00252         return 0;
00253     }
00254     fseek(SplineFile, 0, SEEK_SET);
00255     int InitialNumSplines = numSplines;
00256     if (!fgets(tempString, stringLength, SplineFile))
00257     {
00258         MessageBox(NULL, "Error reading from the spline data file", "Error", MB_OK | MB_ICONERROR);
00259         numSplines = InitialNumSplines;
00260         return FALSE;
00261     }
00262     numSplines = atoi(tempString);
00263     if (InitialNumSplines > numSplines)
00264     {
00265         for (int loop = InitialNumSplines - 1; loop >= numSplines; loop--)
00266         {
00267             DeleteSpline(loop, SplineList);
00268         }
00269     }
00270     if (numSplines > InitialNumSplines)
00271     {
00272         for (int loop = InitialNumSplines; loop < numSplines; loop++)
00273         {
00274             AddSpline(loop, SplineList);
00275         }
00276     }
00277     for (int loop = 0; loop < numSplines; loop++)
00278     {
00279         spline = SplineList.Get(loop);
00280         // Active flag
00281         fgets(tempString, stringLength, SplineFile);
00282         spline->Active = atoi(tempString);
00283         // Repeat flag
00284         fgets(tempString, stringLength, SplineFile);
00285         spline->Repeat = atoi(tempString);
00286         // Degree
00287         fgets(tempString, stringLength, SplineFile);
00288         spline->Degree = atoi(tempString);
00289         // NumControl
00290         fgets(tempString, stringLength, SplineFile);
00291         spline->NumControl = atoi(tempString);
00292         // NumPoints
00293         fgets(tempString, stringLength, SplineFile);
00294         spline->NumPoints = atoi(tempString);
00295         // StartTime
00296         fgets(tempString, stringLength, SplineFile);
00297         spline->StartTime = atof(tempString);
00298         // EndTime
00299         fgets(tempString, stringLength, SplineFile);
00300         spline->EndTime = atof(tempString);
00301         // Red
00302         fgets(tempString, stringLength, SplineFile);
00303         spline->Red = atof(tempString);
00304         // Green
00305         fgets(tempString, stringLength, SplineFile);
00306         spline->Green = atof(tempString);
00307         // Blue
00308         fgets(tempString, stringLength, SplineFile);
00309         spline->Blue = atof(tempString);
00310 
00311         for (int loop2 = 0; loop2 <= spline->NumControl; loop2++)
00312         {
00313             fgets(tempString, stringLength, SplineFile);
00314             spline->Control[loop2].x = atof(tempString);
00315             fgets(tempString, stringLength, SplineFile);
00316             spline->Control[loop2].y = atof(tempString);
00317             fgets(tempString, stringLength, SplineFile);
00318             spline->Control[loop2].z = atof(tempString);
00319         }
00320         spline->CopyOfStartTime = spline->StartTime;
00321         spline->CopyOfEndTime = spline->EndTime;
00322     }
00323 
00324     currentSpline = numSplines - 1;
00325     if (lookAtPath >= numSplines)
00326         lookAtPath = numSplines - 1;
00327     if (fclose(SplineFile))
00328         MessageBox(NULL, "File didn't close", "Error", MB_OK | MB_ICONERROR);
00329     return 1;
00330 }
00331 
00332 void SetSplines(LinkedList<SPLINE>& SplineList)
00333 {
00334     srand((unsigned)time(NULL));
00335     //Create a new spline
00336     for (int loop = 0; loop < numSplines; loop++)
00337     {
00338         AddSpline(loop, SplineList);
00339     }
00340     //Load splines from data file
00341     LoadSplines(SplineFileName, SplineList);
00342 }
00343 
00344 void SetGLLighting(LIGHT* light)         // Loop through and reset all the lights
00345 {
00346     int temp;
00347     for (temp = 0; temp <= numLights; temp++)
00348     {
00349         light[temp].LightNumber = temp;
00350         light[temp].Reset();
00351     }
00352     glEnable(GL_LIGHTING);
00353 }
00354 
00355 void SetGLCamera(CAMERA* camera)          // Loop through and reset all the cameras
00356 {
00357     int temp;
00358     for(temp = 0; temp <= numCameras; temp++)
00359         camera[temp].Reset();
00360 }
00361 
00362 void SetGLVertices(VERTEX* vertex)
00363 {
00364     vertex[0].x = -80;
00365     vertex[0].y = -10;
00366     vertex[0].z = -60;
00367 
00368     vertex[1].x = 20;
00369     vertex[1].y = -10;
00370     vertex[1].z = -60;
00371 
00372     vertex[2].x = 20;
00373     vertex[2].y = -10;
00374     vertex[2].z = -40;
00375 
00376     vertex[3].x = 170;
00377     vertex[3].y = -10;
00378     vertex[3].z = -40;
00379 
00380     vertex[4].x = 170;
00381     vertex[4].y = -10;
00382     vertex[4].z = 40;
00383 
00384     vertex[5].x = 120;
00385     vertex[5].y = -10;
00386     vertex[5].z = 40;
00387 
00388     vertex[6].x = 120;
00389     vertex[6].y = -10;
00390     vertex[6].z = 80;
00391 
00392     vertex[7].x = 160;
00393     vertex[7].y = -10;
00394     vertex[7].z = 80;
00395 
00396     vertex[8].x = 160;
00397     vertex[8].y = -10;
00398     vertex[8].z = 160;
00399 
00400     vertex[9].x = 60;
00401     vertex[9].y = -10;
00402     vertex[9].z = 160;
00403 
00404     vertex[10].x = 60;
00405     vertex[10].y = -10;
00406     vertex[10].z = 80;
00407 
00408     vertex[11].x = 100;
00409     vertex[11].y = -10;
00410     vertex[11].z = 80;
00411 
00412     vertex[12].x = 100;
00413     vertex[12].y = -10;
00414     vertex[12].z = 40;
00415 
00416     vertex[13].x = 20;
00417     vertex[13].y = -10;
00418     vertex[13].z = 40;
00419 
00420     vertex[14].x = 20;
00421     vertex[14].y = -10;
00422     vertex[14].z = 60;
00423 
00424     vertex[15].x = -80;
00425     vertex[15].y = -10;
00426     vertex[15].z = 60;
00427 
00428     vertex[16].x = -80;
00429     vertex[16].y = 10;
00430     vertex[16].z = -60;
00431 
00432     vertex[17].x = 20;
00433     vertex[17].y = 10;
00434     vertex[17].z = -60;
00435 
00436     vertex[18].x = 20;
00437     vertex[18].y = 10;
00438     vertex[18].z = -40;
00439 
00440     vertex[19].x = 170;
00441     vertex[19].y = 10;
00442     vertex[19].z = -40;
00443 
00444     vertex[20].x = 170;
00445     vertex[20].y = 10;
00446     vertex[20].z = 40;
00447 
00448     vertex[21].x = 120;
00449     vertex[21].y = 10;
00450     vertex[21].z = 40;
00451 
00452     vertex[22].x = 120;
00453     vertex[22].y = 10;
00454     vertex[22].z = 80;
00455 
00456     vertex[23].x = 160;
00457     vertex[23].y = 10;
00458     vertex[23].z = 80;
00459 
00460     vertex[24].x = 160;
00461     vertex[24].y = 10;
00462     vertex[24].z = 160;
00463 
00464     vertex[25].x = 60;
00465     vertex[25].y = 10;
00466     vertex[25].z = 160;
00467 
00468     vertex[26].x = 60;
00469     vertex[26].y = 10;
00470     vertex[26].z = 80;
00471 
00472     vertex[27].x = 100;
00473     vertex[27].y = 10;
00474     vertex[27].z = 80;
00475 
00476     vertex[28].x = 100;
00477     vertex[28].y = 10;
00478     vertex[28].z = 40;
00479 
00480     vertex[29].x = 20;
00481     vertex[29].y = 10;
00482     vertex[29].z = 40;
00483 
00484     vertex[30].x = 20;
00485     vertex[30].y = 10;
00486     vertex[30].z = 60;
00487 
00488     vertex[31].x = -80;
00489     vertex[31].y = 10;
00490     vertex[31].z = 60;
00491 
00492     vertex[32].x = -80;
00493     vertex[32].y = 10;
00494     vertex[32].z = 40;
00495 
00496     vertex[33].x = -80;
00497     vertex[33].y = 40;
00498     vertex[33].z = 0;
00499 
00500     vertex[34].x = -80;
00501     vertex[34].y = 10;
00502     vertex[34].z = -40;
00503 
00504     vertex[35].x = 20;
00505     vertex[35].y = 40;
00506     vertex[35].z = 0;
00507 
00508     vertex[36].x = 170;
00509     vertex[36].y = 40;
00510     vertex[36].z = 0;
00511 }
00512 
00513 // Initialize the world data
00514 void SetGLWorld(POLYGON* polygon, TEXTURE* texture, VERTEX* vertex)
00515 {
00516     SetGLVertices(vertex);
00517 
00518     polygon[0].Scale[0] = 6.0;
00519     polygon[0].Scale[1] = 1.0;
00520     polygon[0].Shift[0] = 0.0;
00521     polygon[0].Shift[1] = 0.0;
00522     polygon[0].Rotate = 0.0;
00523     polygon[0].Vertex[0] = vertex[0];
00524     polygon[0].Vertex[1] = vertex[17];
00525     polygon[0].Vertex[2] = vertex[16];
00526     polygon[0].Texture = texture[2].TexID;
00527     polygon[0].Vertex[0].u = 0.0;
00528     polygon[0].Vertex[0].v = 0.0;
00529     polygon[0].Vertex[1].u = 1.0;
00530     polygon[0].Vertex[1].v = 1.0;
00531     polygon[0].Vertex[2].u = 0.0;
00532     polygon[0].Vertex[2].v = 1.0;
00533 
00534     polygon[1].Scale[0] = 6.0;
00535     polygon[1].Scale[1] = 1.0;
00536     polygon[1].Shift[0] = 0.0;
00537     polygon[1].Shift[1] = 0.0;
00538     polygon[1].Rotate = 0.0;
00539     polygon[1].Vertex[0] = vertex[0];
00540     polygon[1].Vertex[1] = vertex[1];
00541     polygon[1].Vertex[2] = vertex[17];
00542     polygon[1].Texture = texture[2].TexID;
00543     polygon[1].Vertex[0].u = 0.0;
00544     polygon[1].Vertex[0].v = 0.0;
00545     polygon[1].Vertex[1].u = 1.0;
00546     polygon[1].Vertex[1].v = 0.0;
00547     polygon[1].Vertex[2].u = 1.0;
00548     polygon[1].Vertex[2].v = 1.0;
00549 
00550     polygon[2].Scale[0] = 1.0;
00551     polygon[2].Scale[1] = 1.0;
00552     polygon[2].Shift[0] = 0.0;
00553     polygon[2].Shift[1] = 0.0;
00554     polygon[2].Rotate = 0.0;
00555     polygon[2].Vertex[0] = vertex[1];
00556     polygon[2].Vertex[1] = vertex[18];
00557     polygon[2].Vertex[2] = vertex[17];
00558     polygon[2].Texture = texture[2].TexID;
00559     polygon[2].Vertex[0].u = 0.0;
00560     polygon[2].Vertex[0].v = 0.0;
00561     polygon[2].Vertex[1].u = 1.0;
00562     polygon[2].Vertex[1].v = 1.0;
00563     polygon[2].Vertex[2].u = 0.0;
00564     polygon[2].Vertex[2].v = 1.0;
00565 
00566     polygon[3].Scale[0] = 1.0;
00567     polygon[3].Scale[1] = 1.0;
00568     polygon[3].Shift[0] = 0.0;
00569     polygon[3].Shift[1] = 0.0;
00570     polygon[3].Rotate = 0.0;
00571     polygon[3].Vertex[0] = vertex[1];
00572     polygon[3].Vertex[1] = vertex[2];
00573     polygon[3].Vertex[2] = vertex[18];
00574     polygon[3].Texture = texture[2].TexID;
00575     polygon[3].Vertex[0].u = 0.0;
00576     polygon[3].Vertex[0].v = 0.0;
00577     polygon[3].Vertex[1].u = 1.0;
00578     polygon[3].Vertex[1].v = 0.0;
00579     polygon[3].Vertex[2].u = 1.0;
00580     polygon[3].Vertex[2].v = 1.0;
00581 
00582     polygon[4].Scale[0] = 5.0;
00583     polygon[4].Scale[1] = 1.0;
00584     polygon[4].Shift[0] = 0.0;
00585     polygon[4].Shift[1] = 0.0;
00586     polygon[4].Rotate = 0.0;
00587     polygon[4].Vertex[0] = vertex[2];
00588     polygon[4].Vertex[1] = vertex[19];
00589     polygon[4].Vertex[2] = vertex[18];
00590     polygon[4].Texture = texture[2].TexID;
00591     polygon[4].Vertex[0].u = 0.0;
00592     polygon[4].Vertex[0].v = 0.0;
00593     polygon[4].Vertex[1].u = 1.0;
00594     polygon[4].Vertex[1].v = 1.0;
00595     polygon[4].Vertex[2].u = 0.0;
00596     polygon[4].Vertex[2].v = 1.0;
00597 
00598     polygon[5].Scale[0] = 5.0;
00599     polygon[5].Scale[1] = 1.0;
00600     polygon[5].Shift[0] = 0.0;
00601     polygon[5].Shift[1] = 0.0;
00602     polygon[5].Rotate = 0.0;
00603     polygon[5].Vertex[0] = vertex[2];
00604     polygon[5].Vertex[1] = vertex[3];
00605     polygon[5].Vertex[2] = vertex[19];
00606     polygon[5].Texture = texture[2].TexID;
00607     polygon[5].Vertex[0].u = 0.0;
00608     polygon[5].Vertex[0].v = 0.0;
00609     polygon[5].Vertex[1].u = 1.0;
00610     polygon[5].Vertex[1].v = 0.0;
00611     polygon[5].Vertex[2].u = 1.0;
00612     polygon[5].Vertex[2].v = 1.0;
00613 
00614     polygon[6].Scale[0] = 4.0;
00615     polygon[6].Scale[1] = 1.0;
00616     polygon[6].Shift[0] = 0.0;
00617     polygon[6].Shift[1] = 0.0;
00618     polygon[6].Rotate = 0.0;
00619     polygon[6].Vertex[0] = vertex[3];
00620     polygon[6].Vertex[1] = vertex[20];
00621     polygon[6].Vertex[2] = vertex[19];
00622     polygon[6].Texture = texture[2].TexID;
00623     polygon[6].Vertex[0].u = 0.0;
00624     polygon[6].Vertex[0].v = 0.0;
00625     polygon[6].Vertex[1].u = 1.0;
00626     polygon[6].Vertex[1].v = 1.0;
00627     polygon[6].Vertex[2].u = 0.0;
00628     polygon[6].Vertex[2].v = 1.0;
00629 
00630     polygon[7].Scale[0] = 4.0;
00631     polygon[7].Scale[1] = 1.0;
00632     polygon[7].Shift[0] = 0.0;
00633     polygon[7].Shift[1] = 0.0;
00634     polygon[7].Rotate = 0.0;
00635     polygon[7].Vertex[0] = vertex[3];
00636     polygon[7].Vertex[1] = vertex[4];
00637     polygon[7].Vertex[2] = vertex[20];
00638     polygon[7].Texture = texture[2].TexID;
00639     polygon[7].Vertex[0].u = 0.0;
00640     polygon[7].Vertex[0].v = 0.0;
00641     polygon[7].Vertex[1].u = 1.0;
00642     polygon[7].Vertex[1].v = 0.0;
00643     polygon[7].Vertex[2].u = 1.0;
00644     polygon[7].Vertex[2].v = 1.0;
00645 
00646     polygon[8].Scale[0] = 2.0;
00647     polygon[8].Scale[1] = 1.0;
00648     polygon[8].Shift[0] = 0.0;
00649     polygon[8].Shift[1] = 0.0;
00650     polygon[8].Rotate = 0.0;
00651     polygon[8].Vertex[0] = vertex[4];
00652     polygon[8].Vertex[1] = vertex[21];
00653     polygon[8].Vertex[2] = vertex[20];
00654     polygon[8].Texture = texture[2].TexID;
00655     polygon[8].Vertex[0].u = 0.0;
00656     polygon[8].Vertex[0].v = 0.0;
00657     polygon[8].Vertex[1].u = 1.0;
00658     polygon[8].Vertex[1].v = 1.0;
00659     polygon[8].Vertex[2].u = 0.0;
00660     polygon[8].Vertex[2].v = 1.0;
00661 
00662     polygon[9].Scale[0] = 2.0;
00663     polygon[9].Scale[1] = 1.0;
00664     polygon[9].Shift[0] = 0.0;
00665     polygon[9].Shift[1] = 0.0;
00666     polygon[9].Rotate = 0.0;
00667     polygon[9].Vertex[0] = vertex[4];
00668     polygon[9].Vertex[1] = vertex[5];
00669     polygon[9].Vertex[2] = vertex[21];
00670     polygon[9].Texture = texture[2].TexID;
00671     polygon[9].Vertex[0].u = 0.0;
00672     polygon[9].Vertex[0].v = 0.0;
00673     polygon[9].Vertex[1].u = 1.0;
00674     polygon[9].Vertex[1].v = 0.0;
00675     polygon[9].Vertex[2].u = 1.0;
00676     polygon[9].Vertex[2].v = 1.0;
00677 
00678     polygon[10].Scale[0] = 2.0;
00679     polygon[10].Scale[1] = 1.0;
00680     polygon[10].Shift[0] = 0.0;
00681     polygon[10].Shift[1] = 0.0;
00682     polygon[10].Rotate = 0.0;
00683     polygon[10].Vertex[0] = vertex[5];
00684     polygon[10].Vertex[1] = vertex[22];
00685     polygon[10].Vertex[2] = vertex[21];
00686     polygon[10].Texture = texture[2].TexID;
00687     polygon[10].Vertex[0].u = 0.0;
00688     polygon[10].Vertex[0].v = 0.0;
00689     polygon[10].Vertex[1].u = 1.0;
00690     polygon[10].Vertex[1].v = 1.0;
00691     polygon[10].Vertex[2].u = 0.0;
00692     polygon[10].Vertex[2].v = 1.0;
00693 
00694     polygon[11].Scale[0] = 2.0;
00695     polygon[11].Scale[1] = 1.0;
00696     polygon[11].Shift[0] = 0.0;
00697     polygon[11].Shift[1] = 0.0;
00698     polygon[11].Rotate = 0.0;
00699     polygon[11].Vertex[0] = vertex[5];
00700     polygon[11].Vertex[1] = vertex[6];
00701     polygon[11].Vertex[2] = vertex[22];
00702     polygon[11].Texture = texture[2].TexID;
00703     polygon[11].Vertex[0].u = 0.0;
00704     polygon[11].Vertex[0].v = 0.0;
00705     polygon[11].Vertex[1].u = 1.0;
00706     polygon[11].Vertex[1].v = 0.0;
00707     polygon[11].Vertex[2].u = 1.0;
00708     polygon[11].Vertex[2].v = 1.0;
00709 
00710     polygon[12].Scale[0] = 2.0;
00711     polygon[12].Scale[1] = 1.0;
00712     polygon[12].Shift[0] = 0.0;
00713     polygon[12].Shift[1] = 0.0;
00714     polygon[12].Rotate = 0.0;
00715     polygon[12].Vertex[0] = vertex[6];
00716     polygon[12].Vertex[1] = vertex[23];
00717     polygon[12].Vertex[2] = vertex[22];
00718     polygon[12].Texture = texture[2].TexID;
00719     polygon[12].Vertex[0].u = 0.0;
00720     polygon[12].Vertex[0].v = 0.0;
00721     polygon[12].Vertex[1].u = 1.0;
00722     polygon[12].Vertex[1].v = 1.0;
00723     polygon[12].Vertex[2].u = 0.0;
00724     polygon[12].Vertex[2].v = 1.0;
00725 
00726     polygon[13].Scale[0] = 2.0;
00727     polygon[13].Scale[1] = 1.0;
00728     polygon[13].Shift[0] = 0.0;
00729     polygon[13].Shift[1] = 0.0;
00730     polygon[13].Rotate = 0.0;
00731     polygon[13].Vertex[0] = vertex[6];
00732     polygon[13].Vertex[1] = vertex[7];
00733     polygon[13].Vertex[2] = vertex[23];
00734     polygon[13].Texture = texture[2].TexID;
00735     polygon[13].Vertex[0].u = 0.0;
00736     polygon[13].Vertex[0].v = 0.0;
00737     polygon[13].Vertex[1].u = 1.0;
00738     polygon[13].Vertex[1].v = 0.0;
00739     polygon[13].Vertex[2].u = 1.0;
00740     polygon[13].Vertex[2].v = 1.0;
00741 
00742     polygon[14].Scale[0] = 2.0;
00743     polygon[14].Scale[1] = 1.0;
00744     polygon[14].Shift[0] = 0.0;
00745     polygon[14].Shift[1] = 0.0;
00746     polygon[14].Rotate = 0.0;
00747     polygon[14].Vertex[0] = vertex[7];
00748     polygon[14].Vertex[1] = vertex[24];
00749     polygon[14].Vertex[2] = vertex[23];
00750     polygon[14].Texture = texture[2].TexID;
00751     polygon[14].Vertex[0].u = 0.0;
00752     polygon[14].Vertex[0].v = 0.0;
00753     polygon[14].Vertex[1].u = 1.0;
00754     polygon[14].Vertex[1].v = 1.0;
00755     polygon[14].Vertex[2].u = 0.0;
00756     polygon[14].Vertex[2].v = 1.0;
00757 
00758     polygon[15].Scale[0] = 2.0;
00759     polygon[15].Scale[1] = 1.0;
00760     polygon[15].Shift[0] = 0.0;
00761     polygon[15].Shift[1] = 0.0;
00762     polygon[15].Rotate = 0.0;
00763     polygon[15].Vertex[0] = vertex[7];
00764     polygon[15].Vertex[1] = vertex[8];
00765     polygon[15].Vertex[2] = vertex[24];
00766     polygon[15].Texture = texture[2].TexID;
00767     polygon[15].Vertex[0].u = 0.0;
00768     polygon[15].Vertex[0].v = 0.0;
00769     polygon[15].Vertex[1].u = 1.0;
00770     polygon[15].Vertex[1].v = 0.0;
00771     polygon[15].Vertex[2].u = 1.0;
00772     polygon[15].Vertex[2].v = 1.0;
00773 
00774     polygon[16].Scale[0] = 2.0;
00775     polygon[16].Scale[1] = 1.0;
00776     polygon[16].Shift[0] = 0.0;
00777     polygon[16].Shift[1] = 0.0;
00778     polygon[16].Rotate = 0.0;
00779     polygon[16].Vertex[0] = vertex[8];
00780     polygon[16].Vertex[1] = vertex[25];
00781     polygon[16].Vertex[2] = vertex[24];
00782     polygon[16].Texture = texture[2].TexID;
00783     polygon[16].Vertex[0].u = 0.0;
00784     polygon[16].Vertex[0].v = 0.0;
00785     polygon[16].Vertex[1].u = 1.0;
00786     polygon[16].Vertex[1].v = 1.0;
00787     polygon[16].Vertex[2].u = 0.0;
00788     polygon[16].Vertex[2].v = 1.0;
00789 
00790     polygon[17].Scale[0] = 2.0;
00791     polygon[17].Scale[1] = 1.0;
00792     polygon[17].Shift[0] = 0.0;
00793     polygon[17].Shift[1] = 0.0;
00794     polygon[17].Rotate = 0.0;
00795     polygon[17].Vertex[0] = vertex[8];
00796     polygon[17].Vertex[1] = vertex[9];
00797     polygon[17].Vertex[2] = vertex[25];
00798     polygon[17].Texture = texture[2].TexID;
00799     polygon[17].Vertex[0].u = 0.0;
00800     polygon[17].Vertex[0].v = 0.0;
00801     polygon[17].Vertex[1].u = 1.0;
00802     polygon[17].Vertex[1].v = 0.0;
00803     polygon[17].Vertex[2].u = 1.0;
00804     polygon[17].Vertex[2].v = 1.0;
00805 
00806     polygon[18].Scale[0] = 2.0;
00807     polygon[18].Scale[1] = 1.0;
00808     polygon[18].Shift[0] = 0.0;
00809     polygon[18].Shift[1] = 20.0;
00810     polygon[18].Rotate = 0.0;
00811     polygon[18].Vertex[0] = vertex[9];
00812     polygon[18].Vertex[1] = vertex[26];
00813     polygon[18].Vertex[2] = vertex[25];
00814     polygon[18].Texture = texture[2].TexID;
00815     polygon[18].Vertex[0].u = 0.0;
00816     polygon[18].Vertex[0].v = 0.0;
00817     polygon[18].Vertex[1].u = 1.0;
00818     polygon[18].Vertex[1].v = 1.0;
00819     polygon[18].Vertex[2].u = 0.0;
00820     polygon[18].Vertex[2].v = 1.0;
00821 
00822     polygon[19].Scale[0] = 2.0;
00823     polygon[19].Scale[1] = 1.0;
00824     polygon[19].Shift[0] = 0.0;
00825     polygon[19].Shift[1] = 20.0;
00826     polygon[19].Rotate = 0.0;
00827     polygon[19].Vertex[0] = vertex[9];
00828     polygon[19].Vertex[1] = vertex[10];
00829     polygon[19].Vertex[2] = vertex[26];
00830     polygon[19].Texture = texture[2].TexID;
00831     polygon[19].Vertex[0].u = 0.0;
00832     polygon[19].Vertex[0].v = 0.0;
00833     polygon[19].Vertex[1].u = 1.0;
00834     polygon[19].Vertex[1].v = 0.0;
00835     polygon[19].Vertex[2].u = 1.0;
00836     polygon[19].Vertex[2].v = 1.0;
00837 
00838     polygon[20].Scale[0] = 2.0;
00839     polygon[20].Scale[1] = 1.0;
00840     polygon[20].Shift[0] = 0.0;
00841     polygon[20].Shift[1] = 0.0;
00842     polygon[20].Rotate = 0.0;
00843     polygon[20].Vertex[0] = vertex[10];
00844     polygon[20].Vertex[1] = vertex[27];
00845     polygon[20].Vertex[2] = vertex[26];
00846     polygon[20].Texture = texture[2].TexID;
00847     polygon[20].Vertex[0].u = 0.0;
00848     polygon[20].Vertex[0].v = 0.0;
00849     polygon[20].Vertex[1].u = 1.0;
00850     polygon[20].Vertex[1].v = 1.0;
00851     polygon[20].Vertex[2].u = 0.0;
00852     polygon[20].Vertex[2].v = 1.0;
00853 
00854     polygon[21].Scale[0] = 2.0;
00855     polygon[21].Scale[1] = 1.0;
00856     polygon[21].Shift[0] = 0.0;
00857     polygon[21].Shift[1] = 0.0;
00858     polygon[21].Rotate = 0.0;
00859     polygon[21].Vertex[0] = vertex[10];
00860     polygon[21].Vertex[1] = vertex[11];
00861     polygon[21].Vertex[2] = vertex[27];
00862     polygon[21].Texture = texture[2].TexID;
00863     polygon[21].Vertex[0].u = 0.0;
00864     polygon[21].Vertex[0].v = 0.0;
00865     polygon[21].Vertex[1].u = 1.0;
00866     polygon[21].Vertex[1].v = 0.0;
00867     polygon[21].Vertex[2].u = 1.0;
00868     polygon[21].Vertex[2].v = 1.0;
00869 
00870     polygon[22].Scale[0] = 2.0;
00871     polygon[22].Scale[1] = 1.0;
00872     polygon[22].Shift[0] = 0.0;
00873     polygon[22].Shift[1] = 0.0;
00874     polygon[22].Rotate = 0.0;
00875     polygon[22].Vertex[0] = vertex[11];
00876     polygon[22].Vertex[1] = vertex[28];
00877     polygon[22].Vertex[2] = vertex[27];
00878     polygon[22].Texture = texture[2].TexID;
00879     polygon[22].Vertex[0].u = 0.0;
00880     polygon[22].Vertex[0].v = 0.0;
00881     polygon[22].Vertex[1].u = 1.0;
00882     polygon[22].Vertex[1].v = 1.0;
00883     polygon[22].Vertex[2].u = 0.0;
00884     polygon[22].Vertex[2].v = 1.0;
00885 
00886     polygon[23].Scale[0] = 2.0;
00887     polygon[23].Scale[1] = 1.0;
00888     polygon[23].Shift[0] = 0.0;
00889     polygon[23].Shift[1] = 0.0;
00890     polygon[23].Rotate = 0.0;
00891     polygon[23].Vertex[0] = vertex[11];
00892     polygon[23].Vertex[1] = vertex[12];
00893     polygon[23].Vertex[2] = vertex[28];
00894     polygon[23].Texture = texture[2].TexID;
00895     polygon[23].Vertex[0].u = 0.0;
00896     polygon[23].Vertex[0].v = 0.0;
00897     polygon[23].Vertex[1].u = 1.0;
00898     polygon[23].Vertex[1].v = 0.0;
00899     polygon[23].Vertex[2].u = 1.0;
00900     polygon[23].Vertex[2].v = 1.0;
00901 
00902 
00903     polygon[24].Scale[0] = 2.0;
00904     polygon[24].Scale[1] = 1.0;
00905     polygon[24].Shift[0] = 0.0;
00906     polygon[24].Shift[1] = 0.0;
00907     polygon[24].Rotate = 0.0;
00908     polygon[24].Vertex[0] = vertex[12];
00909     polygon[24].Vertex[1] = vertex[29];
00910     polygon[24].Vertex[2] = vertex[28];
00911     polygon[24].Texture = texture[2].TexID;
00912     polygon[24].Vertex[0].u = 0.0;
00913     polygon[24].Vertex[0].v = 0.0;
00914     polygon[24].Vertex[1].u = 1.0;
00915     polygon[24].Vertex[1].v = 1.0;
00916     polygon[24].Vertex[2].u = 0.0;
00917     polygon[24].Vertex[2].v = 1.0;
00918 
00919     polygon[25].Scale[0] = 2.0;
00920     polygon[25].Scale[1] = 1.0;
00921     polygon[25].Shift[0] = 0.0;
00922     polygon[25].Shift[1] = 0.0;
00923     polygon[25].Rotate = 0.0;
00924     polygon[25].Vertex[0] = vertex[12];
00925     polygon[25].Vertex[1] = vertex[13];
00926     polygon[25].Vertex[2] = vertex[29];
00927     polygon[25].Texture = texture[2].TexID;
00928     polygon[25].Vertex[0].u = 0.0;
00929     polygon[25].Vertex[0].v = 0.0;
00930     polygon[25].Vertex[1].u = 1.0;
00931     polygon[25].Vertex[1].v = 0.0;
00932     polygon[25].Vertex[2].u = 1.0;
00933     polygon[25].Vertex[2].v = 1.0;
00934 
00935     polygon[26].Scale[0] = 1.0;
00936     polygon[26].Scale[1] = 1.0;
00937     polygon[26].Shift[0] = 0.0;
00938     polygon[26].Shift[1] = 0.0;
00939     polygon[26].Rotate = 0.0;
00940     polygon[26].Vertex[0] = vertex[13];
00941     polygon[26].Vertex[1] = vertex[30];
00942     polygon[26].Vertex[2] = vertex[29];
00943     polygon[26].Texture = texture[2].TexID;
00944     polygon[26].Vertex[0].u = 0.0;
00945     polygon[26].Vertex[0].v = 0.0;
00946     polygon[26].Vertex[1].u = 1.0;
00947     polygon[26].Vertex[1].v = 1.0;
00948     polygon[26].Vertex[2].u = 0.0;
00949     polygon[26].Vertex[2].v = 1.0;
00950 
00951     polygon[27].Scale[0] = 1.0;
00952     polygon[27].Scale[1] = 1.0;
00953     polygon[27].Shift[0] = 0.0;
00954     polygon[27].Shift[1] = 0.0;
00955     polygon[27].Rotate = 0.0;
00956     polygon[27].Vertex[0] = vertex[13];
00957     polygon[27].Vertex[1] = vertex[14];
00958     polygon[27].Vertex[2] = vertex[30];
00959     polygon[27].Texture = texture[2].TexID;
00960     polygon[27].Vertex[0].u = 0.0;
00961     polygon[27].Vertex[0].v = 0.0;
00962     polygon[27].Vertex[1].u = 1.0;
00963     polygon[27].Vertex[1].v = 0.0;
00964     polygon[27].Vertex[2].u = 1.0;
00965     polygon[27].Vertex[2].v = 1.0;
00966 
00967     polygon[28].Scale[0] = 6.0;
00968     polygon[28].Scale[1] = 1.0;
00969     polygon[28].Shift[0] = 0.0;
00970     polygon[28].Shift[1] = 0.0;
00971     polygon[28].Rotate = 0.0;
00972     polygon[28].Vertex[0] = vertex[14];
00973     polygon[28].Vertex[1] = vertex[31];
00974     polygon[28].Vertex[2] = vertex[30];
00975     polygon[28].Texture = texture[2].TexID;
00976     polygon[28].Vertex[0].u = 0.0;
00977     polygon[28].Vertex[0].v = 0.0;
00978     polygon[28].Vertex[1].u = 1.0;
00979     polygon[28].Vertex[1].v = 1.0;
00980     polygon[28].Vertex[2].u = 0.0;
00981     polygon[28].Vertex[2].v = 1.0;
00982 
00983     polygon[29].Scale[0] = 6.0;
00984     polygon[29].Scale[1] = 1.0;
00985     polygon[29].Shift[0] = 0.0;
00986     polygon[29].Shift[1] = 0.0;
00987     polygon[29].Rotate = 0.0;
00988     polygon[29].Vertex[0] = vertex[14];
00989     polygon[29].Vertex[1] = vertex[15];
00990     polygon[29].Vertex[2] = vertex[31];
00991     polygon[29].Texture = texture[2].TexID;
00992     polygon[29].Vertex[0].u = 0.0;
00993     polygon[29].Vertex[0].v = 0.0;
00994     polygon[29].Vertex[1].u = 1.0;
00995     polygon[29].Vertex[1].v = 0.0;
00996     polygon[29].Vertex[2].u = 1.0;
00997     polygon[29].Vertex[2].v = 1.0;
00998 
00999     polygon[30].Scale[0] = 5.0;
01000     polygon[30].Scale[1] = 1.0;
01001     polygon[30].Shift[0] = 0.0;
01002     polygon[30].Shift[1] = 0.0;
01003     polygon[30].Rotate = 0.0;
01004     polygon[30].Vertex[0] = vertex[15];
01005     polygon[30].Vertex[1] = vertex[16];
01006     polygon[30].Vertex[2] = vertex[31];
01007     polygon[30].Texture = texture[2].TexID;
01008     polygon[30].Vertex[0].u = 0.0;
01009     polygon[30].Vertex[0].v = 0.0;
01010     polygon[30].Vertex[1].u = 1.0;
01011     polygon[30].Vertex[1].v = 1.0;
01012     polygon[30].Vertex[2].u = 0.0;
01013     polygon[30].Vertex[2].v = 1.0;
01014 
01015     polygon[31].Scale[0] = 5.0;
01016     polygon[31].Scale[1] = 1.0;
01017     polygon[31].Shift[0] = 0.0;
01018     polygon[31].Shift[1] = 0.0;
01019     polygon[31].Rotate = 0.0;
01020     polygon[31].Vertex[0] = vertex[15];
01021     polygon[31].Vertex[1] = vertex[0];
01022     polygon[31].Vertex[2] = vertex[16];
01023     polygon[31].Texture = texture[2].TexID;
01024     polygon[31].Vertex[0].u = 0.0;
01025     polygon[31].Vertex[0].v = 0.0;
01026     polygon[31].Vertex[1].u = 1.0;
01027     polygon[31].Vertex[1].v = 0.0;
01028     polygon[31].Vertex[2].u = 1.0;
01029     polygon[31].Vertex[2].v = 1.0;
01030 
01031     polygon[32].Scale[0] = 5.0;
01032     polygon[32].Scale[1] = 5.0;
01033     polygon[32].Shift[0] = 0.0;
01034     polygon[32].Shift[1] = 0.0;
01035     polygon[32].Rotate = 0.0;
01036     polygon[32].Vertex[0] = vertex[15];
01037     polygon[32].Vertex[1] = vertex[1];
01038     polygon[32].Vertex[2] = vertex[0];
01039     polygon[32].Texture = texture[0].TexID;
01040     polygon[32].Vertex[0].u = 0.0;
01041     polygon[32].Vertex[0].v = 0.0;
01042     polygon[32].Vertex[1].u = 1.0;
01043     polygon[32].Vertex[1].v = 1.0;
01044     polygon[32].Vertex[2].u = 0.0;
01045     polygon[32].Vertex[2].v = 1.0;
01046 
01047     polygon[33].Scale[0] = 5.0;
01048     polygon[33].Scale[1] = 5.0;
01049     polygon[33].Shift[0] = 0.0;
01050     polygon[33].Shift[1] = 0.0;
01051     polygon[33].Rotate = 0.0;
01052     polygon[33].Vertex[0] = vertex[15];
01053     polygon[33].Vertex[1] = vertex[14];
01054     polygon[33].Vertex[2] = vertex[1];
01055     polygon[33].Texture = texture[0].TexID;
01056     polygon[33].Vertex[0].u = 0.0;
01057     polygon[33].Vertex[0].v = 0.0;
01058     polygon[33].Vertex[1].u = 1.0;
01059     polygon[33].Vertex[1].v = 0.0;
01060     polygon[33].Vertex[2].u = 1.0;
01061     polygon[33].Vertex[2].v = 1.0;
01062 
01063     polygon[34].Scale[0] = 5.0;
01064     polygon[34].Scale[1] = 5.0;
01065     polygon[34].Shift[0] = 0.0;
01066     polygon[34].Shift[1] = 0.0;
01067     polygon[34].Rotate = 0.0;
01068     polygon[34].Vertex[0] = vertex[13];
01069     polygon[34].Vertex[1] = vertex[3];
01070     polygon[34].Vertex[2] = vertex[2];
01071     polygon[34].Texture = texture[0].TexID;
01072     polygon[34].Vertex[0].u = 0.0;
01073     polygon[34].Vertex[0].v = 0.0;
01074     polygon[34].Vertex[1].u = 1.0;
01075     polygon[34].Vertex[1].v = 1.0;
01076     polygon[34].Vertex[2].u = 0.0;
01077     polygon[34].Vertex[2].v = 1.0;
01078 
01079     polygon[35].Scale[0] = 5.0;
01080     polygon[35].Scale[1] = 5.0;
01081     polygon[35].Shift[0] = 0.0;
01082     polygon[35].Shift[1] = 0.0;
01083     polygon[35].Rotate = 0.0;
01084     polygon[35].Vertex[0] = vertex[13];
01085     polygon[35].Vertex[1] = vertex[4];
01086     polygon[35].Vertex[2] = vertex[3];
01087     polygon[35].Texture = texture[0].TexID;
01088     polygon[35].Vertex[0].u = 0.0;
01089     polygon[35].Vertex[0].v = 0.0;
01090     polygon[35].Vertex[1].u = 1.0;
01091     polygon[35].Vertex[1].v = 0.0;
01092     polygon[35].Vertex[2].u = 1.0;
01093     polygon[35].Vertex[2].v = 1.0;
01094 
01095     polygon[36].Scale[0] = 1.0;
01096     polygon[36].Scale[1] = 2.0;
01097     polygon[36].Shift[0] = 0.0;
01098     polygon[36].Shift[1] = 0.0;
01099     polygon[36].Rotate = 0.0;
01100     polygon[36].Vertex[0] = vertex[11];
01101     polygon[36].Vertex[1] = vertex[5];
01102     polygon[36].Vertex[2] = vertex[12];
01103     polygon[36].Texture = texture[0].TexID;
01104     polygon[36].Vertex[0].u = 0.0;
01105     polygon[36].Vertex[0].v = 0.0;
01106     polygon[36].Vertex[1].u = 1.0;
01107     polygon[36].Vertex[1].v = 1.0;
01108     polygon[36].Vertex[2].u = 0.0;
01109     polygon[36].Vertex[2].v = 1.0;
01110 
01111     polygon[37].Scale[0] = 1.0;
01112     polygon[37].Scale[1] = 2.0;
01113     polygon[37].Shift[0] = 0.0;
01114     polygon[37].Shift[1] = 0.0;
01115     polygon[37].Rotate = 0.0;
01116     polygon[37].Vertex[0] = vertex[11];
01117     polygon[37].Vertex[1] = vertex[6];
01118     polygon[37].Vertex[2] = vertex[5];
01119     polygon[37].Texture = texture[0].TexID;
01120     polygon[37].Vertex[0].u = 0.0;
01121     polygon[37].Vertex[0].v = 0.0;
01122     polygon[37].Vertex[1].u = 1.0;
01123     polygon[37].Vertex[1].v = 0.0;
01124     polygon[37].Vertex[2].u = 1.0;
01125     polygon[37].Vertex[2].v = 1.0;
01126 
01127     polygon[38].Scale[0] = 5.0;
01128     polygon[38].Scale[1] = 5.0;
01129     polygon[38].Shift[0] = 0.0;
01130     polygon[38].Shift[1] = 0.0;
01131     polygon[38].Rotate = 0.0;
01132     polygon[38].Vertex[0] = vertex[9];
01133     polygon[38].Vertex[1] = vertex[7];
01134     polygon[38].Vertex[2] = vertex[10];
01135     polygon[38].Texture = texture[0].TexID;
01136     polygon[38].Vertex[0].u = 0.0;
01137     polygon[38].Vertex[0].v = 0.0;
01138     polygon[38].Vertex[1].u = 1.0;
01139     polygon[38].Vertex[1].v = 1.0;
01140     polygon[38].Vertex[2].u = 0.0;
01141     polygon[38].Vertex[2].v = 1.0;
01142 
01143     polygon[39].Scale[0] = 5.0;
01144     polygon[39].Scale[1] = 5.0;
01145     polygon[39].Shift[0] = 0.0;
01146     polygon[39].Shift[1] = 0.0;
01147     polygon[39].Rotate = 0.0;
01148     polygon[39].Vertex[0] = vertex[9];
01149     polygon[39].Vertex[1] = vertex[8];
01150     polygon[39].Vertex[2] = vertex[7];
01151     polygon[39].Texture = texture[0].TexID;
01152     polygon[39].Vertex[0].u = 0.0;
01153     polygon[39].Vertex[0].v = 0.0;
01154     polygon[39].Vertex[1].u = 1.0;
01155     polygon[39].Vertex[1].v = 0.0;
01156     polygon[39].Vertex[2].u = 1.0;
01157     polygon[39].Vertex[2].v = 1.0;
01158 
01159     polygon[40].Scale[0] = 5.0;
01160     polygon[40].Scale[1] = 1.0;
01161     polygon[40].Shift[0] = 0.0;
01162     polygon[40].Shift[1] = 0.0;
01163     polygon[40].Rotate = 0.0;
01164     polygon[40].Vertex[0] = vertex[18];
01165     polygon[40].Vertex[1] = vertex[16];
01166     polygon[40].Vertex[2] = vertex[17];
01167     polygon[40].Texture = texture[1].TexID;
01168     polygon[40].Vertex[0].u = 0.0;
01169     polygon[40].Vertex[0].v = 0.0;
01170     polygon[40].Vertex[1].u = 1.0;
01171     polygon[40].Vertex[1].v = 1.0;
01172     polygon[40].Vertex[2].u = 0.0;
01173     polygon[40].Vertex[2].v = 1.0;
01174 
01175     polygon[41].Scale[0] = 5.0;
01176     polygon[41].Scale[1] = 1.0;
01177     polygon[41].Shift[0] = 0.0;
01178     polygon[41].Shift[1] = 0.0;
01179     polygon[41].Rotate = 0.0;
01180     polygon[41].Vertex[0] = vertex[18];
01181     polygon[41].Vertex[1] = vertex[34];
01182     polygon[41].Vertex[2] = vertex[16];
01183     polygon[41].Texture = texture[1].TexID;
01184     polygon[41].Vertex[0].u = 0.0;
01185     polygon[41].Vertex[0].v = 0.0;
01186     polygon[41].Vertex[1].u = 1.0;
01187     polygon[41].Vertex[1].v = 0.0;
01188     polygon[41].Vertex[2].u = 1.0;
01189     polygon[41].Vertex[2].v = 1.0;
01190 
01191     polygon[42].Scale[0] = 3.0;
01192     polygon[42].Scale[1] = 2.0;
01193     polygon[42].Shift[0] = 0.0;
01194     polygon[42].Shift[1] = 0.0;
01195     polygon[42].Rotate = 0.0;
01196     polygon[42].Vertex[0] = vertex[36];
01197     polygon[42].Vertex[1] = vertex[18];
01198     polygon[42].Vertex[2] = vertex[19];
01199     polygon[42].Texture = texture[3].TexID;
01200     polygon[42].Vertex[0].u = 0.0;
01201     polygon[42].Vertex[0].v = 0.0;
01202     polygon[42].Vertex[1].u = 1.0;
01203     polygon[42].Vertex[1].v = 1.0;
01204     polygon[42].Vertex[2].u = 0.0;
01205     polygon[42].Vertex[2].v = 1.0;
01206 
01207     polygon[43].Scale[0] = 3.0;
01208     polygon[43].Scale[1] = 2.0;
01209     polygon[43].Shift[0] = 0.0;
01210     polygon[43].Shift[1] = 0.0;
01211     polygon[43].Rotate = 0.0;
01212     polygon[43].Vertex[0] = vertex[36];
01213     polygon[43].Vertex[1] = vertex[35];
01214     polygon[43].Vertex[2] = vertex[18];
01215     polygon[43].Texture = texture[3].TexID;
01216     polygon[43].Vertex[0].u = 0.0;
01217     polygon[43].Vertex[0].v = 0.0;
01218     polygon[43].Vertex[1].u = 1.0;
01219     polygon[43].Vertex[1].v = 0.0;
01220     polygon[43].Vertex[2].u = 1.0;
01221     polygon[43].Vertex[2].v = 1.0;
01222 
01223     polygon[44].Scale[0] = 1.0;
01224     polygon[44].Scale[1] = 2.0;
01225     polygon[44].Shift[0] = 0.0;
01226     polygon[44].Shift[1] = 0.0;
01227     polygon[44].Rotate = 0.0;
01228     polygon[44].Vertex[0] = vertex[22];
01229     polygon[44].Vertex[1] = vertex[28];
01230     polygon[44].Vertex[2] = vertex[21];
01231     polygon[44].Texture = texture[1].TexID;
01232     polygon[44].Vertex[0].u = 0.0;
01233     polygon[44].Vertex[0].v = 0.0;
01234     polygon[44].Vertex[1].u = 1.0;
01235     polygon[44].Vertex[1].v = 1.0;
01236     polygon[44].Vertex[2].u = 0.0;
01237     polygon[44].Vertex[2].v = 1.0;
01238 
01239     polygon[45].Scale[0] = 1.0;
01240     polygon[45].Scale[1] = 2.0;
01241     polygon[45].Shift[0] = 0.0;
01242     polygon[45].Shift[1] = 0.0;
01243     polygon[45].Rotate = 0.0;
01244     polygon[45].Vertex[0] = vertex[22];
01245     polygon[45].Vertex[1] = vertex[27];
01246     polygon[45].Vertex[2] = vertex[28];
01247     polygon[45].Texture = texture[1].TexID;
01248     polygon[45].Vertex[0].u = 0.0;
01249     polygon[45].Vertex[0].v = 0.0;
01250     polygon[45].Vertex[1].u = 1.0;
01251     polygon[45].Vertex[1].v = 0.0;
01252     polygon[45].Vertex[2].u = 1.0;
01253     polygon[45].Vertex[2].v = 1.0;
01254 
01255     polygon[46].Scale[0] = 5.0;
01256     polygon[46].Scale[1] = 5.0;
01257     polygon[46].Shift[0] = 0.0;
01258     polygon[46].Shift[1] = 0.0;
01259     polygon[46].Rotate = 0.0;
01260     polygon[46].Vertex[0] = vertex[24];
01261     polygon[46].Vertex[1] = vertex[26];
01262     polygon[46].Vertex[2] = vertex[23];
01263     polygon[46].Texture = texture[1].TexID;
01264     polygon[46].Vertex[0].u = 0.0;
01265     polygon[46].Vertex[0].v = 0.0;
01266     polygon[46].Vertex[1].u = 1.0;
01267     polygon[46].Vertex[1].v = 1.0;
01268     polygon[46].Vertex[2].u = 0.0;
01269     polygon[46].Vertex[2].v = 1.0;
01270 
01271     polygon[47].Scale[0] = 5.0;
01272     polygon[47].Scale[1] = 5.0;
01273     polygon[47].Shift[0] = 0.0;
01274     polygon[47].Shift[1] = 0.0;
01275     polygon[47].Rotate = 0.0;
01276     polygon[47].Vertex[0] = vertex[24];
01277     polygon[47].Vertex[1] = vertex[25];
01278     polygon[47].Vertex[2] = vertex[26];
01279     polygon[47].Texture = texture[1].TexID;
01280     polygon[47].Vertex[0].u = 0.0;
01281     polygon[47].Vertex[0].v = 0.0;
01282     polygon[47].Vertex[1].u = 1.0;
01283     polygon[47].Vertex[1].v = 0.0;
01284     polygon[47].Vertex[2].u = 1.0;
01285     polygon[47].Vertex[2].v = 1.0;
01286 
01287     polygon[48].Scale[0] = 3.0;
01288     polygon[48].Scale[1] = 2.0;
01289     polygon[48].Shift[0] = 0.0;
01290     polygon[48].Shift[1] = 0.0;
01291     polygon[48].Rotate = 0.0;
01292     polygon[48].Vertex[0] = vertex[20];
01293     polygon[48].Vertex[1] = vertex[35];
01294     polygon[48].Vertex[2] = vertex[36];
01295     polygon[48].Texture = texture[3].TexID;
01296     polygon[48].Vertex[0].u = 0.0;
01297     polygon[48].Vertex[0].v = 0.0;
01298     polygon[48].Vertex[1].u = 1.0;
01299     polygon[48].Vertex[1].v = 1.0;
01300     polygon[48].Vertex[2].u = 0.0;
01301     polygon[48].Vertex[2].v = 1.0;
01302 
01303     polygon[49].Scale[0] = 3.0;
01304     polygon[49].Scale[1] = 2.0;
01305     polygon[49].Shift[0] = 0.0;
01306     polygon[49].Shift[1] = 0.0;
01307     polygon[49].Rotate = 0.0;
01308     polygon[49].Vertex[0] = vertex[20];
01309     polygon[49].Vertex[1] = vertex[29];
01310     polygon[49].Vertex[2] = vertex[35];
01311     polygon[49].Texture = texture[3].TexID;
01312     polygon[49].Vertex[0].u = 0.0;
01313     polygon[49].Vertex[0].v = 0.0;
01314     polygon[49].Vertex[1].u = 1.0;
01315     polygon[49].Vertex[1].v = 0.0;
01316     polygon[49].Vertex[2].u = 1.0;
01317     polygon[49].Vertex[2].v = 1.0;
01318 
01319     polygon[50].Scale[0] = 5.0;
01320     polygon[50].Scale[1] = 5.0;
01321     polygon[50].Shift[0] = 0.0;
01322     polygon[50].Shift[1] = 0.0;
01323     polygon[50].Rotate = 0.0;
01324     polygon[50].Vertex[0] = vertex[30];
01325     polygon[50].Vertex[1] = vertex[32];
01326     polygon[50].Vertex[2] = vertex[29];
01327     polygon[50].Texture = texture[1].TexID;
01328     polygon[50].Vertex[0].u = 0.0;
01329     polygon[50].Vertex[0].v = 0.0;
01330     polygon[50].Vertex[1].u = 1.0;
01331     polygon[50].Vertex[1].v = 1.0;
01332     polygon[50].Vertex[2].u = 0.0;
01333     polygon[50].Vertex[2].v = 1.0;
01334 
01335     polygon[51].Scale[0] = 5.0;
01336     polygon[51].Scale[1] = 5.0;
01337     polygon[51].Shift[0] = 0.0;
01338     polygon[51].Shift[1] = 0.0;
01339     polygon[51].Rotate = 0.0;
01340     polygon[51].Vertex[0] = vertex[30];
01341     polygon[51].Vertex[1] = vertex[31];
01342     polygon[51].Vertex[2] = vertex[32];
01343     polygon[51].Texture = texture[1].TexID;
01344     polygon[51].Vertex[0].u = 0.0;
01345     polygon[51].Vertex[0].v = 0.0;
01346     polygon[51].Vertex[1].u = 1.0;
01347     polygon[51].Vertex[1].v = 0.0;
01348     polygon[51].Vertex[2].u = 1.0;
01349     polygon[51].Vertex[2].v = 1.0;
01350 
01351     polygon[52].Scale[0] = 3.0;
01352     polygon[52].Scale[1] = 2.0;
01353     polygon[52].Shift[0] = 0.0;
01354     polygon[52].Shift[1] = 0.0;
01355     polygon[52].Rotate = 0.0;
01356     polygon[52].Vertex[0] = vertex[29];
01357     polygon[52].Vertex[1] = vertex[33];
01358     polygon[52].Vertex[2] = vertex[35];
01359     polygon[52].Texture = texture[3].TexID;
01360     polygon[52].Vertex[0].u = 0.0;
01361     polygon[52].Vertex[0].v = 0.0;
01362     polygon[52].Vertex[1].u = 1.0;
01363     polygon[52].Vertex[1].v = 1.0;
01364     polygon[52].Vertex[2].u = 0.0;
01365     polygon[52].Vertex[2].v = 1.0;
01366 
01367     polygon[53].Scale[0] = 3.0;
01368     polygon[53].Scale[1] = 2.0;
01369     polygon[53].Shift[0] = 0.0;
01370     polygon[53].Shift[1] = 0.0;
01371     polygon[53].Rotate = 0.0;
01372     polygon[53].Vertex[0] = vertex[29];
01373     polygon[53].Vertex[1] = vertex[32];
01374     polygon[53].Vertex[2] = vertex[33];
01375     polygon[53].Texture = texture[3].TexID;
01376     polygon[53].Vertex[0].u = 0.0;
01377     polygon[53].Vertex[0].v = 0.0;
01378     polygon[53].Vertex[1].u = 1.0;
01379     polygon[53].Vertex[1].v = 0.0;
01380     polygon[53].Vertex[2].u = 1.0;
01381     polygon[53].Vertex[2].v = 1.0;
01382 
01383     polygon[54].Scale[0] = 3.0;
01384     polygon[54].Scale[1] = 2.0;
01385     polygon[54].Shift[0] = 0.0;
01386     polygon[54].Shift[1] = 0.0;
01387     polygon[54].Rotate = 0.0;
01388     polygon[54].Vertex[0] = vertex[35];
01389     polygon[54].Vertex[1] = vertex[34];
01390     polygon[54].Vertex[2] = vertex[18];
01391     polygon[54].Texture = texture[3].TexID;
01392     polygon[54].Vertex[0].u = 0.0;
01393     polygon[54].Vertex[0].v = 0.0;
01394     polygon[54].Vertex[1].u = 1.0;
01395     polygon[54].Vertex[1].v = 1.0;
01396     polygon[54].Vertex[2].u = 0.0;
01397     polygon[54].Vertex[2].v = 1.0;
01398 
01399     polygon[55].Scale[0] = 3.0;
01400     polygon[55].Scale[1] = 2.0;
01401     polygon[55].Shift[0] = 0.0;
01402     polygon[55].Shift[1] = 0.0;
01403     polygon[55].Rotate = 0.0;
01404     polygon[55].Vertex[0] = vertex[35];
01405     polygon[55].Vertex[1] = vertex[33];
01406     polygon[55].Vertex[2] = vertex[34];
01407     polygon[55].Texture = texture[3].TexID;
01408     polygon[55].Vertex[0].u = 0.0;
01409     polygon[55].Vertex[0].v = 0.0;
01410     polygon[55].Vertex[1].u = 1.0;
01411     polygon[55].Vertex[1].v = 0.0;
01412     polygon[55].Vertex[2].u = 1.0;
01413     polygon[55].Vertex[2].v = 1.0;
01414 
01415     polygon[56].Scale[0] = 4.0;
01416     polygon[56].Scale[1] = 3.0;
01417     polygon[56].Shift[0] = 0.0;
01418     polygon[56].Shift[1] = 0.0;
01419     polygon[56].Rotate = 0.0;
01420     polygon[56].Vertex[0] = vertex[32];
01421     polygon[56].Vertex[1] = vertex[34];
01422     polygon[56].Vertex[2] = vertex[33];
01423     polygon[56].Texture = texture[2].TexID;
01424     polygon[56].Vertex[0].u = 0.0;
01425     polygon[56].Vertex[0].v = 0.0;
01426     polygon[56].Vertex[1].u = 1.0;
01427     polygon[56].Vertex[1].v = 0.0;
01428     polygon[56].Vertex[2].u = 0.5;
01429     polygon[56].Vertex[2].v = 0.5;
01430 
01431     polygon[57].Scale[0] = 4.0;
01432     polygon[57].Scale[1] = 3.0;
01433     polygon[57].Shift[0] = 0.0;
01434     polygon[57].Shift[1] = 0.0;
01435     polygon[57].Rotate = 0;
01436     polygon[57].Vertex[0] = vertex[19];
01437     polygon[57].Vertex[1] = vertex[20];
01438     polygon[57].Vertex[2] = vertex[36];
01439     polygon[57].Texture = texture[2].TexID;
01440     polygon[57].Vertex[0].u = 0.0;
01441     polygon[57].Vertex[0].v = 0.0;
01442     polygon[57].Vertex[1].u = 1.0;
01443     polygon[57].Vertex[1].v = 0.0;
01444     polygon[57].Vertex[2].u = 0.5;
01445     polygon[57].Vertex[2].v = 0.5;
01446 
01447     for (int loop = 0; loop < numPolygons; loop++)
01448         polygon[loop].SetNormal();
01449 }
01450 
01451 void SetGLProperties()
01452 {
01453     glCullFace(GL_BACK);
01454     glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
01455     glClearDepth(1.0);
01456     glDepthFunc(GL_LESS);
01457     glEnable(GL_DEPTH_TEST);
01458     glShadeModel(GL_SMOOTH);
01459     glEnable(GL_NORMALIZE);
01460     glEnable(GL_CULL_FACE);
01461 }
01462 
01463 void SetGLProjection(int Width, int Height)
01464 {
01465     if (Height==0)
01466         Height=1;
01467     glViewport(0, 0, Width, Height);
01468     glMatrixMode(GL_PROJECTION);
01469     glLoadIdentity();
01470     gluPerspective(45.0,(float)Width/(float)Height, 0.8, 500.0);
01471 }
01472 
01473 void SetGLView(int Width, int Height)
01474 {
01475     SetGLProjection(Width, Height);
01476     glMatrixMode(GL_MODELVIEW);
01477     glLoadIdentity();
01478 }
01479 
01480 void SetGLMaterial()
01481 {
01482     float mat_ambient[] = { 1.0, 1.0, 1.0, 1.0 };
01483     float mat_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
01484     float mat_specular[] = { 0.9, 0.9, 0.9, 1.0 };
01485     float mat_emission[] = { 0.0, 0.0, 0.0, 1.0 };
01486     float mat_shininess[] = { 80.0 };
01487 
01488     glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
01489     glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
01490     glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
01491     glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
01492     glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
01493 }
01494 
01495 int SetGLTexture(TEXTURE* texture)
01496 {
01497     glEnable(GL_TEXTURE_2D);
01498 
01499     sprintf(texture[0].TexName, "%s", "floor.tga");
01500     if (!texture[0].LoadTGA())
01501     {
01502         MessageBox(NULL,"Failed to load floor image","Error",MB_OK|MB_ICONERROR);
01503         return FALSE;
01504     }
01505     sprintf(texture[1].TexName, "%s", "roof.tga");
01506     if (!texture[1].LoadTGA())
01507     {
01508         MessageBox(NULL,"Failed to load roof image","Error",MB_OK|MB_ICONERROR);
01509         return FALSE;
01510     }
01511     sprintf(texture[2].TexName, "%s", "wall.tga");
01512     if (!texture[2].LoadTGA())
01513     {
01514         MessageBox(NULL,"Failed to load wall image","Error",MB_OK|MB_ICONERROR);
01515         return FALSE;
01516     }
01517     sprintf(texture[3].TexName, "%s", "tile.tga");
01518     if (!texture[3].LoadTGA())
01519     {
01520         MessageBox(NULL,"Failed to load tile image","Error",MB_OK|MB_ICONERROR);
01521         return FALSE;
01522     }
01523     return TRUE;
01524 }
01525 
01526 void DrawMyText()
01527 {
01528     glBlendFunc(GL_ONE,  GL_ONE_MINUS_SRC_ALPHA) ;
01529     glDisable(GL_LIGHTING);
01530     glColor3f(0.0, 1.0, 0.0);
01531     glEnable(GL_BLEND);
01532     glDisable(GL_DEPTH_TEST);
01533     glPushMatrix();
01534     glLoadIdentity();
01535     glFontBegin(&myFont);
01536     char text[256];
01537 
01538     glFontTextOut("Tutorial #13  (Portals)", -52, 40, -100);
01539 
01540     sprintf(text, "FPS = %d", fps);
01541     glFontTextOut(text, -52, 38, -100);
01542 
01543     sprintf(text, "%s", "Press M to change camera mode");
01544     glFontTextOut(text, -52, 34, -100);
01545 
01546     sprintf(text, "%s", "Press P to toggle the portal rendering");
01547     glFontTextOut(text, -52, 30, -100);
01548 
01549     if (showportals)
01550     {
01551         sprintf(text, "Current leaf = %d", currentleaf);
01552         glFontTextOut(text, -52, 26, -100);
01553 
01554         sprintf(text, "Number of portals = %d", numcurrentportals);
01555         glFontTextOut(text, -52, 22, -100);
01556     }
01557 
01558     glFontEnd();
01559     glPopMatrix();
01560     glEnable(GL_DEPTH_TEST);
01561     glDisable(GL_BLEND);
01562     glEnable(GL_LIGHTING);
01563 }
01564 
01565 void DrawGrid()
01566 {
01567     glDisable(GL_TEXTURE_2D);
01568     glDisable(GL_LIGHTING);
01569     glPushMatrix();
01570     glTranslatef(0,-2.0,0);
01571     glColor3f(0.0f,1.0f,0.0f);
01572 
01573     float Line = -10;
01574     int Grid;
01575     glBegin(GL_LINES);
01576     for(Grid = 0; Grid <= 20; Grid += 1)
01577     {
01578         glVertex3f(Line + Grid, 0, -10);
01579         glVertex3f(Line + Grid, 0, 10);
01580         glVertex3f(-10, 0, Line + Grid);
01581         glVertex3f(10, 0, Line + Grid);
01582     }
01583     glEnd();
01584     glPopMatrix();
01585     glEnable(GL_TEXTURE_2D);
01586     glEnable(GL_LIGHTING);
01587 }
01588 
01589 void DrawWorld(BSP_node* root)
01590 {
01591     float mat_ambient[] = { 0.8, 0.8, 0.8, 1.0 };
01592     float mat_diffuse[] = { 0.8, 0.8, 0.8, 1.0 };
01593     glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
01594     glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
01595 
01596     glPushMatrix();
01597 
01598     glDisable (GL_DEPTH_TEST);
01599     RenderBSP(root);
01600     glEnable (GL_DEPTH_TEST);
01601 
01602     glPopMatrix();
01603 
01604 /*
01605     //Draw polygons that are in the leaf
01606     for (int loop = 0; loop < numPolygons; loop++)
01607     {
01608         glMatrixMode(GL_TEXTURE);
01609         glPushMatrix();
01610 
01611 
01612         glScalef(polygon[loop].Scale[0], polygon[loop].Scale[1], 1.0f);
01613         glTranslatef(polygon[loop].Shift[0], polygon[loop].Shift[1], 0.0f);
01614         glRotatef(polygon[loop].Rotate, 0.0f, 0.0f, 1.0f);
01615 
01616         glBindTexture(GL_TEXTURE_2D, polygon[loop].Texture);
01617         glBegin(GL_TRIANGLES);
01618         glNormal3fv(&polygon[loop].Vertex[0].nx);
01619         glTexCoord2f(polygon[loop].Vertex[0].u, polygon[loop].Vertex[0].v);
01620         glVertex3fv(&polygon[loop].Vertex[0].x);
01621         glTexCoord2f(polygon[loop].Vertex[1].u, polygon[loop].Vertex[1].v);
01622         glVertex3fv(&polygon[loop].Vertex[1].x);
01623         glTexCoord2f(polygon[loop].Vertex[2].u, polygon[loop].Vertex[2].v);
01624         glVertex3fv(&polygon[loop].Vertex[2].x);
01625         glEnd();
01626 
01627         glPopMatrix();
01628         glMatrixMode(GL_MODELVIEW);
01629     }
01630 */
01631 }
01632 
01633 void DrawGreenSphere()
01634 {
01635     float mat_ambient[] = { 0.2, 1.0, 0.1, 1.0 };
01636     float mat_diffuse[] = { 0.2, 1.0, 0.1, 1.0 };
01637     glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
01638     glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
01639 //    glDisable(GL_TEXTURE_2D);
01640     glPushMatrix();
01641     glLoadIdentity();
01642     glTranslatef(-2.0, -2.0, -8.0);
01643     GLUquadricObj * sphere = gluNewQuadric();
01644     gluQuadricOrientation(sphere, GLU_OUTSIDE);
01645     gluSphere(sphere,0.3,20,20);
01646     glPopMatrix();
01647 //    glEnable(GL_TEXTURE_2D);
01648 }
01649 
01650 void DrawSphere()
01651 {
01652     float mat_ambient[] = { 0.8, 0.5, 0.1, 1.0 };
01653     float mat_diffuse[] = { 0.8, 0.5, 0.1, 1.0 };
01654     glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
01655     glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
01656 
01657     glDisable(GL_TEXTURE_2D);
01658     glPushMatrix();
01659     glTranslatef(-3.0f,-1.0f,-8.0f);
01660     GLUquadricObj * sphere = gluNewQuadric();
01661     gluQuadricOrientation(sphere, GLU_OUTSIDE);
01662     gluSphere(sphere, 1.0, 50, 50);
01663     glPopMatrix();
01664     glEnable(GL_TEXTURE_2D);
01665 }
01666 
01667 void DrawCone()
01668 {
01669     float mat_ambient[] = { 0.1, 0.5, 1.0, 1.0 };
01670     float mat_diffuse[] = { 0.1, 0.5, 1.0, 1.0 };
01671     glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
01672     glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
01673 
01674     glDisable(GL_TEXTURE_2D);
01675     glDisable(GL_CULL_FACE);
01676     glPushMatrix();
01677     glTranslatef(3.0f,-2.0f,-8.0f);
01678     glRotatef(-90,1,0,0);
01679     GLUquadricObj * cylinder = gluNewQuadric();
01680     gluQuadricOrientation(cylinder, GLU_OUTSIDE);
01681     gluCylinder(cylinder,1.0,0.0,2.0,20,20);
01682     glPopMatrix();
01683     glEnable(GL_CULL_FACE);
01684     glEnable(GL_TEXTURE_2D);
01685 }
01686 
01687 float GetTimePassed(float& lasttime, int average, float* lastmultiplier)
01688 {
01689     float timeoffset;
01690     float currenttime;
01691 /*
01692 If the program has just started, set last tickcount to the current tickcount.
01693 This prevents the program from thinking that several hours have passed since the last frame.
01694 */
01695     if (lasttime == 0)
01696         lasttime = (float)GetTickCount();
01697         // Get the current time
01698     currenttime = (float)GetTickCount();
01699         // Calculate the offset
01700     timeoffset = currenttime - lasttime;
01701     // If timeoffset less than 1/120 of a second (in milliseconds) then set to minimum offset
01702     if (timeoffset < 8.333333)
01703     {
01704         timeoffset = 8.333333;
01705         currenttime = lasttime + timeoffset;
01706     }
01707     // Put the current time in the lasttime variable
01708         lasttime = currenttime;
01709     // return the time offset in seconds per frame
01710         multiplier = timeoffset / 1000;
01711     for (int loop = 0; loop < average - 1; loop++)
01712     {
01713         lastmultiplier[loop] = lastmultiplier[loop + 1];
01714     }
01715     lastmultiplier[average - 1] = multiplier;
01716     for (int loop = 0; loop < average - 1; loop++)
01717         multiplier += lastmultiplier[loop];
01718     multiplier /= (float)average; 
01719         if (multiplier)
01720         fps = (int)(1.0 / multiplier);
01721     return multiplier;
01722 }
01723 
01724 bool CheckClipPlanes(CAMERA Camera, VECTOR Vect)
01725 {
01726   float ProjectionMatrix[16];
01727   float ModelViewMatrix[16];
01728   float A, B, C, Distance;
01729   int Counter = 0;
01730   glGetFloatv(GL_PROJECTION_MATRIX, ProjectionMatrix);
01731   glGetFloatv(GL_MODELVIEW_MATRIX, ModelViewMatrix);
01732 
01733   MultMatrix(ProjectionMatrix, ModelViewMatrix);
01734 
01735   //right clipping plane
01736   A = ProjectionMatrix[0] - ProjectionMatrix[3];
01737   B = ProjectionMatrix[4] - ProjectionMatrix[7];
01738   C = ProjectionMatrix[8] - ProjectionMatrix[11];
01739 
01740   Distance = -1 * (A * (-Camera.Position.x + Vect.x) + B * (-Camera.Position.y + Vect.y) + C * (-Camera.Position.z + Vect.z));
01741   if (Distance > 0)
01742     Counter++;
01743 
01744   //left clipping plane
01745   A = ProjectionMatrix[0] + ProjectionMatrix[3];
01746   B = ProjectionMatrix[4] + ProjectionMatrix[7];
01747   C = ProjectionMatrix[8] + ProjectionMatrix[11];
01748 
01749   Distance = A * (-Camera.Position.x + Vect.x) + B * (-Camera.Position.y + Vect.y) + C * (-Camera.Position.z + Vect.z);
01750   if (Distance > 0)
01751     Counter++;
01752 
01753   //top clipping plane
01754   A = ProjectionMatrix[1] - ProjectionMatrix[3];
01755   B = ProjectionMatrix[5] - ProjectionMatrix[7];
01756   C = ProjectionMatrix[9] - ProjectionMatrix[11];
01757 
01758   Distance = -1 * (A * (-Camera.Position.x + Vect.x) + B * (-Camera.Position.y + Vect.y) + C * (-Camera.Position.z + Vect.z));
01759   if (Distance > 0)
01760     Counter++;
01761 
01762   //bottom clipping plane
01763   A = ProjectionMatrix[1] + ProjectionMatrix[3];
01764   B = ProjectionMatrix[5] + ProjectionMatrix[7];
01765   C = ProjectionMatrix[9] + ProjectionMatrix[11];
01766 
01767   Distance = A * (-Camera.Position.x + Vect.x) + B * (-Camera.Position.y + Vect.y) + C * (-Camera.Position.z + Vect.z);
01768   if (Distance > 0)
01769     Counter++;
01770 
01771   // near clipping plane (might not be necessary when the near frustrum plane is close, but just in case)
01772   A = ProjectionMatrix[2] - ProjectionMatrix[3];
01773   B = ProjectionMatrix[6] - ProjectionMatrix[7];
01774   C = ProjectionMatrix[10] - ProjectionMatrix[11];
01775 
01776   Distance = A * (-Camera.Position.x + Vect.x) + B * (-Camera.Position.y + Vect.y) + C * (-Camera.Position.z + Vect.z);
01777   if (Distance > 0)
01778     Counter++;
01779 
01780   // far clipping plane (the equation didn't work for the far plane, so I'll just use a distance test)
01781   VECTOR Vect2;
01782   Vect2.x = Vect.x - Camera.Position.x;
01783   Vect2.y = Vect.y - Camera.Position.y;
01784   Vect2.z = Vect.z - Camera.Position.z;
01785   if (MagnitudeVector(Vect2) < 200)
01786     Counter++;
01787 
01788   if (Counter == 6)
01789     return 1;
01790   else
01791     return 0;
01792 }
01793 
01794 //  A halo type billboard that always faces the camera
01795 void DrawHalo(TEXTURE* texture, LIGHT* light, CAMERA* camera)
01796 {
01797     float halfwidth = 2;
01798     float halfheight = 2;
01799 
01800     MATRIX mat;
01801     glGetFloatv(GL_MODELVIEW_MATRIX, mat.Element);
01802 
01803     VECTOR right;
01804     right.x = mat.Element[0];
01805     right.y = mat.Element[4];
01806     right.z = mat.Element[8];
01807     right.Normalize();
01808     right.x *= halfwidth;
01809     right.y *= halfwidth;
01810     right.z *= halfwidth;
01811 
01812     VECTOR up;
01813     up.x = mat.Element[1];
01814     up.y = mat.Element[5];
01815     up.z = mat.Element[9];
01816     up.Normalize();
01817     up.x *= halfheight;
01818     up.y *= halfheight;
01819     up.z *= halfheight;
01820 
01821 /*
01822    If you are using a quake style camera that doesn't roll
01823    then you can use the following commented code to make a conventional
01824    billboard remain vertical. If you are using a camera with 6DOF however,
01825    then this will not work.
01826 */
01827 
01828 /*
01829     up.x = 0.0;
01830     up.z = 0.0;
01831     right.y = 0.0;
01832 //*/
01833 
01834     float mat_ambient[] = { 0.2, 0.2, 0.2, 1.0 };
01835     float mat_diffuse[] = { 0.8, 0.8, 0.8, 1.0 };
01836     glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
01837     glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
01838     glEnable(GL_BLEND);
01839     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
01840     glEnable(GL_ALPHA_TEST);
01841     glAlphaFunc(GL_GREATER, 0);
01842     glDisable(GL_LIGHTING);
01843     glColor4f(1.0, 1.0, 1.0, 1.0);
01844     glBindTexture(GL_TEXTURE_2D, texture[1].TexID);
01845     glPopMatrix();
01846         glBegin(GL_QUADS);
01847             glTexCoord2f(0.0f, 0.0f); glVertex3f(light[currentLight].Position.x + (-right.x - up.x), light[currentLight].Position.y + (-right.y - up.y), light[currentLight].Position.z + (-right.z - up.z));
01848             glTexCoord2f(1.0f, 0.0f); glVertex3f(light[currentLight].Position.x + (right.x - up.x), light[currentLight].Position.y + (right.y - up.y), light[currentLight].Position.z + (right.z - up.z));
01849             glTexCoord2f(1.0f, 1.0f); glVertex3f(light[currentLight].Position.x + (right.x + up.x), light[currentLight].Position.y + (right.y + up.y), light[currentLight].Position.z + (right.z + up.z));
01850             glTexCoord2f(0.0f, 1.0f); glVertex3f(light[currentLight].Position.x + (up.x - right.x), light[currentLight].Position.y + (up.y - right.y), light[currentLight].Position.z + (up.z - right.z));
01851         glEnd();
01852     glPopMatrix();
01853     glEnable(GL_LIGHTING);
01854     glDisable(GL_ALPHA);
01855     glDisable(GL_BLEND);
01856 }
01857 
01858 //  A fire type billboard that rotates to face the camera but remains vertical
01859 void DrawFire(TEXTURE* texture, LIGHT* light, CAMERA* camera)
01860 {
01861     float halfwidth = 1.0;
01862     float halfheight = 2.0;
01863     VECTOR FirePosition(3.0, -2.0 + halfheight, -8.0);
01864 //  Get the vector from the billboard position to the camera
01865     VECTOR A;
01866     A.x = (camera[currentCamera].Position.x - FirePosition.x);
01867     A.y = (camera[currentCamera].Position.y - FirePosition.y);
01868     A.z = (camera[currentCamera].Position.z - FirePosition.z);
01869     A.Normalize();
01870 // Set a vector to the standard up vector
01871     VECTOR B;
01872     B.x = (0);
01873     B.y = (1);
01874     B.z = (0);
01875     B.Normalize();
01876 // Take the cross product of these vectors to find a vector perpendicular to the camera
01877     VECTOR C = CrossVector(A, B);
01878     C.Normalize();
01879 
01880 // Negate the perpendicular vector to make the billboard face the front
01881     VECTOR right;
01882     right.x = -C.x * halfwidth;
01883     right.y = -C.y * halfwidth;
01884     right.z = -C.z * halfwidth;
01885 
01886     VECTOR up;
01887     up.x = 0;
01888     up.y = 1 * halfheight;
01889     up.z = 0;
01890 
01891 // Continue as normal
01892     float mat_ambient[] = { 0.2, 0.2, 0.2, 1.0 };
01893     float mat_diffuse[] = { 0.8, 0.8, 0.8, 1.0 };
01894     glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
01895     glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
01896     glEnable(GL_BLEND);
01897     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
01898     glEnable(GL_ALPHA_TEST);
01899     glAlphaFunc(GL_GREATER, 0);
01900     glDisable(GL_LIGHTING);
01901     glColor4f(1.0, 1.0, 1.0, 1.0);
01902     glBindTexture(GL_TEXTURE_2D, texture[2].TexID);
01903     glPopMatrix();
01904         glBegin(GL_QUADS);
01905             glTexCoord2f(0.0f, 0.0f); glVertex3f(FirePosition.x + (-right.x - up.x), FirePosition.y + (-right.y - up.y), FirePosition.z + (-right.z - up.z));
01906             glTexCoord2f(1.0f, 0.0f); glVertex3f(FirePosition.x + (right.x - up.x), FirePosition.y + (right.y - up.y), FirePosition.z + (right.z - up.z));
01907             glTexCoord2f(1.0f, 1.0f); glVertex3f(FirePosition.x + (right.x + up.x), FirePosition.y + (right.y + up.y), FirePosition.z + (right.z + up.z));
01908             glTexCoord2f(0.0f, 1.0f); glVertex3f(FirePosition.x + (up.x - right.x), FirePosition.y + (up.y - right.y), FirePosition.z + (up.z - right.z));
01909         glEnd();
01910     glPopMatrix();
01911     glEnable(GL_LIGHTING);
01912     glDisable(GL_ALPHA);
01913     glDisable(GL_BLEND);
01914 }
01915 
01916 void DrawBillboards(TEXTURE* texture, LIGHT* light, CAMERA* camera)
01917 {
01918         DrawHalo(texture, light, camera);
01919 
01920 /*
01921 // Draw depth sorted billboards
01922     VECTOR FirePosition(3.0, -2.0, -8.0);
01923 
01924     VECTOR VectorToCone;
01925     VectorToCone.x = FirePosition.x - camera[currentCamera].Position.x;
01926     VectorToCone.y = FirePosition.y - camera[currentCamera].Position.y;
01927     VectorToCone.z = FirePosition.z - camera[currentCamera].Position.z;
01928     float FireDistance = VectorToCone.GetMagnitude();
01929 
01930     VECTOR VectorToLight;
01931     VectorToLight.x = light[currentLight].Position.x - camera[currentCamera].Position.x;
01932     VectorToLight.y = light[currentLight].Position.y - camera[currentCamera].Position.y;
01933     VectorToLight.z = light[currentLight].Position.z - camera[currentCamera].Position.z;
01934     float LightDistance = VectorToLight.GetMagnitude();
01935 
01936     if(LightDistance < FireDistance)
01937     {
01938         DrawFire();
01939         DrawHalo();
01940     }
01941     else
01942     {
01943         DrawHalo();
01944         DrawFire();
01945     }
01946 //*/
01947 }

Generated on Fri Dec 23 05:20:17 2005 for Portals by doxygen1.2.15