Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/ODE/src/world_entities/space_ships/hover.cc @ 10355

Last change on this file since 10355 was 10355, checked in by bottac, 17 years ago

Here comes the updated version.

File size: 22.6 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14
15*/
16
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
18
19#include "hover.h"
20
21#include "weapons/weapon_manager.h"
22#include "weapons/test_gun.h"
23#include "weapons/turret.h"
24#include "weapons/cannon.h"
25
26#include "util/loading/factory.h"
27//#include "util/loading/resource_manager.h"
28
29#include "key_mapper.h"
30#include "state.h"
31
32#include "graphics_engine.h"
33
34#include "debug.h"
35#include "bsp_entity.h"
36#include "terrain.h"
37#include "state.h"
38#include "camera.h"
39
40
41ObjectListDefinition(Hover);
42CREATE_FACTORY(Hover);
43
44#include "script_class.h"
45CREATE_SCRIPTABLE_CLASS(Hover,
46                        addMethod("hasPlayer", Executor0ret<Playable, lua_State*,bool>(&Playable::hasPlayer))
47                        //Coordinates
48                            ->addMethod("setAbsCoor", Executor3<PNode, lua_State*,float,float,float>(&PNode::setAbsCoor))
49                            ->addMethod("getAbsCoorX", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorX))
50                            ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY))
51                            ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorZ))
52                       );
53
54/**
55 *  destructs the hover, deletes alocated memory
56 */
57Hover::~Hover ()
58{
59  this->setPlayer(NULL);
60
61  //if (this->hoverBuffer != NULL)
62  //  ResourceManager::getInstance()->unload(this->hoverBuffer);
63}
64
65/**
66 * loads a Hover information from a specified file.
67 * @param fileName the name of the File to load the hover from (absolute path)
68 */
69Hover::Hover(const std::string& fileName)
70{
71  this->init();
72  TiXmlDocument doc(fileName);
73
74  if(!doc.LoadFile())
75  {
76    PRINTF(2)("Loading file %s failed for Hover.\n", fileName.c_str());
77    return;
78  }
79
80  this->loadParams(doc.RootElement());
81
82  //load sound
83  //if (this->hoverBuffer != NULL)
84  //  ResourceManager::getInstance()->unload(this->hoverBuffer);
85  //this->hoverBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/engine/hover.wav", WAV);
86
87}
88
89/**
90 *  creates a new Spaceship from Xml Data
91 * @param root the xml element containing spaceship data
92
93   @todo add more parameters to load
94*/
95Hover::Hover(const TiXmlElement* root)
96{
97  this->init();
98  if (root != NULL)
99    this->loadParams(root);
100
101  //weapons:
102  Weapon* wpRight = new TestGun(0);
103  wpRight->setName("testGun Right");
104  Weapon* wpLeft = new TestGun(1);
105  wpLeft->setName("testGun Left");
106  Weapon* cannon = dynamic_cast<Weapon*>(Factory::fabricate("Hyperblaster"));
107
108  cannon->setName("BFG");
109
110  this->addWeapon(wpLeft, 1, 0);
111  this->addWeapon(wpRight,1 ,1);
112  this->addWeapon(cannon, 0, 2);
113
114  this->getWeaponManager().changeWeaponConfig(1);
115  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false);
116
117  this->loadModel("models/ships/hoverglider_mainbody.obj");
118}
119
120
121/**
122 * initializes a Hover
123 */
124void Hover::init()
125{
126
127  //this->hitEntity = NULL;
128  //this->hoverBuffer = NULL;
129
130  //  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
131  this->registerObject(this, Hover::_objectList);
132  this->toReflectionList();
133
134  this->loadModel("models/ships/hoverglider_wing.obj", 1.0f, 3);
135  this->loadModel("models/ships/hoverglider_rotor.obj", 1.0f, 4);
136  this->loadModel("models/ships/rotor.obj", .45f, 5);
137
138  bForward = bBackward = bLeft = bRight = bAscend = bDescend = false;
139  mouseSensitivity = 0.005;
140
141  this->rotorSpeed = 1000.0f;
142  this->rotorCycle = 0.0f;
143  this->cameraLook = 0.0f;
144  this->rotation = 0.0f;
145  this->acceleration = 15.0f;
146  this->airFriction = 3.0f;
147
148  // camera - issue
149  this->cameraNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
150  this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE);
151  //this->cameraNode.setParentMode(PNODE_ROTATE_MOVEMENT);
152  this->cameraNode.setParent(this);
153
154  // rotors
155  this->wingNodeLeft.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT );
156  this->wingNodeLeft.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE);
157  this->wingNodeLeft.setParent(this);
158  this->wingNodeLeft.setRelCoor(-1.5, -.3, -1.0);
159  this->rotorNodeLeft.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
160  this->rotorNodeLeft.setParent(&this->wingNodeLeft);
161  this->rotorNodeLeft.setRelCoor(0, 1.0, -2.3);
162
163  this->wingNodeRight.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
164  this->wingNodeRight.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE);
165  this->wingNodeRight.setParent(this);
166  this->wingNodeRight.setRelCoor(-1.5, -0.3, 1.0);
167  this->rotorNodeRight.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
168  this->rotorNodeRight.setParent(&this->wingNodeRight);
169  this->rotorNodeRight.setRelCoor(0, 1.0, 2.3);
170
171  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false);
172
173
174  //add events to the eventlist
175  registerEvent(KeyMapper::PEV_FORWARD);
176  registerEvent(KeyMapper::PEV_BACKWARD);
177  registerEvent(KeyMapper::PEV_LEFT);
178  registerEvent(KeyMapper::PEV_RIGHT);
179  registerEvent(KeyMapper::PEV_UP);
180  registerEvent(KeyMapper::PEV_DOWN);
181  registerEvent(KeyMapper::PEV_FIRE1);
182  registerEvent(KeyMapper::PEV_NEXT_WEAPON);
183  registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON);
184  registerEvent(EV_MOUSE_MOTION);
185
186
187  // WEAPON_MANAGER configuration
188  this->getWeaponManager().setSlotCount(5);
189
190  this->getWeaponManager().setSlotPosition(0, Vector(-0.28, 1.186, -2.750), &this->wingNodeLeft);
191  this->getWeaponManager().setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
192
193  this->getWeaponManager().setSlotPosition(1, Vector(-0.28, 1.186, 2.750), &this->wingNodeRight);
194  this->getWeaponManager().setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
195
196  this->getWeaponManager().setSlotPosition(2, Vector(-1.63, .809, -.003));
197  this->getWeaponManager().setSlotCapability(2, WTYPE_HEAVY);
198
199  /// TODO: THESE ARE TOO MUCH
200  this->getWeaponManager().setSlotPosition(3, Vector(-1.63, .678, -.652));
201  this->getWeaponManager().setSlotDirection(3, Quaternion(-24/180 * M_PI, Vector(1,0,0)));
202
203  this->getWeaponManager().setSlotPosition(4, Vector(-1.63, .678, .652));
204  this->getWeaponManager().setSlotDirection(4, Quaternion(24/180 * M_PI, Vector(1,0,0)));
205
206  this->cameraNode.setRelCoor(1,5,0);
207  this->getWeaponManager().getFixedTarget()->setParent(&this->cameraNode);
208  this->getWeaponManager().getFixedTarget()->setRelCoor(1000,0,0);
209
210  // NETWORK THINGS
211
212  registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) );
213  registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) );
214  registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) );
215  registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) );
216  registerVar( new SynchronizeableBool( &bAscend, &bAscend, "bAscend", PERMISSION_OWNER ) );
217  registerVar( new SynchronizeableBool( &bDescend, &bDescend, "bDescend", PERMISSION_OWNER ) );
218
219  registerVar( new SynchronizeableFloat( &rotation, &rotation, "rotation", PERMISSION_OWNER ) );
220
221 //this->subscribeReaction(CoRe::CREngine::CR_PHYSICS_FULL_WALK, BspEntity::staticClassID());
222 this->subscribeReaction(CoRe::CREngine::CR_PHYSICS_FULL_WALK, WorldEntity::staticClassID());
223}
224
225/**
226 * loads the Settings of a Hover from an XML-element.
227 * @param root the XML-element to load the Spaceship's properties from
228 */
229void Hover::loadParams(const TiXmlElement* root)
230{
231  WorldEntity::loadParams(root);
232}
233
234
235void Hover::enter()
236{
237  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true);
238
239  State::getCameraNode()->setParentSoft(&this->cameraNode);
240  State::getCameraNode()->setRelCoorSoft(-10, 0,0);
241  State::getCameraTargetNode()->setParentSoft(&this->cameraNode);
242
243  //this->soundSource.play(this->hoverBuffer, 0.3f, true);
244
245}
246
247void Hover::leave()
248{
249  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false);
250  this->detachCamera();
251
252}
253
254
255/**
256 *  effect that occurs after the Hover is spawned
257*/
258void Hover::postSpawn ()
259{
260  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
261}
262
263/**
264 *  the action occuring if the hover left the game
265*/
266void Hover::leftWorld ()
267{}
268
269/**
270 *  this function is called, when two entities collide
271 * @param entity: the world entity with whom it collides
272 *
273 * Implement behaviour like damage application or other miscellaneous collision stuff in this function
274 */
275void Hover::collidesWith(WorldEntity* entity, const Vector& location)
276{
277  Playable::collidesWith(entity, location);
278}
279
280
281
282/**
283 *  the function called for each passing timeSnap
284 * @param time The timespan passed since last update
285*/
286void Hover::tick (float dt)
287{
288  Playable::tick(dt);
289
290  // spaceship controlled movement
291  this->movement(dt);
292  this->rotorCycle += this->rotorSpeed * dt;
293}
294
295/**
296 *  calculate the velocity
297 * @param time the timeslice since the last frame
298*/
299void Hover::movement (float dt)
300{
301  Vector accel(0.0, 0.0, 0.0);
302
303  if( this->bForward )
304  {
305    accel += Vector(this->acceleration, 0, 0);
306  }
307
308  if( this->bBackward )
309  {
310    accel -= Vector(this->acceleration, 0, 0);
311  }
312  if( this->bLeft)
313  {
314    accel -= Vector(0, 0, this->acceleration);
315  }
316
317  if( this->bRight)
318  {
319    accel += Vector(0, 0, this->acceleration);
320  }
321
322  if (this->bAscend )
323  {
324    accel += Vector(0, this->acceleration, 0);
325  }
326  if (this->bDescend )
327  {
328    accel -= Vector(0, this->acceleration, 0);
329  }
330
331  Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration);
332
333  // this is the air friction (necessary for a smooth control)
334  Vector damping = (this->velocity * this->airFriction);
335
336
337  this->velocity += (accelerationDir - damping)* dt;
338
339  this->shiftCoor (this->velocity * dt);
340
341  // limit the maximum rotation speed.
342  if (this->rotation != 0.0f)
343  {
344    float maxRot = 10.0 * dt;
345    if (unlikely(this->rotation > maxRot)) this->rotation = maxRot;
346    if (unlikely(this->rotation < -maxRot)) this->rotation = -maxRot;
347    this->direction *= Quaternion(-M_PI/4.0*this->rotation, Vector(0,1,0));
348    this->rotation = 0.0f;
349  }
350
351  this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5);
352
353  this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z * .03 +this->rotation, Vector(1,0,0)), 5);
354  this->rotorNodeLeft.setRelDirSoft(Quaternion(-accel.x * .05+this->rotation + cameraLook, Vector(0,0,1)), 5);
355
356  this->wingNodeRight.setRelDirSoft(Quaternion(accel.z * .03 +this->rotation, Vector(1,0,0)), 5);
357  this->rotorNodeRight.setRelDirSoft(Quaternion(-accel.x*.05 -this->rotation + cameraLook, Vector(0,0,1)), 5);
358}
359
360
361void Hover::draw() const
362{ 
363  Vector tmpRot;
364  WorldEntity::draw();
365
366  glPushMatrix();
367  /// LEFT SIDE
368  glTranslatef (this->wingNodeLeft.getAbsCoor ().x,
369                this->wingNodeLeft.getAbsCoor ().y,
370                this->wingNodeLeft.getAbsCoor ().z);
371  tmpRot = this->wingNodeLeft.getAbsDir().getSpacialAxis();
372  glRotatef (this->wingNodeLeft.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
373  this->getModel(3)->draw();
374  glPopMatrix ();
375
376  glPushMatrix();
377  glTranslatef (this->rotorNodeLeft.getAbsCoor ().x,
378                this->rotorNodeLeft.getAbsCoor ().y,
379                this->rotorNodeLeft.getAbsCoor ().z);
380  tmpRot = this->rotorNodeLeft.getAbsDir().getSpacialAxis();
381  glRotatef (this->rotorNodeLeft.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
382  this->getModel(4)->draw();
383  glTranslatef(0,-1,0);
384  glRotatef(this->rotorCycle, 0,1,0);
385  this->getModel(5)->draw();
386  glPopMatrix ();
387
388  /// RIGHT SIDE
389  glPushMatrix();
390  glTranslatef (this->wingNodeRight.getAbsCoor ().x,
391                this->wingNodeRight.getAbsCoor ().y,
392                this->wingNodeRight.getAbsCoor ().z);
393  tmpRot = this->wingNodeRight.getAbsDir().getSpacialAxis();
394  glRotatef (this->wingNodeRight.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
395  glScalef(1,1,-1);
396  this->getModel(3)->draw();
397  glPopMatrix ();
398
399  glPushMatrix();
400  glTranslatef (this->rotorNodeRight.getAbsCoor ().x,
401                this->rotorNodeRight.getAbsCoor ().y,
402                this->rotorNodeRight.getAbsCoor ().z);
403  tmpRot = this->rotorNodeRight.getAbsDir().getSpacialAxis();
404  glRotatef (this->rotorNodeRight.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
405  glScalef(1,1,-1);
406  this->getModel(4)->draw();
407  glTranslatef(0,-1,0);
408  glRotatef(this->rotorCycle, 0,1,0);
409  this->getModel(5)->draw();
410
411  glPopMatrix ();
412
413 glPushMatrix(); 
414 glTranslatef (this->getAbsCoor ().x,
415                  this->getAbsCoor ().y-2.0,
416                  this->getAbsCoor ().z);
417
418/* glBegin(GL_QUADS);
419        glColor4f(0.9,0.9,0.2,0.33);   
420        glNormal3f( 0.0f, 1.0f, 0.0f);                                  // Normal Pointing Up
421                glTexCoord2f(0.0f, 1.0f); glVertex3f(-10.0f, - 2.0f, -1.00f);   // Point 1 (Top)
422                glTexCoord2f(0.0f, 0.0f); glVertex3f(-10.0f,  -2.0f,  10.0f);   // Point 2 (Top)
423                glTexCoord2f(1.0f, 0.0f); glVertex3f( 10.0f,  -2.0f,  10.0f);   // Point 3 (Top)
424                glTexCoord2f(1.0f, 1.0f); glVertex3f( 10.0f,  -2.0f, -10.0f);   // Point 4 (Top)
425glEnd(); */
426
427//this->getModel(0)->draw();
428 // glMatrixMode(GL_MODELVIEW);
429       
430  //  Vector tmpRot = this->getAbsDir().getSpacialAxis();
431   // glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
432
433        Vector a = Vector(0.0,0.0,-10.0);
434
435 
436        //      drawDebugCube( &a);
437   // Experiment
438       
439
440       
441        glPushAttrib( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT | GL_STENCIL_BUFFER_BIT );
442        glDepthMask(GL_FALSE);
443//glClear( GL_STENCIL_BUFFER_BIT);
444        glDisable(GL_TEXTURE_2D);
445        glActiveTextureARB(GL_TEXTURE0_ARB);
446        glDisable(GL_TEXTURE_2D);
447// drawDebugCube( &a);
448       
449
450                //glEnable(GL_CULL_FACE);
451                glEnable(GL_STENCIL_TEST);
452                //glEnable(GL_POLYGON_OFFSET_FILL);
453                //glPolygonOffset(0.0f, 100.0f);
454        //drawDebugCube( &a);
455
456
457
458        glDisable( GL_LIGHTING );                                       // Turn Off Lighting
459        glDepthMask( GL_FALSE );                                        // Turn Off Writing To The Depth-Buffer
460        //glDepthFunc( GL_LEQUAL );
461        glEnable( GL_STENCIL_TEST );                                    // Turn On Stencil Buffer Testing
462        //glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );                // Don't Draw Into The Colour Buffer
463        //glStencilFunc( GL_ALWAYS, 1, 0xFFFFFFFFL );
464
465
466        glColorMask(0, 0, 0, 0);
467        glStencilFunc(GL_ALWAYS, 1, 0xffffffff);
468
469        // First Pass. Increase Stencil Value In The Shadow
470       
471        glFrontFace( GL_CCW );
472        glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
473        //doShadowPass( object, lightPosition );
474        //drawDebugCube(&(State::getCamera()->getAbsCoor()  + State::getCamera()->getAbsDirV()*3.0f) );
475        drawDebugCube( &a);
476        this->getModel(0)->draw();
477        //WorldEntity::draw();
478       
479        // Second Pass. Decrease Stencil Value In The Shadow
480        glFrontFace( GL_CW );
481        glStencilOp( GL_KEEP, GL_KEEP, GL_DECR );
482        //doShadowPass( object, lightPosition );
483        //drawDebugCube(&(State::getCamera()->getAbsCoor() ) );
484        drawDebugCube( &a);
485        this->getModel(0)->draw();
486        //WorldEntity::draw();
487       
488        glFrontFace( GL_CCW );
489
490        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
491                glDepthMask(GL_TRUE);
492
493
494                glColor4f( 0.0f, 0.9f, 0.0f, 0.4f );
495        glDisable(GL_POLYGON_OFFSET_FILL);
496        glDisable(GL_DEPTH_TEST); 
497                glDisable(GL_CULL_FACE);
498        //glEnable( GL_BLEND );
499        //glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
500        //glStencilFunc( GL_NOTEQUAL, 0, 0xffffffff );
501        //glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
502        ////glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
503       
504        glPushMatrix();
505        glLoadIdentity();
506        glBegin( GL_TRIANGLE_STRIP );
507                glVertex3f( -1.1f,  1.1f, -5.5f );
508                glVertex3f( -1.1f, -1.1f, -5.5f );
509                glVertex3f(  1.1f,  1.1f, -5.5f );
510                glVertex3f(  1.1f, -1.1f, -5.5f );
511        glEnd();
512         glPopMatrix ();
513       
514        /*
515        glPushMatrix();
516        glLoadIdentity();
517        glMatrixMode(GL_PROJECTION);
518        glPushMatrix();
519        glLoadIdentity();
520        glOrtho(0, 1, 1, 0, 0, 1);
521       
522
523        glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
524        glBegin(GL_QUADS);
525                glVertex2i(0, 0);
526                glVertex2i(0, 1);
527                glVertex2i(1, 1);
528                glVertex2i(1, 0);
529        glEnd();
530
531        glEnable(GL_DEPTH_TEST);
532
533        glPopMatrix();
534        glMatrixMode(GL_MODELVIEW);
535        */
536   
537 glPopAttrib();
538glPopMatrix ();
539}
540
541/**
542 * @todo switch statement ??
543 */
544void Hover::process(const Event &event)
545{
546  Playable::process(event);
547
548  if( event.type == KeyMapper::PEV_LEFT)
549    this->bLeft = event.bPressed;
550  else if( event.type == KeyMapper::PEV_RIGHT)
551    this->bRight = event.bPressed;
552  else if( event.type == KeyMapper::PEV_UP)
553    this->bAscend = event.bPressed; //this->shiftCoor(0,.1,0);
554  else if( event.type == KeyMapper::PEV_DOWN)
555    this->bDescend = event.bPressed; //this->shiftCoor(0,-.1,0);
556  else if( event.type == KeyMapper::PEV_FORWARD)
557    this->bForward = event.bPressed; //this->shiftCoor(0,.1,0);
558  else if( event.type == KeyMapper::PEV_BACKWARD)
559    this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0);
560  else if( event.type == EV_MOUSE_MOTION)
561  {
562    float xMouse, yMouse;
563    xMouse = event.xRel*mouseSensitivity;
564    yMouse = event.yRel*mouseSensitivity;
565
566    // rotate the Player around the y-axis
567    this->rotation += xMouse;
568
569    this->cameraLook += yMouse;
570    // rotate the Camera around the z-axis
571    if (cameraLook > M_PI_4)
572      cameraLook = M_PI_4;
573    else if (cameraLook < -M_PI_4)
574      cameraLook = -M_PI_4;
575    //this->cameraNode.setRelDirSoft(this->direction,10);
576  }
577}
578
579 void drawDebugCube(const Vector* cam)
580{
581glBegin(GL_QUADS);
582 // Front Face
583                glNormal3f( 0.0f, 0.0f, 1.0f);                                  // Normal Pointing Towards Viewer
584                glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -10.0f,  1.0f);     // Point 1 (Front)
585                glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -10.0f,  1.0f);     // Point 2 (Front)
586                glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  10.0f,  1.0f);     // Point 3 (Front)
587                glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  10.0f,  1.0f);     // Point 4 (Front)
588                // Back Face
589                glNormal3f( 0.0f, 0.0f,-1.0f);                                  // Normal Pointing Away From Viewer
590                glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -10.0f, -1.0f);     // Point 1 (Back)
591                glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  10.0f, -1.0f);     // Point 2 (Back)
592                glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  10.0f, -1.0f);     // Point 3 (Back)
593                glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -10.0f, -1.0f);     // Point 4 (Back)
594                // Top Face
595                glNormal3f( 0.0f, 1.0f, 0.0f);                                  // Normal Pointing Up
596                glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  10.0f, -1.0f);     // Point 1 (Top)
597                glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  10.0f,  1.0f);     // Point 2 (Top)
598                glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  10.0f,  1.0f);     // Point 3 (Top)
599                glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  10.0f, -1.0f);     // Point 4 (Top)
600                // Bottom Face
601                glNormal3f( 0.0f,-1.0f, 0.0f);                                  // Normal Pointing Down
602                glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -10.0f, -1.0f);     // Point 1 (Bottom)
603                glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -10.0f, -1.0f);     // Point 2 (Bottom)
604                glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -10.0f,  1.0f);     // Point 3 (Bottom)
605                glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -10.0f,  1.0f);     // Point 4 (Bottom)
606                // Right face
607                glNormal3f( 1.0f, 0.0f, 0.0f);                                  // Normal Pointing Right
608                glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -10.0f, -1.0f);     // Point 1 (Right)
609                glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  10.0f, -1.0f);     // Point 2 (Right)
610                glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  10.0f,  1.0f);     // Point 3 (Right)
611                glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -10.0f,  1.0f);     // Point 4 (Right)
612                // Left Face
613                glNormal3f(-1.0f, 0.0f, 0.0f);                                  // Normal Pointing Left
614                glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -10.0f, -1.0f);     // Point 1 (Left)
615                glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -10.0f,  1.0f);     // Point 2 (Left)
616                glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  10.0f,  1.0f);     // Point 3 (Left)
617                glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  10.0f, -1.0f);     // Point 4 (Left)
618        glEnd();                                                                // Done Drawing Quads
619
620
621  glBegin(GL_QUADS);
622
623return;
624  // Bottom Face.  Red, 75% opaque, magnified texture
625
626  //glNormal3f( 0.0f, -1.0f, 0.0f); // Needed for lighting
627 // glColor4f(0.9,0.2,0.2,.75); // Basic polygon color
628
629  //glTexCoord2f(0.800f, 0.800f);
630glVertex3f(cam->x-5.0f, cam->y-100.0f,cam->z -5.0f);
631 // glTexCoord2f(0.200f, 0.800f);
632glVertex3f(cam->x+5.0f, cam->y-100.0f,cam->z -5.0f);
633  //glTexCoord2f(0.200f, 0.200f);
634glVertex3f(cam->x+ 5.0f,cam->y -100.0f,cam->z +  5.0f);
635  //glTexCoord2f(0.800f, 0.200f);
636glVertex3f(cam->x-5.0f, cam->y-100.0f, cam->z + 5.0f); //OK
637
638
639  // Top face; offset.  White, 50% opaque.
640
641 // glNormal3f( 0.0f, 5.0f, 0.0f);  glColor4f(0.5,0.5,0.5,.5);
642
643  //glTexCoord2f(0.005f, 5.995f);
644glVertex3f(cam->x-5.0f, cam->y+ 100.0f, cam->z -5.0f);
645  //glTexCoord2f(0.005f, 0.005f);
646glVertex3f(cam->x-5.0f, cam->y+ 100.0f,  cam->z +5.0f);
647  //glTexCoord2f(5.995f, 0.005f);
648glVertex3f(cam->x+ 5.0f,  cam->y+100.0f,  cam->z +5.0f);
649  //glTexCoord2f(5.995f, 5.995f);
650glVertex3f(cam->x+ 5.0f, cam->y+ 100.0f, cam->z -5.0f); //OKQUAD_STRI
651
652
653  // Far face.  Green, 50% opaque, non-uniform texture cooridinates.
654
655  //glNormal3f( 0.0f, 0.0f,-5.0f);  glColor4f(0.2,0.9,0.2,.5);
656
657 // glTexCoord2f(0.995f, 0.005f);
658glVertex3f(cam->x-5.0f, cam->y-100.0f, cam->z -5.0f);
659 // glTexCoord2f(2.995f, 2.995f);
660glVertex3f(cam->x-5.0f, cam->y+ 100.0f, cam->z -5.0f);
661 // glTexCoord2f(0.005f, 0.995f);
662glVertex3f(cam->x+ 5.0f,cam->y+  100.0f, cam->z -5.0f);
663  //glTexCoord2f(0.005f, 0.005f);
664glVertex3f( cam->x+5.0f,cam->y -100.0f, cam->z -5.0f);
665
666
667  // Right face.  Blue; 25% opaque
668
669 // glNormal3f( 5.0f, 0.0f, 0.0f);  glColor4f(0.2,0.2,0.9,.25);
670
671 // glTexCoord2f(0.995f, 0.005f);
672glVertex3f(cam->x+ 5.0f, cam->y -100.0f, cam->z -5.0f);
673 // glTexCoord2f(0.995f, 0.995f);
674glVertex3f(cam->x+ 5.0f, cam->y+ 100.0f, cam->z -5.0f);
675 // glTexCoord2f(0.005f, 0.995f);
676glVertex3f(cam->x+ 5.0f, cam->y+ 100.0f, cam->z + 5.0f);
677 // glTexCoord2f(0.005f, 0.005f);
678glVertex3f(cam->x+ 5.0f, cam->y-100.0f,  cam->z +5.0f);
679
680
681  // Front face; offset.  Multi-colored, 50% opaque.
682
683 // glNormal3f( 0.0f, 0.0f, 5.0f);
684
685//  glColor4f( 0.9f, 0.2f, 0.2f, 0.5f);
686//  glTexCoord2f( 0.005f, 0.005f);
687glVertex3f(cam->x-5.0f, cam->y-100.0f,  cam->z +5.0f);
688//  glColor4f( 0.2f, 0.9f, 0.2f, 0.5f);
689//  glTexCoord2f( 0.995f, 0.005f);
690glVertex3f(cam->x+ 5.0f, cam->y-100.0f,  cam->z +5.0f);
691 // glColor4f( 0.2f, 0.2f, 0.9f, 0.5f);
692//  glTexCoord2f( 0.995f, 0.995f);
693glVertex3f( cam->x+5.0f,  cam->y+100.0f,  cam->z +5.0f);
694//  glColor4f( 0.5f, 0.5f, 0.5f, 0.5f);
695//  glTexCoord2f( 0.005f, 0.995f); g
696glVertex3f(cam->x-5.0f, cam->y+ 100.0f,  cam->z +5.0f);
697
698
699  // Left Face; offset.  Yellow, varying levels of opaque.
700
701//  glNormal3f(-5.0f, 0.0f, 0.0f);
702
703//  glColor4f(0.9,0.9,0.2,0.0);
704 // glTexCoord2f(0.005f, 0.005f);
705glVertex3f(cam->x-5.0f, cam->y-100.0f, cam->z -5.0f);
706  //glColor4f(0.9,0.9,0.2,0.66);
707// glTexCoord2f(0.995f, 0.005f);
708glVertex3f(cam->x-5.0f,cam->y -100.0f,  cam->z +5.0f);
709//  glColor4f(0.9,0.9,0.2,5.0);
710//  glTexCoord2f(0.995f, 0.995f);
711glVertex3f(cam->x-5.0f, cam->y+ 100.0f,  cam->z +5.0f);
712//  glColor4f(0.9,0.9,0.2,0.33);
713//  glTexCoord2f(0.005f, 0.995f);
714glVertex3f(cam->x-5.0f, cam->y+ 100.0f, cam->z -5.0f);
715
716  glEnd();
717}
Note: See TracBrowser for help on using the repository browser.