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