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