Al's Programming Resource Homepage  Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

general.h File Reference

#include "shared.h"
#include "polygon.h"
#include "texture.h"
#include "camera.h"

Go to the source code of this file.

Functions

void SetGLCamera (CAMERA *)
void SetGLWorld (POLYGON *)
void SetGLProperties ()
void SetGLProjection (int Width, int Height)
void SetGLView (int Width, int Height)
void SetGLMaterial ()
void SetGLLighting ()
void SetGLTexture (TEXTURE *)
void DrawGrid ()
void DrawCube (POLYGON *, TEXTURE *)
void DrawSphere ()
void DrawCone ()
float GetTimePassed (float &, int, float *)


Function Documentation

void DrawCone  
 

Definition at line 326 of file general.cpp.

Referenced by DrawGLScene().

00327 {
00328     float mat_ambient[] = { 0.1, 0.5, 1.0, 1.0 };
00329     float mat_diffuse[] = { 0.1, 0.5, 1.0, 1.0 };
00330     glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
00331     glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
00332 
00333     glDisable(GL_TEXTURE_2D);
00334     glDisable(GL_CULL_FACE);
00335     glPushMatrix();
00336     glTranslatef(3.0f,-2.0f,-8.0f);
00337     glRotatef(-90,1,0,0);
00338     GLUquadricObj * cylinder = gluNewQuadric();
00339     gluQuadricOrientation(cylinder, GLU_OUTSIDE);
00340     gluCylinder(cylinder,1.0,0.0,2.0,20,20);
00341     glPopMatrix();
00342     glEnable(GL_CULL_FACE);
00343     glEnable(GL_TEXTURE_2D);
00344 }

void DrawCube POLYGON  ,
TEXTURE  
 

Definition at line 239 of file general.cpp.

References polygon, and texture.

Referenced by DrawGLScene().

00240 {
00241         float mat_ambient[] = { 0.8, 0.8, 0.8, 1.0 };
00242         float mat_diffuse[] = { 0.8, 0.8, 0.8, 1.0 };
00243         glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
00244         glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
00245 
00246         glBindTexture(GL_TEXTURE_2D, texture[0].TexID);
00247 
00248         glPushMatrix();
00249     glTranslatef(0.0f,0.0f,-5.0f);
00250     glBegin(GL_TRIANGLES);
00251         // Front Face
00252             glNormal3fv(&polygon[0].Vertex[0].nx);
00253         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[0].Vertex[0].x);
00254         glTexCoord2f(1.0f, 0.0f); glVertex3fv(&polygon[0].Vertex[1].x);
00255         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[0].Vertex[2].x);
00256 
00257         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[1].Vertex[0].x);
00258         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[1].Vertex[1].x);
00259         glTexCoord2f(0.0f, 1.0f); glVertex3fv(&polygon[1].Vertex[2].x);
00260         // Back Face
00261             glNormal3fv(&polygon[2].Vertex[0].nx);
00262         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[2].Vertex[0].x);
00263         glTexCoord2f(1.0f, 0.0f); glVertex3fv(&polygon[2].Vertex[1].x);
00264         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[2].Vertex[2].x);
00265 
00266         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[3].Vertex[0].x);
00267         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[3].Vertex[1].x);
00268         glTexCoord2f(0.0f, 1.0f); glVertex3fv(&polygon[3].Vertex[2].x);
00269         // Top Face
00270             glNormal3fv(&polygon[4].Vertex[0].nx);
00271         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[4].Vertex[0].x);
00272         glTexCoord2f(1.0f, 0.0f); glVertex3fv(&polygon[4].Vertex[1].x);
00273         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[4].Vertex[2].x);
00274 
00275         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[5].Vertex[0].x);
00276         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[5].Vertex[1].x);
00277         glTexCoord2f(0.0f, 1.0f); glVertex3fv(&polygon[5].Vertex[2].x);
00278         // Bottom Face
00279             glNormal3fv(&polygon[6].Vertex[0].nx);
00280         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[6].Vertex[0].x);
00281         glTexCoord2f(1.0f, 0.0f); glVertex3fv(&polygon[6].Vertex[1].x);
00282         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[6].Vertex[2].x);
00283 
00284         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[7].Vertex[0].x);
00285         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[7].Vertex[1].x);
00286         glTexCoord2f(0.0f, 1.0f); glVertex3fv(&polygon[7].Vertex[2].x);
00287         // Right face
00288             glNormal3fv(&polygon[8].Vertex[0].nx);
00289         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[8].Vertex[0].x);
00290         glTexCoord2f(1.0f, 0.0f); glVertex3fv(&polygon[8].Vertex[1].x);
00291         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[8].Vertex[2].x);
00292 
00293         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[9].Vertex[0].x);
00294         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[9].Vertex[1].x);
00295         glTexCoord2f(0.0f, 1.0f); glVertex3fv(&polygon[9].Vertex[2].x);
00296         // Left Face
00297             glNormal3fv(&polygon[10].Vertex[0].nx);
00298         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[10].Vertex[0].x);
00299         glTexCoord2f(1.0f, 0.0f); glVertex3fv(&polygon[10].Vertex[1].x);
00300         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[10].Vertex[2].x);
00301 
00302         glTexCoord2f(0.0f, 0.0f); glVertex3fv(&polygon[11].Vertex[0].x);
00303         glTexCoord2f(1.0f, 1.0f); glVertex3fv(&polygon[11].Vertex[1].x);
00304         glTexCoord2f(0.0f, 1.0f); glVertex3fv(&polygon[11].Vertex[2].x);
00305     glEnd();
00306         glPopMatrix();
00307 }

