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