[1853] | 1 | |
---|
| 2 | /* |
---|
| 3 | orxonox - the future of 3D-vertical-scrollers |
---|
| 4 | |
---|
| 5 | Copyright (C) 2004 orx |
---|
| 6 | |
---|
| 7 | This program is free software; you can redistribute it and/or modify |
---|
| 8 | it under the terms of the GNU General Public License as published by |
---|
| 9 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 10 | any later version. |
---|
[1855] | 11 | |
---|
| 12 | ### File Specific: |
---|
| 13 | main-programmer: Patrick Boenzli |
---|
[2190] | 14 | co-programmer: Christian Meyer |
---|
[1853] | 15 | */ |
---|
| 16 | |
---|
[2190] | 17 | #include "world.h" |
---|
| 18 | #include "world_entity.h" |
---|
| 19 | #include "collision.h" |
---|
[3365] | 20 | #include "track_manager.h" |
---|
[2190] | 21 | #include "track.h" |
---|
[2036] | 22 | #include "player.h" |
---|
[2190] | 23 | #include "command_node.h" |
---|
| 24 | #include "camera.h" |
---|
[2816] | 25 | #include "environment.h" |
---|
[3365] | 26 | #include "p_node.h" |
---|
| 27 | #include "null_parent.h" |
---|
| 28 | #include "helper_parent.h" |
---|
| 29 | #include "glmenu_imagescreen.h" |
---|
[2036] | 30 | |
---|
[1856] | 31 | using namespace std; |
---|
[1853] | 32 | |
---|
| 33 | |
---|
[1858] | 34 | /** |
---|
[2551] | 35 | \brief create a new World |
---|
| 36 | |
---|
| 37 | This creates a new empty world! |
---|
[1858] | 38 | */ |
---|
[2636] | 39 | World::World (char* name) |
---|
[1855] | 40 | { |
---|
[3365] | 41 | this->setClassName ("World"); |
---|
[2636] | 42 | this->worldName = name; |
---|
| 43 | this->debugWorldNr = -1; |
---|
[2822] | 44 | this->entities = new tList<WorldEntity>(); |
---|
[1855] | 45 | } |
---|
| 46 | |
---|
[2636] | 47 | World::World (int worldID) |
---|
| 48 | { |
---|
| 49 | this->debugWorldNr = worldID; |
---|
| 50 | this->worldName = NULL; |
---|
[2822] | 51 | this->entities = new tList<WorldEntity>(); |
---|
[2636] | 52 | } |
---|
| 53 | |
---|
[1858] | 54 | /** |
---|
[2551] | 55 | \brief remove the World from memory |
---|
[3365] | 56 | |
---|
| 57 | delete everything explicitly, that isn't contained in the parenting tree! |
---|
| 58 | things contained in the tree are deleted automaticaly |
---|
[1858] | 59 | */ |
---|
[2190] | 60 | World::~World () |
---|
[1872] | 61 | { |
---|
[3220] | 62 | printf("World::~World() - deleting current world\n"); |
---|
[3226] | 63 | CommandNode* cn = Orxonox::getInstance()->getLocalInput(); |
---|
[3220] | 64 | cn->unbind(this->localPlayer); |
---|
| 65 | cn->reset(); |
---|
| 66 | this->localCamera->destroy(); |
---|
| 67 | |
---|
[3365] | 68 | this->nullParent->destroy (); |
---|
| 69 | |
---|
| 70 | //delete this->trackManager; |
---|
| 71 | |
---|
| 72 | /* |
---|
[3220] | 73 | WorldEntity* entity = entities->enumerate(); |
---|
| 74 | while( entity != NULL ) |
---|
| 75 | { |
---|
| 76 | entity->destroy(); |
---|
| 77 | entity = entities->nextElement(); |
---|
| 78 | } |
---|
| 79 | this->entities->destroy(); |
---|
[3365] | 80 | */ |
---|
[3220] | 81 | |
---|
[3365] | 82 | /* FIX the parent list has to be cleared - not possible if we got the old list also*/ |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | //delete this->entities; |
---|
| 86 | //delete this->localCamera; |
---|
[3220] | 87 | /* this->localPlayer hasn't to be deleted explicitly, it is |
---|
| 88 | contained in entities*/ |
---|
[1872] | 89 | } |
---|
[1858] | 90 | |
---|
[3365] | 91 | GLfloat ctrlpoints[4][3] = { |
---|
| 92 | {20.0, 10.0, 5.0}, {40.0, -10.0, 0.0}, |
---|
| 93 | {60.0, -10.0, 5.0}, {80.0, 10.0, 5.0}}; |
---|
[2636] | 94 | |
---|
[3365] | 95 | |
---|
[3222] | 96 | ErrorMessage World::init() |
---|
[2636] | 97 | { |
---|
| 98 | this->bPause = false; |
---|
[3226] | 99 | CommandNode* cn = Orxonox::getInstance()->getLocalInput(); |
---|
[3216] | 100 | cn->addToWorld(this); |
---|
| 101 | cn->enable(true); |
---|
[3365] | 102 | |
---|
| 103 | //glMap1f (GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &ctrlpoints[0][0]); |
---|
| 104 | //glEnable (GL_MAP1_VERTEX_3); |
---|
| 105 | |
---|
| 106 | //theNurb = gluNewNurbsRenderer (); |
---|
| 107 | //gluNurbsProperty (theNurb, GLU_NURBS_MODE, GLU_NURBS_TESSELLATOR); |
---|
| 108 | //gluNurbsProperty (theNurb, GLU_NURBS_VERTEX, vertexCallback ); |
---|
| 109 | |
---|
[2636] | 110 | } |
---|
| 111 | |
---|
[3365] | 112 | |
---|
| 113 | |
---|
[3222] | 114 | ErrorMessage World::start() |
---|
[2636] | 115 | { |
---|
[3220] | 116 | printf("World::start() - starting current World: nr %i\n", this->debugWorldNr); |
---|
| 117 | this->bQuitOrxonox = false; |
---|
| 118 | this->bQuitCurrentGame = false; |
---|
[2636] | 119 | this->mainLoop(); |
---|
| 120 | } |
---|
| 121 | |
---|
[3222] | 122 | ErrorMessage World::stop() |
---|
[2636] | 123 | { |
---|
[3220] | 124 | printf("World::stop() - got stop signal\n"); |
---|
[2636] | 125 | this->bQuitCurrentGame = true; |
---|
| 126 | } |
---|
| 127 | |
---|
[3222] | 128 | ErrorMessage World::pause() |
---|
[2636] | 129 | { |
---|
| 130 | this->isPaused = true; |
---|
| 131 | } |
---|
| 132 | |
---|
[3365] | 133 | |
---|
[3222] | 134 | ErrorMessage World::resume() |
---|
[2636] | 135 | { |
---|
| 136 | this->isPaused = false; |
---|
| 137 | } |
---|
| 138 | |
---|
[3365] | 139 | |
---|
[3221] | 140 | void World::destroy() |
---|
| 141 | { |
---|
[3365] | 142 | } |
---|
[3221] | 143 | |
---|
[3365] | 144 | |
---|
| 145 | void World::displayLoadScreen () |
---|
| 146 | { |
---|
| 147 | printf ("World::displayLoadScreen - start\n"); |
---|
| 148 | |
---|
| 149 | //GLMenuImageScreen* |
---|
| 150 | glmis = new GLMenuImageScreen(); |
---|
| 151 | glmis->init(); |
---|
| 152 | glmis->draw(); |
---|
| 153 | |
---|
| 154 | printf ("World::displayLoadScreen - end\n"); |
---|
[3221] | 155 | } |
---|
| 156 | |
---|
[3365] | 157 | |
---|
| 158 | void World::releaseLoadScreen () |
---|
| 159 | { |
---|
| 160 | printf ("World::releaseLoadScreen - start\n"); |
---|
| 161 | |
---|
| 162 | printf ("World::releaseLoadScreen - end\n"); |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | |
---|
[2636] | 166 | void World::load() |
---|
| 167 | { |
---|
[3365] | 168 | // BezierCurve* tmpCurve = new BezierCurve(); |
---|
[2636] | 169 | if(this->debugWorldNr != -1) |
---|
| 170 | { |
---|
[3365] | 171 | trackManager = TrackManager::getInstance(); |
---|
| 172 | trackManager->addPoint(Vector(0,-5,0)); |
---|
| 173 | trackManager->addPoint(Vector(10,0,5)); |
---|
| 174 | trackManager->addPoint(Vector(20,0,-5)); |
---|
| 175 | trackManager->addPoint(Vector(30,0,5)); |
---|
| 176 | trackManager->addPoint(Vector(40,0,5)); |
---|
| 177 | trackManager->setDuration(.5); |
---|
| 178 | trackManager->setSavePoint(); |
---|
| 179 | trackManager->addPoint(Vector(50,10,10)); |
---|
| 180 | trackManager->addPoint(Vector(60,0, 10)); |
---|
| 181 | trackManager->addPoint(Vector(70,0, 10)); |
---|
| 182 | trackManager->addPoint(Vector(80,0,-10)); |
---|
| 183 | trackManager->addPoint(Vector(90,0,-10)); |
---|
| 184 | trackManager->setDuration(.5); |
---|
| 185 | trackManager->setSavePoint(); |
---|
| 186 | trackManager->addPoint(Vector(110,0,5)); |
---|
| 187 | trackManager->addPoint(Vector(120,0, 10)); |
---|
| 188 | trackManager->addPoint(Vector(130,0, 10)); |
---|
| 189 | trackManager->addPoint(Vector(140,0,-10)); |
---|
| 190 | trackManager->addPoint(Vector(150,0,-10)); |
---|
| 191 | trackManager->setDuration(.5); |
---|
| 192 | int fork11, fork12, fork13, fork14; |
---|
| 193 | trackManager->fork(4, &fork11, &fork12, &fork13, &fork14); |
---|
| 194 | trackManager->workOn(fork11); |
---|
| 195 | trackManager->addPoint(Vector(170, 0, -15)); |
---|
| 196 | trackManager->addPoint(Vector(180, 0, -15)); |
---|
| 197 | trackManager->workOn(fork12); |
---|
| 198 | trackManager->addPoint(Vector(170, 0, 10)); |
---|
| 199 | trackManager->addPoint(Vector(180, 0, 10)); |
---|
| 200 | trackManager->addPoint(Vector(190,2,5)); |
---|
| 201 | trackManager->addPoint(Vector(200,2,5)); |
---|
| 202 | int fork21, fork22; |
---|
| 203 | trackManager->fork(2, &fork21, &fork22); |
---|
| 204 | trackManager->workOn(fork21); |
---|
| 205 | trackManager->addPoint(Vector(220, 10,-10)); |
---|
| 206 | trackManager->addPoint(Vector(230, 0,-10)); |
---|
| 207 | trackManager->addPoint(Vector(240, 0, 2)); |
---|
| 208 | trackManager->addPoint(Vector(250, 0, 0)); |
---|
| 209 | trackManager->addPoint(Vector(260, 0, 5)); |
---|
| 210 | trackManager->join(2, fork12, fork11); |
---|
| 211 | trackManager->workOn(fork22); |
---|
| 212 | trackManager->addPoint(Vector(220, -10,10)); |
---|
| 213 | trackManager->addPoint(Vector(230, 0, 10)); |
---|
| 214 | trackManager->addPoint(Vector(240, 0, 10)); |
---|
| 215 | trackManager->addPoint(Vector(250, 0, 5)); |
---|
| 216 | trackManager->workOn(fork13); |
---|
| 217 | trackManager->addPoint(Vector(200,-10,5)); |
---|
| 218 | trackManager->addPoint(Vector(250,-10,5)); |
---|
| 219 | printf("fork14: %d\n", fork14); |
---|
| 220 | trackManager->workOn(fork14); |
---|
| 221 | trackManager->addPoint(Vector(200,15,0)); |
---|
| 222 | trackManager->addPoint(Vector(210,0,10)); |
---|
| 223 | |
---|
| 224 | |
---|
| 225 | |
---|
| 226 | trackManager->join(4, fork21, fork22, fork13, fork14); |
---|
| 227 | |
---|
| 228 | /* |
---|
| 229 | tmpCurve->addNode(Vector(10,0,-10)); |
---|
| 230 | //tmpCurve->addNode(Vector(10,2,5)); |
---|
| 231 | //tmpCurve->addNode(Vector(10,3,-5)); |
---|
| 232 | // tmpCurve->addNode(Vector(10,1,5)); |
---|
| 233 | tmpCurve->addNode(Vector(10,0,5)); |
---|
| 234 | */ |
---|
[2636] | 235 | switch(this->debugWorldNr) |
---|
| 236 | { |
---|
[3225] | 237 | /* |
---|
| 238 | this loads the hard-coded debug world. this only for simplicity and will be |
---|
| 239 | removed by a reald world-loader, which interprets a world-file. |
---|
| 240 | if you want to add an own debug world, just add a case DEBUG_WORLD_[nr] and |
---|
| 241 | make whatever you want... |
---|
| 242 | */ |
---|
[2636] | 243 | case DEBUG_WORLD_0: |
---|
| 244 | { |
---|
[3365] | 245 | this->nullParent = NullParent::getInstance (); |
---|
| 246 | this->nullParent->setName ("NullParent"); |
---|
| 247 | |
---|
[2636] | 248 | // create some path nodes |
---|
| 249 | this->pathnodes = new Vector[6]; |
---|
| 250 | this->pathnodes[0] = Vector(0, 0, 0); |
---|
[2792] | 251 | this->pathnodes[1] = Vector(1000, 0, 0); |
---|
| 252 | // this->pathnodes[2] = Vector(-100, 140, 0); |
---|
| 253 | // this->pathnodes[3] = Vector(0, 180, 0); |
---|
| 254 | // this->pathnodes[4] = Vector(100, 140, 0); |
---|
| 255 | // this->pathnodes[5] = Vector(100, 40, 0); |
---|
[2636] | 256 | |
---|
| 257 | // create the tracks |
---|
[2816] | 258 | this->tracklen = 2; |
---|
| 259 | this->track = new Track[2]; |
---|
[2636] | 260 | for( int i = 0; i < this->tracklen; i++) |
---|
| 261 | { |
---|
| 262 | this->track[i] = Track( i, (i+1)%this->tracklen, &this->pathnodes[i], &this->pathnodes[(i+1)%this->tracklen]); |
---|
| 263 | } |
---|
[3194] | 264 | // !\todo old track-system has to be removed |
---|
| 265 | |
---|
[3365] | 266 | //create helper for player |
---|
| 267 | HelperParent* hp = new HelperParent (); |
---|
| 268 | /* the player has to be added to this helper */ |
---|
| 269 | |
---|
[2636] | 270 | // create a player |
---|
[3365] | 271 | WorldEntity* myPlayer = new Player (); |
---|
| 272 | myPlayer->setName ("player"); |
---|
| 273 | this->spawn (myPlayer); |
---|
[2640] | 274 | this->localPlayer = myPlayer; |
---|
| 275 | |
---|
[2636] | 276 | // bind input |
---|
[3365] | 277 | Orxonox *orx = Orxonox::getInstance (); |
---|
[3226] | 278 | orx->getLocalInput()->bind (myPlayer); |
---|
[2636] | 279 | |
---|
| 280 | // bind camera |
---|
| 281 | this->localCamera = new Camera(this); |
---|
[3365] | 282 | this->localCamera->setName ("camera"); |
---|
| 283 | this->getCamera()->bind (myPlayer); |
---|
| 284 | this->localPlayer->addChild (this->localCamera); |
---|
| 285 | |
---|
[2816] | 286 | |
---|
[3365] | 287 | Vector* es = new Vector (50, 2, 0); |
---|
| 288 | Quaternion* qs = new Quaternion (); |
---|
[2816] | 289 | WorldEntity* env = new Environment(); |
---|
[3365] | 290 | env->setName ("env"); |
---|
| 291 | this->spawn(env, es, qs); |
---|
[2816] | 292 | |
---|
[3365] | 293 | |
---|
[2636] | 294 | break; |
---|
| 295 | } |
---|
| 296 | case DEBUG_WORLD_1: |
---|
| 297 | { |
---|
[3365] | 298 | /* |
---|
| 299 | this->testCurve = new UPointCurve(); |
---|
| 300 | this->testCurve->addNode(Vector( 0, 0, 0)); |
---|
| 301 | this->testCurve->addNode(Vector(10, 0, 5)); |
---|
| 302 | this->testCurve->addNode(Vector(20, -5,-5)); |
---|
| 303 | this->testCurve->addNode(Vector(30, 5, 10)); |
---|
| 304 | this->testCurve->addNode(Vector(40, 0,-10)); |
---|
| 305 | this->testCurve->addNode(Vector(50, 0,-10)); |
---|
| 306 | */ |
---|
| 307 | |
---|
| 308 | this->nullParent = NullParent::getInstance (); |
---|
| 309 | this->nullParent->setName ("NullParent"); |
---|
| 310 | |
---|
[2636] | 311 | // create some path nodes |
---|
| 312 | this->pathnodes = new Vector[6]; |
---|
| 313 | this->pathnodes[0] = Vector(0, 0, 0); |
---|
| 314 | this->pathnodes[1] = Vector(20, 10, 10); |
---|
| 315 | this->pathnodes[2] = Vector(40, 0, 10); |
---|
| 316 | this->pathnodes[3] = Vector(60, 10, 0); |
---|
| 317 | this->pathnodes[4] = Vector(80, 20, 10); |
---|
| 318 | this->pathnodes[5] = Vector(30, 50, 0); |
---|
| 319 | |
---|
[3365] | 320 | |
---|
| 321 | |
---|
| 322 | |
---|
[2636] | 323 | // create the tracks |
---|
| 324 | this->tracklen = 6; |
---|
| 325 | this->track = new Track[6]; |
---|
| 326 | for( int i = 0; i < this->tracklen; i++) |
---|
| 327 | { |
---|
| 328 | this->track[i] = Track( i, (i+1)%this->tracklen, &this->pathnodes[i], &this->pathnodes[(i+1)%this->tracklen]); |
---|
| 329 | } |
---|
[3194] | 330 | |
---|
[2636] | 331 | // create a player |
---|
[2644] | 332 | WorldEntity* myPlayer = new Player(); |
---|
[3365] | 333 | myPlayer->setName ("player"); |
---|
[2644] | 334 | this->spawn(myPlayer); |
---|
[3194] | 335 | this->localPlayer = myPlayer; |
---|
[2636] | 336 | |
---|
| 337 | // bind input |
---|
| 338 | Orxonox *orx = Orxonox::getInstance(); |
---|
[3226] | 339 | orx->getLocalInput()->bind (myPlayer); |
---|
[2636] | 340 | |
---|
| 341 | // bind camera |
---|
[3365] | 342 | this->localCamera = new Camera (this); |
---|
| 343 | this->localCamera->setName ("camera"); |
---|
[2636] | 344 | this->getCamera()->bind (myPlayer); |
---|
[3365] | 345 | this->localPlayer->addChild (this->localCamera); |
---|
[2636] | 346 | break; |
---|
| 347 | } |
---|
| 348 | default: |
---|
| 349 | printf("World::load() - no world with ID %i found", this->debugWorldNr ); |
---|
| 350 | } |
---|
| 351 | } |
---|
| 352 | else if(this->worldName != NULL) |
---|
| 353 | { |
---|
| 354 | |
---|
| 355 | } |
---|
[2731] | 356 | |
---|
| 357 | // initialize debug coord system |
---|
| 358 | objectList = glGenLists(1); |
---|
| 359 | glNewList (objectList, GL_COMPILE); |
---|
| 360 | glLoadIdentity(); |
---|
[2792] | 361 | glColor3f(1.0,0,0); |
---|
[2817] | 362 | glBegin(GL_QUADS); |
---|
[3200] | 363 | |
---|
| 364 | int sizeX = 100; |
---|
[3365] | 365 | int sizeZ = 80; |
---|
[3200] | 366 | float length = 1000; |
---|
| 367 | float width = 200; |
---|
| 368 | float widthX = float (length /sizeX); |
---|
[3365] | 369 | float widthZ = float (width /sizeZ); |
---|
[3199] | 370 | |
---|
[3365] | 371 | float height [sizeX][sizeZ]; |
---|
| 372 | Vector normal_vectors[sizeX][sizeZ]; |
---|
[3199] | 373 | |
---|
[3200] | 374 | |
---|
| 375 | for ( int i = 0; i<sizeX-1; i+=1) |
---|
[3365] | 376 | for (int j = 0; j<sizeZ-1;j+=1) |
---|
[3200] | 377 | //height[i][j] = rand()/20046 + (j-25)*(j-25)/30; |
---|
[3199] | 378 | #ifdef __WIN32__ |
---|
[3200] | 379 | height[i][j]=(sin((float)j/3)*rand()*i/182400)*.5; |
---|
[3199] | 380 | #else |
---|
[3200] | 381 | height[i][j]=(sin((float)j/3)*rand()*(long)i/6282450500.0)*.5; |
---|
[3199] | 382 | #endif |
---|
[3200] | 383 | |
---|
[3365] | 384 | //Die Huegel ein wenig glaetten |
---|
[3199] | 385 | for (int h=1; h<2;h++) |
---|
[3200] | 386 | for (int i=1;i<sizeX-2 ;i+=1 ) |
---|
[3365] | 387 | for(int j=1;j<sizeZ-2;j+=1) |
---|
[3199] | 388 | height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4; |
---|
| 389 | |
---|
| 390 | //Berechnung von normalen Vektoren |
---|
[3200] | 391 | for(int i=1;i<sizeX-2;i+=1) |
---|
[3365] | 392 | for(int j=1;j<sizeZ-2 ;j+=1) |
---|
[2792] | 393 | { |
---|
[3365] | 394 | Vector v1 = Vector (widthX*(1), height[i][j], widthZ*(j) ); |
---|
| 395 | Vector v2 = Vector (widthX*(i-1), height[i-1][j], widthZ*(j)); |
---|
| 396 | Vector v3 = Vector (widthX*(i), height[i][j+1], widthZ*(j+1)); |
---|
| 397 | Vector v4 = Vector (widthX*(i+1), height[i+1][j], widthZ*(j)); |
---|
| 398 | Vector v5 = Vector (widthX*(i), height[i][j-1], widthZ*(j-1)); |
---|
[3199] | 399 | |
---|
[3200] | 400 | Vector c1 = v2 - v1; |
---|
| 401 | Vector c2 = v3 - v1; |
---|
| 402 | Vector c3= v4 - v1; |
---|
| 403 | Vector c4 = v5 - v1; |
---|
| 404 | Vector zero = Vector (0,0,0); |
---|
[3365] | 405 | normal_vectors[i][j]=c1.cross(v3-v5)+c2.cross(v4-v2)+c3.cross(v5-v3)+c4.cross(v2-v4); |
---|
[3199] | 406 | normal_vectors[i][j].normalize(); |
---|
[3200] | 407 | } |
---|
| 408 | |
---|
| 409 | int snowheight=3; |
---|
| 410 | for ( int i = 0; i<sizeX; i+=1) |
---|
[3365] | 411 | for (int j = 0; j<sizeZ;j+=1) |
---|
[3200] | 412 | { |
---|
[3365] | 413 | Vector v1 = Vector (widthX*(i), height[i][j]-20, widthZ*(j) -width/2); |
---|
| 414 | Vector v2 = Vector (widthX*(i+1), height[i+1][j]-20, widthZ*(j) -width/2); |
---|
| 415 | Vector v3 = Vector (widthX*(i+1), height[i+1][j+1]-20, widthZ*(j+1)-width/2); |
---|
| 416 | Vector v4 = Vector (widthX*(i), height[i][j+1]-20, widthZ*(j+1)-width/2); |
---|
[3200] | 417 | float a[3]; |
---|
| 418 | if(height[i][j]<snowheight){ |
---|
| 419 | a[0]=0; |
---|
| 420 | a[1]=1.0-height[i][j]/10-.3; |
---|
| 421 | a[2]=0; |
---|
| 422 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
[3199] | 423 | } |
---|
[3200] | 424 | else{ |
---|
[3199] | 425 | a[0]=1.0; |
---|
| 426 | a[1]=1.0; |
---|
| 427 | a[2]=1.0; |
---|
| 428 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
[2817] | 429 | |
---|
[3199] | 430 | } |
---|
[3200] | 431 | glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z); |
---|
| 432 | glVertex3f(v1.x, v1.y, v1.z); |
---|
| 433 | if(height[i+1][j]<snowheight){ |
---|
| 434 | a[0]=0; |
---|
| 435 | a[1] =1.0-height[i+1][j]/10-.3; |
---|
| 436 | a[2]=0; |
---|
| 437 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
| 438 | } |
---|
| 439 | else{ |
---|
| 440 | a[0]=1.0; |
---|
| 441 | a[1]=1.0; |
---|
| 442 | a[2]=1.0; |
---|
| 443 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
| 444 | |
---|
| 445 | } |
---|
| 446 | glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z); |
---|
| 447 | glVertex3f(v2.x, v2.y, v2.z); |
---|
| 448 | if(height[i+1][j+1]<snowheight){ |
---|
| 449 | a[0]=0; |
---|
| 450 | a[1] =1.0-height[i+1][j+1]/10-.3; |
---|
| 451 | a[2]=0; |
---|
| 452 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
| 453 | } |
---|
| 454 | else{ |
---|
| 455 | a[0]=1.0; |
---|
| 456 | a[1]=1.0; |
---|
| 457 | a[2]=1.0; |
---|
| 458 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
| 459 | |
---|
| 460 | |
---|
| 461 | } |
---|
| 462 | glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z); |
---|
| 463 | glVertex3f(v3.x, v3.y, v3.z); |
---|
| 464 | if(height[i][j+1]<snowheight){ |
---|
| 465 | a[0]=0; |
---|
| 466 | a[1] =1.0-height[i+1][j+1]/10-.3; |
---|
| 467 | a[2]=0; |
---|
| 468 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
| 469 | } |
---|
| 470 | else{ |
---|
| 471 | a[0]=1.0; |
---|
| 472 | a[1]=1.0; |
---|
| 473 | a[2]=1.0; |
---|
| 474 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
| 475 | } |
---|
| 476 | glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z); |
---|
| 477 | glVertex3f(v4.x, v4.y, v4.z); |
---|
| 478 | |
---|
| 479 | } |
---|
[3199] | 480 | glEnd(); |
---|
| 481 | /* |
---|
[2792] | 482 | glBegin(GL_LINES); |
---|
[2731] | 483 | for( float x = -128.0; x < 128.0; x += 25.0) |
---|
| 484 | { |
---|
| 485 | for( float y = -128.0; y < 128.0; y += 25.0) |
---|
| 486 | { |
---|
| 487 | glColor3f(1,0,0); |
---|
| 488 | glVertex3f(x,y,-128.0); |
---|
| 489 | glVertex3f(x,y,0.0); |
---|
| 490 | glColor3f(0.5,0,0); |
---|
| 491 | glVertex3f(x,y,0.0); |
---|
| 492 | glVertex3f(x,y,128.0); |
---|
| 493 | } |
---|
| 494 | } |
---|
| 495 | for( float y = -128.0; y < 128.0; y += 25.0) |
---|
| 496 | { |
---|
| 497 | for( float z = -128.0; z < 128.0; z += 25.0) |
---|
| 498 | { |
---|
| 499 | glColor3f(0,1,0); |
---|
| 500 | glVertex3f(-128.0,y,z); |
---|
| 501 | glVertex3f(0.0,y,z); |
---|
| 502 | glColor3f(0,0.5,0); |
---|
| 503 | glVertex3f(0.0,y,z); |
---|
| 504 | glVertex3f(128.0,y,z); |
---|
| 505 | } |
---|
| 506 | } |
---|
| 507 | for( float x = -128.0; x < 128.0; x += 25.0) |
---|
| 508 | { |
---|
| 509 | for( float z = -128.0; z < 128.0; z += 25.0) |
---|
| 510 | { |
---|
| 511 | glColor3f(0,0,1); |
---|
| 512 | glVertex3f(x,-128.0,z); |
---|
| 513 | glVertex3f(x,0.0,z); |
---|
| 514 | glColor3f(0,0,0.5); |
---|
| 515 | glVertex3f(x,0.0,z); |
---|
| 516 | glVertex3f(x,128.0,z); |
---|
| 517 | } |
---|
| 518 | |
---|
| 519 | } |
---|
[2792] | 520 | */ |
---|
[2731] | 521 | //draw track |
---|
[2792] | 522 | glBegin(GL_LINES); |
---|
[3365] | 523 | glColor3f(0.0, 1.0, 1.0); |
---|
[2731] | 524 | for( int i = 0; i < tracklen; i++) |
---|
| 525 | { |
---|
| 526 | glVertex3f(pathnodes[i].x,pathnodes[i].y,pathnodes[i].z); |
---|
| 527 | glVertex3f(pathnodes[(i+1)%tracklen].x,pathnodes[(i+1)%tracklen].y,pathnodes[(i+1)%tracklen].z); |
---|
| 528 | } |
---|
| 529 | glEnd(); |
---|
[3365] | 530 | |
---|
| 531 | /* |
---|
| 532 | glBegin(GL_LINE_STRIP); |
---|
| 533 | glColor3f(1.0, 5.0, 1.0); |
---|
| 534 | for( int i = 0; i <= 30; i++) |
---|
| 535 | { |
---|
| 536 | glEvalCoord1f ((GLfloat) i/30.0); |
---|
| 537 | } |
---|
| 538 | glEnd(); |
---|
| 539 | */ |
---|
| 540 | |
---|
| 541 | trackManager->drawGraph(.01); |
---|
| 542 | trackManager->debug(2); |
---|
| 543 | delete trackManager; |
---|
| 544 | |
---|
| 545 | /* |
---|
| 546 | glBegin(GL_LINES); |
---|
| 547 | float i; |
---|
| 548 | for(i = 0.0; i<1; i+=.01) |
---|
| 549 | { |
---|
| 550 | printf("%f, %f, %f\n",tmpCurve->calcPos(i).x, tmpCurve->calcPos(i).y, tmpCurve->calcPos(i).z); |
---|
| 551 | glVertex3f(tmpCurve->calcPos(i).x, tmpCurve->calcPos(i).y, tmpCurve->calcPos(i).z); |
---|
| 552 | } |
---|
| 553 | glEnd(); |
---|
| 554 | */ |
---|
[2731] | 555 | glEndList(); |
---|
[2636] | 556 | } |
---|
| 557 | |
---|
| 558 | |
---|
| 559 | /** |
---|
[2551] | 560 | \brief checks for collisions |
---|
| 561 | |
---|
| 562 | This method runs through all WorldEntities known to the world and checks for collisions |
---|
| 563 | between them. In case of collisions the collide() method of the corresponding entities |
---|
| 564 | is called. |
---|
[1858] | 565 | */ |
---|
[2190] | 566 | void World::collide () |
---|
[1858] | 567 | { |
---|
[2816] | 568 | /* |
---|
| 569 | List *a, *b; |
---|
[2551] | 570 | WorldEntity *aobj, *bobj; |
---|
[2816] | 571 | |
---|
| 572 | a = entities; |
---|
[2551] | 573 | |
---|
| 574 | while( a != NULL) |
---|
| 575 | { |
---|
[2816] | 576 | aobj = a->nextElement(); |
---|
[2551] | 577 | if( aobj->bCollide && aobj->collisioncluster != NULL) |
---|
[2190] | 578 | { |
---|
[2816] | 579 | b = a->nextElement(); |
---|
[2551] | 580 | while( b != NULL ) |
---|
| 581 | { |
---|
[2816] | 582 | bobj = b->nextElement(); |
---|
[2551] | 583 | if( bobj->bCollide && bobj->collisioncluster != NULL ) |
---|
[2190] | 584 | { |
---|
[2551] | 585 | unsigned long ahitflg, bhitflg; |
---|
| 586 | if( check_collision ( &aobj->place, aobj->collisioncluster, |
---|
| 587 | &ahitflg, &bobj->place, bobj->collisioncluster, |
---|
| 588 | &bhitflg) ); |
---|
| 589 | { |
---|
| 590 | aobj->collide (bobj, ahitflg, bhitflg); |
---|
| 591 | bobj->collide (aobj, bhitflg, ahitflg); |
---|
| 592 | } |
---|
[2190] | 593 | } |
---|
[2816] | 594 | b = b->nextElement(); |
---|
[2551] | 595 | } |
---|
[2190] | 596 | } |
---|
[2816] | 597 | a = a->enumerate(); |
---|
[2551] | 598 | } |
---|
[2816] | 599 | */ |
---|
[1858] | 600 | } |
---|
| 601 | |
---|
| 602 | /** |
---|
[2551] | 603 | \brief runs through all entities calling their draw() methods |
---|
[1931] | 604 | */ |
---|
[2190] | 605 | void World::draw () |
---|
[2077] | 606 | { |
---|
[2551] | 607 | // draw entities |
---|
| 608 | WorldEntity* entity; |
---|
[2822] | 609 | entity = this->entities->enumerate(); |
---|
[2816] | 610 | while( entity != NULL ) |
---|
[2551] | 611 | { |
---|
[2822] | 612 | if( entity->bDraw ) entity->draw(); |
---|
| 613 | entity = this->entities->nextElement(); |
---|
[3365] | 614 | } |
---|
[2551] | 615 | |
---|
[3365] | 616 | //glmis = new GLMenuImageScreen(); |
---|
| 617 | ///glmis->init(); |
---|
| 618 | |
---|
[2551] | 619 | // draw debug coord system |
---|
[2731] | 620 | glCallList (objectList); |
---|
[2551] | 621 | |
---|
[1931] | 622 | } |
---|
| 623 | |
---|
| 624 | /** |
---|
[2551] | 625 | \brief updates Placements and notifies entities when they left the |
---|
| 626 | world |
---|
| 627 | |
---|
| 628 | This runs trough all WorldEntities and maps Locations to Placements |
---|
| 629 | if they are bound, checks whether they left the level boundaries |
---|
| 630 | and calls appropriate functions. |
---|
[1883] | 631 | */ |
---|
[2190] | 632 | void World::update () |
---|
[1883] | 633 | { |
---|
[3365] | 634 | /* |
---|
[2816] | 635 | //List<WorldEntity> *l; |
---|
[2551] | 636 | WorldEntity* entity; |
---|
| 637 | Location* loc; |
---|
| 638 | Placement* plc; |
---|
| 639 | Uint32 t; |
---|
| 640 | |
---|
[2816] | 641 | // l = entities->enumerate(); |
---|
| 642 | entity = this->entities->enumerate(); |
---|
| 643 | while( entity != NULL ) |
---|
[2551] | 644 | { |
---|
[2816] | 645 | |
---|
[2551] | 646 | |
---|
| 647 | if( !entity->isFree() ) |
---|
| 648 | { |
---|
[3233] | 649 | loc = entity->getLocation(); |
---|
| 650 | plc = entity->getPlacement(); |
---|
[2551] | 651 | t = loc->part; |
---|
| 652 | |
---|
| 653 | if( t >= tracklen ) |
---|
| 654 | { |
---|
| 655 | printf("An entity is out of the game area\n"); |
---|
[3233] | 656 | entity->leftWorld (); |
---|
[2551] | 657 | } |
---|
| 658 | else |
---|
| 659 | { |
---|
[3233] | 660 | while( track[t].mapCoords( loc, plc) ) |
---|
[2190] | 661 | { |
---|
[3233] | 662 | track[t].postLeave (entity); |
---|
[2551] | 663 | if( loc->part >= tracklen ) |
---|
| 664 | { |
---|
| 665 | printf("An entity has left the game area\n"); |
---|
[3233] | 666 | entity->leftWorld (); |
---|
[2551] | 667 | break; |
---|
| 668 | } |
---|
[3233] | 669 | track[loc->part].postEnter (entity); |
---|
[2190] | 670 | } |
---|
[2551] | 671 | } |
---|
[2190] | 672 | } |
---|
[2551] | 673 | else |
---|
| 674 | { |
---|
| 675 | } |
---|
| 676 | |
---|
[2816] | 677 | entity = entities->nextElement(); |
---|
[2551] | 678 | } |
---|
[3365] | 679 | */ |
---|
[1883] | 680 | } |
---|
| 681 | |
---|
[2077] | 682 | /** |
---|
[2551] | 683 | \brief relays the passed time since the last frame to entities and Track parts |
---|
| 684 | \param deltaT: the time passed since the last frame in milliseconds |
---|
[2077] | 685 | */ |
---|
[3225] | 686 | void World::timeSlice (Uint32 deltaT) |
---|
[2077] | 687 | { |
---|
[2816] | 688 | //List<WorldEntity> *l; |
---|
[2551] | 689 | WorldEntity* entity; |
---|
[3175] | 690 | float seconds = deltaT / 1000.0; |
---|
[2551] | 691 | |
---|
[3365] | 692 | this->nullParent->update (seconds); |
---|
| 693 | //this->nullParent->processTick (seconds); |
---|
| 694 | |
---|
[2816] | 695 | entity = entities->enumerate(); |
---|
| 696 | while( entity != NULL) |
---|
[2551] | 697 | { |
---|
| 698 | entity->tick (seconds); |
---|
[2816] | 699 | entity = entities->nextElement(); |
---|
[2551] | 700 | } |
---|
[2816] | 701 | |
---|
[3209] | 702 | //for( int i = 0; i < tracklen; i++) track[i].tick (seconds); |
---|
[2077] | 703 | } |
---|
[1883] | 704 | |
---|
[2190] | 705 | /** |
---|
[2551] | 706 | \brief removes level data from memory |
---|
[1858] | 707 | */ |
---|
[2190] | 708 | void World::unload() |
---|
[1858] | 709 | { |
---|
[2551] | 710 | if( pathnodes) delete []pathnodes; |
---|
| 711 | if( track) delete []pathnodes; |
---|
[1883] | 712 | } |
---|
[1879] | 713 | |
---|
[2636] | 714 | |
---|
| 715 | void World::setTrackLen(Uint32 len) |
---|
| 716 | { |
---|
| 717 | this->tracklen = len; |
---|
| 718 | } |
---|
| 719 | |
---|
| 720 | int World::getTrackLen() |
---|
| 721 | { |
---|
| 722 | return this->tracklen; |
---|
| 723 | } |
---|
| 724 | |
---|
[3225] | 725 | |
---|
| 726 | |
---|
| 727 | /** |
---|
| 728 | \brief function to put your own debug stuff into it. it can display informations about |
---|
| 729 | the current class/procedure |
---|
| 730 | */ |
---|
[2640] | 731 | void World::debug() |
---|
| 732 | { |
---|
[3365] | 733 | printf ("World::debug() - starting debug\n"); |
---|
| 734 | PNode* p1 = NullParent::getInstance (); |
---|
| 735 | PNode* p2 = new PNode (new Vector(2, 2, 2), p1); |
---|
| 736 | PNode* p3 = new PNode (new Vector(4, 4, 4), p1); |
---|
| 737 | PNode* p4 = new PNode (new Vector(6, 6, 6), p2); |
---|
| 738 | |
---|
| 739 | p1->debug (); |
---|
| 740 | p2->debug (); |
---|
| 741 | p3->debug (); |
---|
| 742 | p4->debug (); |
---|
| 743 | |
---|
| 744 | p1->shiftCoor (new Vector(-1, -1, -1)); |
---|
| 745 | |
---|
| 746 | printf("World::debug() - shift\n"); |
---|
| 747 | p1->debug (); |
---|
| 748 | p2->debug (); |
---|
| 749 | p3->debug (); |
---|
| 750 | p4->debug (); |
---|
| 751 | |
---|
| 752 | p1->update (1); |
---|
| 753 | |
---|
| 754 | printf ("World::debug() - update\n"); |
---|
| 755 | p1->debug (); |
---|
| 756 | p2->debug (); |
---|
| 757 | p3->debug (); |
---|
| 758 | p4->debug (); |
---|
| 759 | |
---|
| 760 | p2->shiftCoor (new Vector(-1, -1, -1)); |
---|
| 761 | p1->update (2); |
---|
| 762 | |
---|
| 763 | p1->debug (); |
---|
| 764 | p2->debug (); |
---|
| 765 | p3->debug (); |
---|
| 766 | p4->debug (); |
---|
| 767 | |
---|
| 768 | p2->setAbsCoor (new Vector(1,2,3)); |
---|
| 769 | |
---|
| 770 | |
---|
| 771 | p1->update (2); |
---|
| 772 | |
---|
| 773 | p1->debug (); |
---|
| 774 | p2->debug (); |
---|
| 775 | p3->debug (); |
---|
| 776 | p4->debug (); |
---|
| 777 | |
---|
| 778 | p1->destroy (); |
---|
| 779 | |
---|
| 780 | |
---|
| 781 | /* |
---|
[2640] | 782 | WorldEntity* entity; |
---|
| 783 | printf("counting all entities\n"); |
---|
[2816] | 784 | printf("World::debug() - enumerate()\n"); |
---|
| 785 | entity = entities->enumerate(); |
---|
| 786 | while( entity != NULL ) |
---|
[2640] | 787 | { |
---|
| 788 | if( entity->bDraw ) printf("got an entity\n"); |
---|
[2816] | 789 | entity = entities->nextElement(); |
---|
[2640] | 790 | } |
---|
[3365] | 791 | */ |
---|
[2640] | 792 | } |
---|
[2636] | 793 | |
---|
[2640] | 794 | |
---|
[3225] | 795 | /* |
---|
| 796 | \brief main loop of the world: executing all world relevant function |
---|
| 797 | |
---|
| 798 | in this loop we synchronize (if networked), handle input events, give the heart-beat to |
---|
| 799 | all other member-entities of the world (tick to player, enemies etc.), checking for |
---|
| 800 | collisions drawing everything to the screen. |
---|
| 801 | */ |
---|
[2636] | 802 | void World::mainLoop() |
---|
| 803 | { |
---|
[3365] | 804 | this->lastFrame = SDL_GetTicks (); |
---|
[3220] | 805 | printf("World::mainLoop() - Entering main loop\n"); |
---|
[3215] | 806 | while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* \todo implement pause */ |
---|
[2551] | 807 | { |
---|
[2636] | 808 | // Network |
---|
[3365] | 809 | this->synchronize (); |
---|
[2636] | 810 | // Process input |
---|
[3365] | 811 | this->handleInput (); |
---|
[3215] | 812 | if( this->bQuitCurrentGame || this->bQuitOrxonox) |
---|
| 813 | { |
---|
| 814 | printf("World::mainLoop() - leaving loop earlier...\n"); |
---|
| 815 | break; |
---|
| 816 | } |
---|
[2636] | 817 | // Process time |
---|
[3365] | 818 | this->timeSlice (); |
---|
[2636] | 819 | // Process collision |
---|
[3365] | 820 | this->collision (); |
---|
[2636] | 821 | // Draw |
---|
[3365] | 822 | this->display (); |
---|
[2816] | 823 | |
---|
[3365] | 824 | for( int i = 0; i < 5000000; i++) {} |
---|
| 825 | /* \todo this is to slow down the program for openGl Software emulator computers, reimplement*/ |
---|
[2551] | 826 | } |
---|
[3215] | 827 | printf("World::mainLoop() - Exiting the main loop\n"); |
---|
[1899] | 828 | } |
---|
| 829 | |
---|
[2190] | 830 | /** |
---|
[2636] | 831 | \brief synchronize local data with remote data |
---|
[1855] | 832 | */ |
---|
[2636] | 833 | void World::synchronize () |
---|
[1855] | 834 | { |
---|
[2636] | 835 | // Get remote input |
---|
| 836 | // Update synchronizables |
---|
[1855] | 837 | } |
---|
[2636] | 838 | |
---|
| 839 | /** |
---|
| 840 | \brief run all input processing |
---|
[3225] | 841 | |
---|
| 842 | the command node is the central input event dispatcher. the node uses the even-queue from |
---|
| 843 | sdl and has its own event-passing-queue. |
---|
[2636] | 844 | */ |
---|
[3225] | 845 | void World::handleInput () |
---|
[2636] | 846 | { |
---|
| 847 | // localinput |
---|
[3225] | 848 | CommandNode* cn = Orxonox::getInstance()->getLocalInput(); |
---|
[3216] | 849 | cn->process(); |
---|
[2636] | 850 | // remoteinput |
---|
| 851 | } |
---|
| 852 | |
---|
| 853 | /** |
---|
| 854 | \brief advance the timeline |
---|
[3225] | 855 | |
---|
| 856 | this calculates the time used to process one frame (with all input handling, drawing, etc) |
---|
| 857 | the time is mesured in ms and passed to all world-entities and other classes that need |
---|
| 858 | a heart-beat. |
---|
[2636] | 859 | */ |
---|
[3225] | 860 | void World::timeSlice () |
---|
[2636] | 861 | { |
---|
| 862 | Uint32 currentFrame = SDL_GetTicks(); |
---|
| 863 | if(!this->bPause) |
---|
| 864 | { |
---|
| 865 | Uint32 dt = currentFrame - this->lastFrame; |
---|
[2816] | 866 | |
---|
[2636] | 867 | if(dt > 0) |
---|
| 868 | { |
---|
| 869 | float fps = 1000/dt; |
---|
| 870 | printf("fps = %f\n", fps); |
---|
| 871 | } |
---|
| 872 | else |
---|
| 873 | { |
---|
[3225] | 874 | /* the frame-rate is limited to 100 frames per second, all other things are for |
---|
| 875 | nothing. |
---|
| 876 | */ |
---|
[3194] | 877 | printf("fps = 1000 - frame rate is adjusted\n"); |
---|
| 878 | SDL_Delay(10); |
---|
| 879 | dt = 10; |
---|
[2636] | 880 | } |
---|
[3225] | 881 | this->timeSlice (dt); |
---|
[2636] | 882 | this->update (); |
---|
[3225] | 883 | this->localCamera->timeSlice(dt); |
---|
[2636] | 884 | } |
---|
| 885 | this->lastFrame = currentFrame; |
---|
| 886 | } |
---|
| 887 | |
---|
[3216] | 888 | |
---|
[2636] | 889 | /** |
---|
| 890 | \brief compute collision detection |
---|
| 891 | */ |
---|
| 892 | void World::collision () |
---|
| 893 | { |
---|
| 894 | this->collide (); |
---|
| 895 | } |
---|
| 896 | |
---|
| 897 | |
---|
| 898 | /** |
---|
[3225] | 899 | \brief render the current frame |
---|
| 900 | |
---|
| 901 | clear all buffers and draw the world |
---|
[2636] | 902 | */ |
---|
| 903 | void World::display () |
---|
| 904 | { |
---|
| 905 | // clear buffer |
---|
| 906 | glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
---|
| 907 | // set camera |
---|
| 908 | this->localCamera->apply (); |
---|
| 909 | // draw world |
---|
| 910 | this->draw(); |
---|
| 911 | // draw HUD |
---|
[3365] | 912 | /* \todo draw HUD */ |
---|
[2636] | 913 | // flip buffers |
---|
| 914 | SDL_GL_SwapBuffers(); |
---|
[3365] | 915 | //SDL_Surface* screen = Orxonox::getInstance()->getScreen (); |
---|
| 916 | //SDL_Flip (screen); |
---|
[2636] | 917 | } |
---|
| 918 | |
---|
[3225] | 919 | /** |
---|
| 920 | \brief give back active camera |
---|
| 921 | |
---|
| 922 | this passes back the actualy active camera |
---|
| 923 | \todo ability to define more than one camera or camera-places |
---|
| 924 | */ |
---|
[2636] | 925 | Camera* World::getCamera() |
---|
| 926 | { |
---|
| 927 | return this->localCamera; |
---|
| 928 | } |
---|
[2644] | 929 | |
---|
| 930 | |
---|
[3225] | 931 | /** |
---|
| 932 | \brief add and spawn a new entity to this world |
---|
| 933 | \param entity to be added |
---|
| 934 | */ |
---|
[2644] | 935 | void World::spawn(WorldEntity* entity) |
---|
| 936 | { |
---|
[3365] | 937 | if( this->nullParent != NULL && entity->parent == NULL) |
---|
| 938 | this->nullParent->addChild (entity); |
---|
[2816] | 939 | |
---|
[3365] | 940 | this->entities->add (entity); |
---|
| 941 | |
---|
[3233] | 942 | entity->postSpawn (); |
---|
[2816] | 943 | } |
---|
| 944 | |
---|
| 945 | |
---|
[3225] | 946 | /** |
---|
| 947 | \brief add and spawn a new entity to this world |
---|
| 948 | \param entity to be added |
---|
| 949 | \param location where to add |
---|
| 950 | */ |
---|
[3365] | 951 | void World::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir) |
---|
[2816] | 952 | { |
---|
[3365] | 953 | entity->setAbsCoor (absCoor); |
---|
| 954 | entity->setAbsDir (absDir); |
---|
| 955 | |
---|
| 956 | if( this->nullParent != NULL && entity->parent == NULL) |
---|
| 957 | this->nullParent->addChild (entity); |
---|
| 958 | |
---|
[2816] | 959 | this->entities->add (entity); |
---|
[3365] | 960 | |
---|
[3233] | 961 | entity->postSpawn (); |
---|
[2644] | 962 | } |
---|
[2816] | 963 | |
---|
| 964 | |
---|
[3216] | 965 | |
---|
[3225] | 966 | /* |
---|
| 967 | \brief commands that the world must catch |
---|
| 968 | \returns false if not used by the world |
---|
| 969 | */ |
---|
[3216] | 970 | bool World::command(Command* cmd) |
---|
| 971 | { |
---|
| 972 | return false; |
---|
| 973 | } |
---|
[3365] | 974 | |
---|
| 975 | |
---|
| 976 | |
---|
| 977 | |
---|
| 978 | void World::swap (unsigned char &a, unsigned char &b) |
---|
| 979 | { |
---|
| 980 | unsigned char temp; |
---|
| 981 | temp = a; |
---|
| 982 | a = b; |
---|
| 983 | b = temp; |
---|
| 984 | } |
---|