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