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