void DrawGrid  
 

Definition at line 216 of file general.cpp.

Referenced by DrawGLScene().

00217 {
00218     glDisable(GL_TEXTURE_2D);
00219     glDisable(GL_LIGHTING);
00220     glPushMatrix();
00221     glTranslatef(0,-2.0,0);
00222     float Line = -10;
00223     int Grid;
00224     glBegin(GL_LINES);
00225     for(Grid = 0; Grid <= 20; Grid += 1)
00226     {
00227         glColor3f(0.0f,1.0f,0.0f);
00228         glVertex3f(Line + Grid, 0, -10);
00229         glVertex3f(Line + Grid, 0, 10);
00230         glVertex3f(-10, 0, Line + Grid);
00231         glVertex3f(10, 0, Line + Grid);
00232     }
00233     glEnd();
00234     glPopMatrix();
00235     glEnable(GL_TEXTURE_2D);
00236     glEnable(GL_LIGHTING);
00237 }

void DrawSphere  
 

Definition at line 309 of file general.cpp.

Referenced by DrawGLScene().

00310 {
00311     float mat_ambient[] = { 0.8, 0.5, 0.1, 1.0 };
00312     float mat_diffuse[] = { 0.8, 0.5, 0.1, 1.0 };
00313     glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
00314     glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
00315 
00316     glDisable(GL_TEXTURE_2D);
00317     glPushMatrix();
00318     glTranslatef(-3.0f,-1.0f,-8.0f);
00319     GLUquadricObj * sphere = gluNewQuadric();
00320     gluQuadricOrientation(sphere, GLU_OUTSIDE);
00321     gluSphere(sphere,1.0,50,50);
00322     glPopMatrix();
00323     glEnable(GL_TEXTURE_2D);
00324 }

float GetTimePassed float &   ,
int   ,
float *   
 

Definition at line 346 of file general.cpp.

References average, fps, lastmultiplier, lasttime, and multiplier.

Referenced by WinMain().

