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