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