00347 {
00348     float timeoffset;
00349     float currenttime;
00350 /*
00351 If the program has just started, set last tickcount to the current tickcount.
00352 This prevents the program from thinking that several hours have passed since the last frame.
00353 */
00354     if (lasttime == 0)
00355         lasttime = (float)GetTickCount();
00356         // Get the current time
00357     currenttime = (float)GetTickCount();
00358         // Calculate the offset
00359     timeoffset = currenttime - lasttime;
00360     // If timeoffset less than 1/120 of a second (in milliseconds) then set to minimum offset
00361     if (timeoffset < 8.333333)
00362     {
00363         timeoffset = 8.333333;
00364         currenttime = lasttime + timeoffset;
00365     }
00366     // Put the current time in the lasttime variable
00367         lasttime = currenttime;
00368     // return the time offset in seconds per frame
00369         multiplier = timeoffset / 1000;
00370     for (int loop = 0; loop < average - 1; loop++)
00371     {
00372         lastmultiplier[loop] = lastmultiplier[loop + 1];
00373     }
00374     lastmultiplier[average - 1] = multiplier;
00375     for (int loop = 0; loop < average - 1; loop++)
00376         multiplier += lastmultiplier[loop];
00377     multiplier /= (float)average; 
00378         if (multiplier)
00379         fps = (int)(1.0 / multiplier);
00380     return multiplier;
00381 }

void SetGLCamera CAMERA  
 

Definition at line 12 of file general.cpp.

References camera, numCameras, and CAMERA::Reset().

Referenced by InitGL().

00013 {
00014     int temp;
00015     for(temp = 0; temp < numCameras; temp++)
00016         camera[temp].Reset();
00017 }

void SetGLLighting  
 

Definition at line 200 of file general.cpp.

Referenced by DrawGLScene(), and InitGL().

00201 {
00202     float light_ambient[] = {0.2, 0.2, 0.2, 1.0};
00203     glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
00204     float light_position[] = {-3.0, 2.0, 1.0, 1.0};
00205     glLightfv(GL_LIGHT0, GL_POSITION, light_position);
00206     glEnable(GL_LIGHTING);
00207     glEnable(GL_LIGHT0);
00208 }

void SetGLMaterial  
 

Definition at line 185 of file general.cpp.

Referenced by InitGL().

00186 {
00187     float mat_ambient[] = { 1.0, 1.0, 1.0, 1.0 };
00188     float mat_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
00189     float mat_specular[] = { 0.9, 0.9, 0.9, 1.0 };
00190     float mat_emission[] = { 0.0, 0.0, 0.0, 1.0 };
00191     float mat_shininess[] = { 80.0 };
00192 
00193     glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
00194     glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
00195     glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
00196     glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
00197     glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
00198 }

void SetGLProjection int    Width,
int    Height
 

Definition at line 168 of file general.cpp.

Referenced by SetGLView().

00169 {
00170     if (Height==0)
00171         Height=1;
00172     glViewport(0, 0, Width, Height);
00173     glMatrixMode(GL_PROJECTION);
00174     glLoadIdentity();
00175     gluPerspective(45.0,(float)Width/(float)Height,1.0,200.0);
00176 }

void SetGLProperties  
 

Definition at line 156 of file general.cpp.

Referenced by InitGL().

00157 {
00158     glCullFace(GL_BACK);
00159     glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
00160     glClearDepth(1.0);
00161     glDepthFunc(GL_LESS);
00162     glEnable(GL_DEPTH_TEST);
00163     glShadeModel(GL_SMOOTH);
00164     glEnable(GL_NORMALIZE);
00165     glEnable(GL_CULL_FACE);
00166 }

void SetGLTexture TEXTURE  
 

Definition at line 210 of file general.cpp.

References TEXTURE::LoadTGA(), and texture.

Referenced by InitGL().

00211 {
00212     sprintf(texture[0].TexName, "%s", "tile.tga");
00213     texture[0].LoadTGA();
00214 }

void SetGLView int    Width,
int    Height
 

