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