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