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