Definition at line 178 of file general.cpp.

References SetGLProjection().

Referenced by InitGL(), and ReSizeGLScene().

00179 {
00180     SetGLProjection(Width, Height);
00181     glMatrixMode(GL_MODELVIEW);
00182     glLoadIdentity();
00183 }

void SetGLWorld POLYGON  
 

Definition at line 19 of file general.cpp.

References polygon, POLYGON::SetNormal(), POLYGON::Vertex, VERTEX::x, VERTEX::y, and VERTEX::z.

Referenced by InitGL().

00020 {
00021 //Front
00022     polygon[0].Vertex[0].x = -1.0;
00023     polygon[0].Vertex[0].y = -1.0;
00024     polygon[0].Vertex[0].z = 1.0;
00025     polygon[0].Vertex[1].x = 1.0;
00026     polygon[0].Vertex[1].y = -1.0;
00027     polygon[0].Vertex[1].z = 1.0;
00028     polygon[0].Vertex[2].x = 1.0;
00029     polygon[0].Vertex[2].y = 1.0;
00030     polygon[0].Vertex[2].z = 1.0;
00031 
00032     polygon[1].Vertex[0].x = -1.0;
00033     polygon[1].Vertex[0].y = -1.0;
00034     polygon[1].Vertex[0].z = 1.0;
00035     polygon[1].Vertex[1].x = 1.0;
00036     polygon[1].Vertex[1].y = 1.0;
00037     polygon[1].Vertex[1].z = 1.0;
00038     polygon[1].Vertex[2].x = -1.0;
00039     polygon[1].Vertex[2].y = 1.0;
00040     polygon[1].Vertex[2].z = 1.0;
00041 //Back
00042     polygon[2].Vertex[0].x = 1.0;
00043     polygon[2].Vertex[0].y = -1.0;
00044     polygon[2].Vertex[0].z = -1.0;
00045     polygon[2].Vertex[1].x = -1.0;
00046     polygon[2].Vertex[1].y = -1.0;
00047     polygon[2].Vertex[1].z = -1.0;
00048     polygon[2].Vertex[2].x = -1.0;
00049     polygon[2].Vertex[2].y = 1.0;
00050     polygon[2].Vertex[2].z = -1.0;
00051 
00052     polygon[3].Vertex[0].x = 1.0;
00053     polygon[3].Vertex[0].y = -1.0;
00054     polygon[3].Vertex[0].z = -1.0;
00055     polygon[3].Vertex[1].x = -1.0;
00056     polygon[3].Vertex[1].y = 1.0;
00057     polygon[3].Vertex[1].z = -1.0;
00058     polygon[3].Vertex[2].x = 1.0;
00059     polygon[3].Vertex[2].y = 1.0;
00060     polygon[3].Vertex[2].z = -1.0;
00061 //Left
00062     polygon[4].Vertex[0].x = -1.0;
00063     polygon[4].Vertex[0].y = -1.0;
00064     polygon[4].Vertex[0].z = -1.0;
00065     polygon[4].Vertex[1].x = -1.0;
00066     polygon[4].Vertex[1].y = -1.0;
00067     polygon[4].Vertex[1].z = 1.0;
00068     polygon[4].Vertex[2].x = -1.0;
00069     polygon[4].Vertex[2].y = 1.0;
00070     polygon[4].Vertex[2].z = 1.0;
00071 
00072     polygon[5].Vertex[0].x = -1.0;
00073     polygon[5].Vertex[0].y = -1.0;
00074     polygon[5].Vertex[0].z = -1.0;
00075     polygon[5].Vertex[1].x = -1.0;
00076     polygon[5].Vertex[1].y = 1.0;
00077     polygon[5].Vertex[1].z = 1.0;
00078     polygon[5].Vertex[2].x = -1.0;
00079     polygon[5].Vertex[2].y = 1.0;
00080     polygon[5].Vertex[2].z = -1.0;
00081 //Right
00082     polygon[6].Vertex[0].x = 1.0;
00083     polygon[6].Vertex[0].y = -1.0;
00084     polygon[6].Vertex[0].z = 1.0;
00085     polygon[6].Vertex[1].x = 1.0;
00086     polygon[6].Vertex[1].y = -1.0;
00087     polygon[6].Vertex[1].z = -1.0;
00088     polygon[6].Vertex[2].x = 1.0;
00089     polygon[6].Vertex[2].y = 1.0;
00090     polygon[6].Vertex[2].z = -1.0;
00091 
00092     polygon[7].Vertex[0].x = 1.0;
00093     polygon[7].Vertex[0].y = -1.0;
00094     polygon[7].Vertex[0].z = 1.0;
00095     polygon[7].Vertex[1].x = 1.0;
00096     polygon[7].Vertex[1].y = 1.0;
00097     polygon[7].Vertex[1].z = -1.0;
00098     polygon[7].Vertex[2].x = 1.0;
00099     polygon[7].Vertex[2].y = 1.0;
00100     polygon[7].Vertex[2].z = 1.0;
00101 //Top
00102     polygon[8].Vertex[0].x = 1.0;
00103     polygon[8].Vertex[0].y = 1.0;
00104     polygon[8].Vertex[0].z = 1.0;
00105     polygon[8].Vertex[1].x = 1.0;
00106     polygon[8].Vertex[1].y = 1.0;
00107     polygon[8].Vertex[1].z = -1.0;
00108     polygon[8].Vertex[2].x = -1.0;
00109     polygon[8].Vertex[2].y = 1.0;
00110     polygon[8].Vertex[2].z = -1.0;
00111 
00112     polygon[9].Vertex[0].x = 1.0;
00113     polygon[9].Vertex[0].y = 1.0;
00114     polygon[9].Vertex[0].z = 1.0;
00115     polygon[9].Vertex[1].x = -1.0;
00116     polygon[9].Vertex[1].y = 1.0;
00117     polygon[9].Vertex[1].z = -1.0;
00118     polygon[9].Vertex[2].x = -1.0;
00119     polygon[9].Vertex[2].y = 1.0;
00120     polygon[9].Vertex[2].z = 1.0;
00121 //Bottom
00122     polygon[10].Vertex[0].x = -1.0;
00123     polygon[10].Vertex[0].y = -1.0;
00124     polygon[10].Vertex[0].z = 1.0;
00125     polygon[10].Vertex[1].x = -1.0;
00126     polygon[10].Vertex[1].y = -1.0;
00127     polygon[10].Vertex[1].z = -1.0;
00128     polygon[10].Vertex[2].x = 1.0;
00129     polygon[10].Vertex[2].y = -1.0;
00130     polygon[10].Vertex[2].z = -1.0;
00131 
00132     polygon[11].Vertex[0].x = -1.0;
00133     polygon[11].Vertex[0].y = -1.0;
00134     polygon[11].Vertex[0].z = 1.0;
00135     polygon[11].Vertex[1].x = 1.0;
00136     polygon[11].Vertex[1].y = -1.0;
00137     polygon[11].Vertex[1].z = -1.0;
00138     polygon[11].Vertex[2].x = 1.0;
00139     polygon[11].Vertex[2].y = -1.0;
00140     polygon[11].Vertex[2].z = 1.0;
00141 
00142     polygon[0].SetNormal();
00143     polygon[1].SetNormal();
00144     polygon[2].SetNormal();
00145     polygon[3].SetNormal();
00146     polygon[4].SetNormal();
00147     polygon[5].SetNormal();
00148     polygon[6].SetNormal();
00149     polygon[7].SetNormal();
00150     polygon[8].SetNormal();
00151     polygon[9].SetNormal();
00152     polygon[10].SetNormal();
00153     polygon[11].SetNormal();
00154 }


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