Changeset 1899 in orxonox.OLD for orxonox/trunk
- Timestamp:
- May 20, 2004, 1:03:53 PM (21 years ago)
- Location:
- orxonox/trunk/core
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/core/npc.cc
r1896 r1899 30 30 31 31 32 void NPC::setPosition( int x, int y, int z)32 void NPC::setPosition(float x, float y, float z) 33 33 { 34 34 xCor = x; yCor = y; zCor = z; 35 35 } 36 36 37 void NPC::getPosition( int* x, int* y, int* z)37 void NPC::getPosition(float* x, float* y, float* z) 38 38 { 39 39 *x = xCor; … … 42 42 } 43 43 44 void NPC::setCollisionRadius( int r)44 void NPC::setCollisionRadius(float r) 45 45 { 46 46 collisionRadius = r; … … 56 56 void NPC::drawNPC(void) 57 57 { 58 cout << "Player::drawNPC()" << endl; 58 glPushMatrix(); 59 glTranslatef(xCor, yCor, 3.0); 60 //glScalef(1.0, 3.0, 1.0); 61 glutWireSphere(1.0, 10, 10); 62 glPopMatrix(); 63 //cout << "Player::drawNPC()" << endl; 59 64 } -
orxonox/trunk/core/npc.h
r1896 r1899 3 3 #define NPC_H 4 4 5 /* openGL Headers */ 6 #include <GL/glut.h> 5 7 6 8 class NPC { … … 10 12 ~NPC (); 11 13 14 /* collision control */ 15 float collisionRadius; 16 17 float xCor; 18 float yCor; 19 float zCor; 20 12 21 void drawNPC(void); 13 void setPosition( int x, int y, int z);14 void getPosition( int* x, int* y, int* z);15 void setCollisionRadius( int r);22 void setPosition(float x, float y, float z); 23 void getPosition(float* x, float* y, float* z); 24 void setCollisionRadius(float r); 16 25 float getCollisionRadius(); 17 26 … … 21 30 int npcType; 22 31 23 /* collision control */24 int collisionRadius;25 32 26 int xCor;27 int yCor;28 int zCor;29 33 ; 30 34 -
orxonox/trunk/core/orxonox.cc
r1897 r1899 99 99 { 100 100 glClearColor(0.0, 0.0, 0.0, 0.0); 101 102 /* world init, shouldnt be done here later */ 101 103 world = new World; 102 104 (*world).initEnvironement(); 103 105 localPlayer = new Player; 106 localPlayer->setPosition(0.0, -10.0, 3.0); 104 107 io = new InputOutput(world, localPlayer); 105 108 (*world).addPlayer(localPlayer); 106 109 Environment *env = new Environment; 107 110 (*world).addEnv(env); 111 NPC* npc = new NPC; 112 npc->setPosition(3.0, 0.0, 3.0); 113 npc->setCollisionRadius(1.0); 114 world->addNPC(npc); 108 115 109 116 glutSpecialFunc(specFunc); … … 248 255 /* increment the frames-per-second counter*/ 249 256 fps++; 257 /* check for collisions */ 258 world->detectCollision(); 259 250 260 /* check for input to pass it over */ 251 261 if ( !pause && (rightWeGo || leftWeGo || upWeGo || downWeGo || shoot1)) { -
orxonox/trunk/core/player.cc
r1896 r1899 25 25 26 26 Player::Player () { 27 // cout << "Player::Player" << endl; 27 28 xCor = yCor = zCor = 0; 28 29 shootLaser = new ShootLaser; -
orxonox/trunk/core/player.h
r1896 r1899 15 15 ~Player (); 16 16 17 /* position of the spacecraft */ 18 float xCor; 19 float yCor; 20 float zCor; 21 22 /* this player wanna shoot? so include a ref to ShootLaser */ 23 ShootLaser* shootLaser; 24 17 25 void setPosition(float x, float y, float z); 18 26 void getPosition(float* x, float* y, float* z); … … 25 33 26 34 private: 27 /* position of the spacecraft */28 float xCor;29 float yCor;30 float zCor;31 35 32 36 33 /* this player wanna shoot? so include a ref to ShootLaser */34 ShootLaser* shootLaser;35 37 }; 36 38 -
orxonox/trunk/core/shoot_laser.cc
r1898 r1899 54 54 /* fix1: weak boundaries check all four sides */ 55 55 /* fix2: conditions, that a struct tree can be cut off */ 56 /* fix3: more efficent and nicer please */ 56 57 if (tmpShoot->yCor > 50) 57 58 { -
orxonox/trunk/core/shoot_laser.h
r1896 r1899 24 24 float collisionRadius; 25 25 }; 26 shoot* lastShoot; 26 27 27 28 ShootLaser (); … … 34 35 35 36 private: 36 shoot* lastShoot; 37 37 38 }; 38 39 -
orxonox/trunk/core/world.cc
r1896 r1899 33 33 lastNPC = null; 34 34 lastEnv = null; 35 lastShoot = null;36 35 } 37 36 … … 128 127 129 128 130 /** 131 \brief Add environmental object 132 \param player A reference to the new env object 133 134 Add a new Environment to the world. Env has to be initialised before. 135 */ 136 bool World::addShoot(ShootLaser* shoot) 137 { 138 shootList* listMember = new shootList; 139 listMember->shoot = shoot; 140 if ( lastShoot != null ) 141 { 142 listMember->number = lastShoot->number + 1; 143 listMember->next = lastShoot; 144 } 145 else 146 { 147 listMember->number = 0; 148 listMember->next = null; 149 } 150 lastShoot = listMember; 151 } 129 152 130 153 131 … … 193 171 tmpEnv = tmpEnv->next; 194 172 } 195 /* now draw all the shoots (many) */ 196 shootList* tmpShoot = lastShoot; 197 while( tmpShoot != null ) 198 { 199 (*tmpShoot->shoot).drawShoot(); 200 tmpShoot = tmpShoot->next; 201 } 173 202 174 203 175 glColor3f(0.0, 1.0, 0.0); … … 255 227 256 228 229 /* collision detection */ 230 /* fix: bad efficency: stupid brute force */ 231 232 void World::detectCollision() 233 { 234 float xOff, yOff, zOff, radius; 235 npcList* tmpNPC; 236 237 //cout << "World::detectCollsions" << endl; 238 /* first: check if any player's shoots trigger a collision */ 239 playerList* tmpPlayer = lastPlayer; 240 Player* player = tmpPlayer->player; 241 while( tmpPlayer != null ) 242 { 243 tmpNPC = lastNPC; 244 while( tmpNPC != null ) 245 { 246 radius = tmpNPC->npc->collisionRadius; 247 ShootLaser::shoot* shoota = tmpPlayer->player->shootLaser->lastShoot; 248 while( shoota != null ) 249 { 250 xOff = shoota->xCor - tmpNPC->npc->xCor; 251 yOff = shoota->yCor - tmpNPC->npc->yCor; 252 zOff = shoota->zCor - tmpNPC->npc->zCor; 253 if ( sqrt(xOff*xOff + yOff*yOff + zOff*zOff) < radius ) 254 cout << "COLLISION " << endl; 255 shoota = shoota->next; 256 } 257 tmpNPC = tmpNPC->next; 258 } 259 260 tmpPlayer = tmpPlayer->next; 261 } 262 263 /* second: check if any player hits an enemy */ 264 265 /* third: check if any enemy shoots a player */ 266 267 //cout << "World::detectCollisions end" << endl; 268 } 269 270 257 271 258 272 /** -
orxonox/trunk/core/world.h
r1896 r1899 6 6 7 7 #include <stdlib.h> 8 #include <cmath> 8 9 9 10 #include "npc.h" … … 48 49 envList* lastEnv; 49 50 50 /* a list of all shoot-amental objects */ 51 struct shootList { 52 shootList* next; 53 ShootLaser* shoot; 54 int number; 55 }; 56 shootList* lastShoot; 51 57 52 58 53 … … 63 58 bool removeNPC(NPC* npc); 64 59 bool addEnv(Environment* env); 65 bool addShoot(ShootLaser* shoot);66 60 67 61 void drawWorld(void); 68 62 void initEnvironement(void); 69 63 void updateWorld(void); 64 void detectCollision(void); 70 65 void testThaTest(void); 71 66
Note: See TracChangeset
for help on using the changeset viewer.