00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <math.h>
00004 #include <ctype.h>
00005
00006 #ifdef WIN32
00007 #include <windows.h>
00008 const float M_PI = { 3.14159265f };
00009 #endif
00010
00011 #include "axes/axes.h"
00012 #include "arrows/arrows.h"
00013 #include "input/input.h"
00014 #include "playerControl/playerControl.h"
00015 #include "fog/fog.h"
00016 #include "windowControl/windowControl.h"
00017 #include "timer/timer.h"
00018 #include "stringDraw/stringDraw.h"
00019 #include "lighting/lighting.h"
00020 #include "opengl.h"
00021
00022
00023
00024 const char *WINDOWTITLE = { "Robin Hood and His Merry Men" };
00025 #define ESCAPE 0x1b
00026 const int INIT_WINDOW_SIZE = { 600 };
00027 const float SCLFACT = { 0.005f };
00028 const float MINSCALE = { 0.05f };
00029
00030
00031 const int LEFT = { 4 };
00032 const int MIDDLE = { 2 };
00033 const int RIGHT = { 1 };
00034
00035
00036
00037
00038 const float BACKCOLOR[] = { 0.2, 0.2, 1., 0. };
00039
00040
00041
00045 int ActiveButton;
00046 int Debug;
00047 int LeftButton;
00048 int MainWindow;
00049 float Scale;
00050
00051 int PointsOn;
00052 int LightOn;
00053 int AeroOn;
00054 int FontType;
00055
00056
00057
00058
00059 ArrowSystem arrows;
00060 Axes axes;
00061 PlayerControl player;
00062 WindowControl windowControl;
00063 Fog fog;
00064 Timer timer;
00065 Lighting lighting;
00066
00067
00068
00069 int fpsCounter = 0;
00070 char fpsMessage[50];
00071
00072
00076 void Display( void );
00077 void DoRasterString( float, float, float, char * );
00078 void DoStrokeString( float, float, float, float, char * );
00079 void InitGraphics( void );
00080
00081
00082 void Reset( void );
00083 void Resize( int, int );
00084 void Visibility( int );
00085
00086
00087
00088
00092 int
00093 main( int argc, char *argv[] )
00094 {
00095
00096
00097 glutInit( &argc, argv );
00098
00099 InitGraphics();
00100 srand(12);
00101
00102
00103 Reset();
00104
00105 glutMainLoop();
00106
00107
00108 return 0;
00109 }
00110
00111
00112 void
00113 MouseMotion(int x, int y)
00114 {
00115 player.MouseMotion(x,y);
00116 }
00117
00118
00119
00123 void
00124 Display( void )
00125 {
00126
00127
00128
00129 glutSetWindow( MainWindow );
00130
00131
00132
00133
00134 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
00135 glEnable( GL_DEPTH_TEST );
00136
00137
00138
00139
00140
00141
00142
00143
00144 glMatrixMode( GL_PROJECTION );
00145 glLoadIdentity();
00146 gluPerspective( 90., 1., 0.1, 1000. );
00147
00148
00149 glMatrixMode( GL_MODELVIEW );
00150 glLoadIdentity();
00151 float Yrot, Xrot, PosX, PosY, PosZ;
00152 Yrot = player.GetYrot();
00153 Xrot = player.GetXrot();
00154 PosX = player.GetPosX();
00155 PosY = player.GetPosY();
00156 PosZ = player.GetPosZ();
00157 gluLookAt( PosX+2*sin((-Yrot-5)*(M_PI/180.0)), PosY+1.0, PosZ+2*cos((-Yrot-5)*(M_PI/180.0) ), PosX, PosY+1.0-Xrot/15.0, PosZ, 0., 1., 0. );
00158
00159
00160
00161
00162 fog.Enable();
00163 axes.Draw();
00164
00165
00166 glPointSize(2);
00167 glLineWidth(2);
00168
00169 lighting.Enable();
00170
00171
00172 glEnable(GL_NORMALIZE);
00173 glShadeModel(GL_SMOOTH);
00174
00175
00176
00177 glPushMatrix();
00178 glTranslatef(PosX, PosY, PosZ);
00179 glRotatef( -Yrot, 0., 1., 0. );
00180 glColor3f( 1.0, 1.0, 1.0);
00181 glutSolidCube(1.0);
00182 glPopMatrix();
00183
00184
00185 glPushMatrix();
00186 glTranslatef(20.0f, 30.0, 20.0f);
00187 glScalef(1.0, 30.0, 1.0);
00188 glColor3f(0.56f,0.27f,.07f);
00189 glutSolidCube(4.0);
00190 glPopMatrix();
00191
00192
00193 glPushMatrix();
00194 glTranslatef(0.0f, 0.0, 21.0f);
00195 glColor3f(0.56f,0.27f,1.0f);
00196 glutSolidSphere(4.0,15,15);
00197 glPopMatrix();
00198
00199 if (1.0/(timer.GetTimeChange()) < 30)
00200 {
00201 timer.Update();
00202 return;
00203 }
00204
00205 if(true)
00206 {
00207 glNormal3f( 0.0, 1.0, 0.0);
00208 glColor3f( 0.0, 1.0, 0.0);
00209 glBegin(GL_QUADS);
00210 glVertex3f(-200.0f, -10.1f, -200.0f);
00211 glVertex3f(-200.0f, -10.1f, 200.0f);
00212 glVertex3f(200.0f, -10.1f, 200.0f);
00213 glVertex3f(200.0f, -10.1f, -200.0f);
00214 glEnd();
00215 }
00216
00217
00218
00219 lighting.Disable();
00220
00221 arrows.Update(timer.GetTimeChange());
00222 arrows.Draw();
00223 arrows.stickySphere(Vector3(0.0,0.0,21.0),4);
00224 arrows.stickyCylinder(Vector3(20.0f,0.0f,20.0f), 2.0f, 60.1f, -10.1f);
00225
00226 fog.Disable();
00227 player.DrawTarget();
00228
00229 fpsCounter++;
00230 if (fpsCounter >= 9) {
00231 fpsCounter = 0;
00232 sprintf(fpsMessage, "fps: %f", 1.0/(timer.GetTimeChange()) );
00233 }
00234
00235 timer.Update();
00236
00237 draw2dString(5.0f, 5.0f, fpsMessage);
00238
00239
00240 glutSwapBuffers();
00241
00242
00243 glFlush();
00244 }
00245
00246 void
00247 Animate( void )
00248 {
00249
00250 player.HandleInput(timer.GetTimeChange());
00251 windowControl.Update();
00252 glutSetWindow( MainWindow );
00253 glutPostRedisplay();
00254 }
00255
00256
00257 void
00258 ToggleArrowStorm(void)
00259 {
00260 static bool doShower = false;
00261 doShower = !doShower;
00262 arrows.DoArrowShower(doShower);
00263
00264 }
00265
00266
00271 void
00272 InitGraphics( void )
00273 {
00274 if( Debug )
00275
00276
00277
00278
00279
00280
00281
00282 glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH );
00283
00284
00285
00286 glutInitWindowSize( INIT_WINDOW_SIZE, INIT_WINDOW_SIZE );
00287
00288
00289
00290 MainWindow = glutCreateWindow( WINDOWTITLE );
00291 glutSetWindowTitle( WINDOWTITLE );
00292
00293
00294
00295 glClearColor( BACKCOLOR[0], BACKCOLOR[1], BACKCOLOR[2], BACKCOLOR[3] );
00296
00297
00298 arrows.Init(700, 1.0f, -10.0);
00299 axes.Init(5.0f);
00300 fog.Init();
00301 windowControl.Init();
00302 player.Init(0.0f,0.0f,30.0f,&arrows);
00303 InputSetMouseMotion(MouseMotion);
00304 lighting.Init();
00305 timer.Init();
00306
00307 InputSetKeyDown('t', ToggleArrowStorm);
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337 glutKeyboardFunc( InputSystemKeyDown );
00338 glutKeyboardUpFunc ( InputSystemKeyUp );
00339 glutMouseFunc( InputSystemMouseButton );
00340 glutPassiveMotionFunc( InputSystemMouseMotion );
00341 glutMotionFunc( InputSystemMouseMotion );
00342
00343 glutSetWindow( MainWindow );
00344 glutDisplayFunc( Display );
00345 glutReshapeFunc( Resize );
00346
00347 glutVisibilityFunc( Visibility );
00348 glutEntryFunc( NULL );
00349
00350 glutSpaceballMotionFunc( NULL );
00351 glutSpaceballRotateFunc( NULL );
00352 glutSpaceballButtonFunc( NULL );
00353 glutButtonBoxFunc( NULL );
00354 glutDialsFunc( NULL );
00355 glutTabletMotionFunc( NULL );
00356 glutTabletButtonFunc( NULL );
00357 glutMenuStateFunc( NULL );
00358 glutIdleFunc( Animate );
00359
00360 glutTimerFunc( 0, NULL, 0 );
00361 }
00362
00363
00364
00365 void
00366 Reset( void )
00367 {
00368
00369 Debug = false;
00370 LightOn = true;
00371 printf("Reset called\n");
00372 glutSetWindow( MainWindow );
00373 glutPostRedisplay();
00374 }
00375
00376
00377
00382 void
00383 Resize( int width, int height )
00384 {
00385 if( Debug )
00386 fprintf( stderr, "ReSize: %d, %d\n", width, height );
00387
00388
00389
00390
00391 float vx, vy, v;
00392
00393
00394 vx = glutGet( GLUT_WINDOW_WIDTH );
00395 vy = glutGet( GLUT_WINDOW_HEIGHT );
00396 v = vx < vy ? vx : vy;
00397
00398
00399 glViewport( 0,0,vx,vy);
00400
00401
00402
00403
00404
00405
00406
00407 glutSetWindow( MainWindow );
00408 glutPostRedisplay();
00409 }
00410
00411
00412
00413
00418 void
00419 Visibility(int state)
00420 {
00421 if( Debug )
00422 fprintf( stderr, "Visibility: %d\n", state );
00423
00424 if( state == GLUT_VISIBLE )
00425 {
00426 glutSetWindow( MainWindow );
00427 glutPostRedisplay();
00428 }
00429 else
00430 {
00431
00432
00433
00434 }
00435 }
00436
00437
00438