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