[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" |
---|
[3500] | 31 | #include "track_node.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"); |
---|
[3461] | 223 | this->localCamera->bind (myPlayer); |
---|
[3505] | 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 | |
---|
[3500] | 241 | trackManager->setBindSlave(TrackNode::getInstance()); |
---|
[3515] | 242 | trackManager->condition(3, LEFTRIGHT, myPlayer); |
---|
[3505] | 243 | TrackNode::getInstance()->addChild(myPlayer); |
---|
| 244 | TrackNode::getInstance()->addChild(localCamera); |
---|
[3433] | 245 | |
---|
[2636] | 246 | break; |
---|
| 247 | } |
---|
| 248 | case DEBUG_WORLD_1: |
---|
| 249 | { |
---|
[3365] | 250 | /* |
---|
| 251 | this->testCurve = new UPointCurve(); |
---|
| 252 | this->testCurve->addNode(Vector( 0, 0, 0)); |
---|
| 253 | this->testCurve->addNode(Vector(10, 0, 5)); |
---|
| 254 | this->testCurve->addNode(Vector(20, -5,-5)); |
---|
| 255 | this->testCurve->addNode(Vector(30, 5, 10)); |
---|
| 256 | this->testCurve->addNode(Vector(40, 0,-10)); |
---|
| 257 | this->testCurve->addNode(Vector(50, 0,-10)); |
---|
| 258 | */ |
---|
| 259 | |
---|
| 260 | this->nullParent = NullParent::getInstance (); |
---|
| 261 | this->nullParent->setName ("NullParent"); |
---|
| 262 | |
---|
| 263 | |
---|
| 264 | |
---|
[2636] | 265 | // create a player |
---|
[2644] | 266 | WorldEntity* myPlayer = new Player(); |
---|
[3365] | 267 | myPlayer->setName ("player"); |
---|
[2644] | 268 | this->spawn(myPlayer); |
---|
[3194] | 269 | this->localPlayer = myPlayer; |
---|
[2636] | 270 | |
---|
| 271 | // bind input |
---|
| 272 | Orxonox *orx = Orxonox::getInstance(); |
---|
[3226] | 273 | orx->getLocalInput()->bind (myPlayer); |
---|
[2636] | 274 | |
---|
| 275 | // bind camera |
---|
[3365] | 276 | this->localCamera = new Camera (this); |
---|
| 277 | this->localCamera->setName ("camera"); |
---|
[3461] | 278 | this->localCamera->bind (myPlayer); |
---|
[3365] | 279 | this->localPlayer->addChild (this->localCamera); |
---|
[3429] | 280 | |
---|
| 281 | // Create SkySphere |
---|
| 282 | skySphere = new Skysphere("../data/pictures/sky-replace.jpg"); |
---|
| 283 | |
---|
[2636] | 284 | break; |
---|
[3429] | 285 | |
---|
| 286 | |
---|
[2636] | 287 | } |
---|
| 288 | default: |
---|
| 289 | printf("World::load() - no world with ID %i found", this->debugWorldNr ); |
---|
| 290 | } |
---|
| 291 | } |
---|
| 292 | else if(this->worldName != NULL) |
---|
| 293 | { |
---|
| 294 | |
---|
| 295 | } |
---|
[2731] | 296 | |
---|
| 297 | // initialize debug coord system |
---|
| 298 | objectList = glGenLists(1); |
---|
| 299 | glNewList (objectList, GL_COMPILE); |
---|
| 300 | glLoadIdentity(); |
---|
[2792] | 301 | glColor3f(1.0,0,0); |
---|
[2817] | 302 | glBegin(GL_QUADS); |
---|
[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 | |
---|
| 349 | int snowheight=3; |
---|
| 350 | for ( int i = 0; i<sizeX; i+=1) |
---|
[3365] | 351 | for (int j = 0; j<sizeZ;j+=1) |
---|
[3200] | 352 | { |
---|
[3365] | 353 | Vector v1 = Vector (widthX*(i), height[i][j]-20, widthZ*(j) -width/2); |
---|
| 354 | Vector v2 = Vector (widthX*(i+1), height[i+1][j]-20, widthZ*(j) -width/2); |
---|
| 355 | Vector v3 = Vector (widthX*(i+1), height[i+1][j+1]-20, widthZ*(j+1)-width/2); |
---|
| 356 | Vector v4 = Vector (widthX*(i), height[i][j+1]-20, widthZ*(j+1)-width/2); |
---|
[3200] | 357 | float a[3]; |
---|
| 358 | if(height[i][j]<snowheight){ |
---|
| 359 | a[0]=0; |
---|
| 360 | a[1]=1.0-height[i][j]/10-.3; |
---|
| 361 | a[2]=0; |
---|
| 362 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
[3199] | 363 | } |
---|
[3200] | 364 | else{ |
---|
[3199] | 365 | a[0]=1.0; |
---|
| 366 | a[1]=1.0; |
---|
| 367 | a[2]=1.0; |
---|
| 368 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
[2817] | 369 | |
---|
[3199] | 370 | } |
---|
[3200] | 371 | glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z); |
---|
| 372 | glVertex3f(v1.x, v1.y, v1.z); |
---|
| 373 | if(height[i+1][j]<snowheight){ |
---|
| 374 | a[0]=0; |
---|
| 375 | a[1] =1.0-height[i+1][j]/10-.3; |
---|
| 376 | a[2]=0; |
---|
| 377 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
| 378 | } |
---|
| 379 | else{ |
---|
| 380 | a[0]=1.0; |
---|
| 381 | a[1]=1.0; |
---|
| 382 | a[2]=1.0; |
---|
| 383 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
| 384 | |
---|
| 385 | } |
---|
| 386 | glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z); |
---|
| 387 | glVertex3f(v2.x, v2.y, v2.z); |
---|
| 388 | if(height[i+1][j+1]<snowheight){ |
---|
| 389 | a[0]=0; |
---|
| 390 | a[1] =1.0-height[i+1][j+1]/10-.3; |
---|
| 391 | a[2]=0; |
---|
| 392 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
| 393 | } |
---|
| 394 | else{ |
---|
| 395 | a[0]=1.0; |
---|
| 396 | a[1]=1.0; |
---|
| 397 | a[2]=1.0; |
---|
| 398 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
| 399 | |
---|
| 400 | |
---|
| 401 | } |
---|
| 402 | glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z); |
---|
| 403 | glVertex3f(v3.x, v3.y, v3.z); |
---|
| 404 | if(height[i][j+1]<snowheight){ |
---|
| 405 | a[0]=0; |
---|
| 406 | a[1] =1.0-height[i+1][j+1]/10-.3; |
---|
| 407 | a[2]=0; |
---|
| 408 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
| 409 | } |
---|
| 410 | else{ |
---|
| 411 | a[0]=1.0; |
---|
| 412 | a[1]=1.0; |
---|
| 413 | a[2]=1.0; |
---|
| 414 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
| 415 | } |
---|
| 416 | glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z); |
---|
| 417 | glVertex3f(v4.x, v4.y, v4.z); |
---|
| 418 | |
---|
| 419 | } |
---|
[3199] | 420 | glEnd(); |
---|
| 421 | /* |
---|
[2792] | 422 | glBegin(GL_LINES); |
---|
[2731] | 423 | for( float x = -128.0; x < 128.0; x += 25.0) |
---|
| 424 | { |
---|
| 425 | for( float y = -128.0; y < 128.0; y += 25.0) |
---|
| 426 | { |
---|
| 427 | glColor3f(1,0,0); |
---|
| 428 | glVertex3f(x,y,-128.0); |
---|
| 429 | glVertex3f(x,y,0.0); |
---|
| 430 | glColor3f(0.5,0,0); |
---|
| 431 | glVertex3f(x,y,0.0); |
---|
| 432 | glVertex3f(x,y,128.0); |
---|
| 433 | } |
---|
| 434 | } |
---|
| 435 | for( float y = -128.0; y < 128.0; y += 25.0) |
---|
| 436 | { |
---|
| 437 | for( float z = -128.0; z < 128.0; z += 25.0) |
---|
| 438 | { |
---|
| 439 | glColor3f(0,1,0); |
---|
| 440 | glVertex3f(-128.0,y,z); |
---|
| 441 | glVertex3f(0.0,y,z); |
---|
| 442 | glColor3f(0,0.5,0); |
---|
| 443 | glVertex3f(0.0,y,z); |
---|
| 444 | glVertex3f(128.0,y,z); |
---|
| 445 | } |
---|
| 446 | } |
---|
| 447 | for( float x = -128.0; x < 128.0; x += 25.0) |
---|
| 448 | { |
---|
| 449 | for( float z = -128.0; z < 128.0; z += 25.0) |
---|
| 450 | { |
---|
| 451 | glColor3f(0,0,1); |
---|
| 452 | glVertex3f(x,-128.0,z); |
---|
| 453 | glVertex3f(x,0.0,z); |
---|
| 454 | glColor3f(0,0,0.5); |
---|
| 455 | glVertex3f(x,0.0,z); |
---|
| 456 | glVertex3f(x,128.0,z); |
---|
| 457 | } |
---|
| 458 | |
---|
| 459 | } |
---|
[2792] | 460 | */ |
---|
[3365] | 461 | /* |
---|
| 462 | glBegin(GL_LINE_STRIP); |
---|
| 463 | glColor3f(1.0, 5.0, 1.0); |
---|
| 464 | for( int i = 0; i <= 30; i++) |
---|
| 465 | { |
---|
| 466 | glEvalCoord1f ((GLfloat) i/30.0); |
---|
| 467 | } |
---|
| 468 | glEnd(); |
---|
| 469 | */ |
---|
| 470 | |
---|
| 471 | trackManager->drawGraph(.01); |
---|
| 472 | trackManager->debug(2); |
---|
[3433] | 473 | /* |
---|
[3365] | 474 | glBegin(GL_LINES); |
---|
| 475 | float i; |
---|
| 476 | for(i = 0.0; i<1; i+=.01) |
---|
| 477 | { |
---|
| 478 | printf("%f, %f, %f\n",tmpCurve->calcPos(i).x, tmpCurve->calcPos(i).y, tmpCurve->calcPos(i).z); |
---|
| 479 | glVertex3f(tmpCurve->calcPos(i).x, tmpCurve->calcPos(i).y, tmpCurve->calcPos(i).z); |
---|
| 480 | } |
---|
| 481 | glEnd(); |
---|
| 482 | */ |
---|
[2731] | 483 | glEndList(); |
---|
[3455] | 484 | // LIGHT initialisation |
---|
| 485 | light = Light::getInstance(); |
---|
| 486 | light->addLight(0); |
---|
| 487 | light->setAttenuation(QUADRATIC, 1.0); |
---|
| 488 | light->setAttenuation(CONSTANT, 2.0); |
---|
| 489 | light->setAttenuation(QUADRATIC, 1.0); |
---|
[3458] | 490 | light->setPosition(10.0, 10.0, 50.0); |
---|
[3455] | 491 | light->setDiffuseColor(1,1,1); |
---|
| 492 | // light->addLight(1); |
---|
| 493 | // light->setPosition(20, 10, -20); |
---|
| 494 | // light->setDiffuseColor(0,0,0); |
---|
| 495 | light->debug(); |
---|
| 496 | |
---|
| 497 | |
---|
[2636] | 498 | } |
---|
| 499 | |
---|
[3459] | 500 | /** |
---|
| 501 | \brief initializes a new World |
---|
| 502 | */ |
---|
| 503 | ErrorMessage World::init() |
---|
| 504 | { |
---|
| 505 | this->bPause = false; |
---|
| 506 | CommandNode* cn = Orxonox::getInstance()->getLocalInput(); |
---|
| 507 | cn->addToWorld(this); |
---|
| 508 | cn->enable(true); |
---|
[2636] | 509 | |
---|
[3459] | 510 | //glMap1f (GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &ctrlpoints[0][0]); |
---|
| 511 | //glEnable (GL_MAP1_VERTEX_3); |
---|
| 512 | |
---|
| 513 | //theNurb = gluNewNurbsRenderer (); |
---|
| 514 | //gluNurbsProperty (theNurb, GLU_NURBS_MODE, GLU_NURBS_TESSELLATOR); |
---|
| 515 | //gluNurbsProperty (theNurb, GLU_NURBS_VERTEX, vertexCallback ); |
---|
| 516 | |
---|
| 517 | } |
---|
| 518 | |
---|
| 519 | |
---|
| 520 | /** |
---|
| 521 | \brief starts the World |
---|
| 522 | */ |
---|
| 523 | ErrorMessage World::start() |
---|
| 524 | { |
---|
| 525 | printf("World::start() - starting current World: nr %i\n", this->debugWorldNr); |
---|
| 526 | this->bQuitOrxonox = false; |
---|
| 527 | this->bQuitCurrentGame = false; |
---|
| 528 | this->mainLoop(); |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | /** |
---|
| 532 | \brief stops the world. |
---|
| 533 | |
---|
| 534 | This happens, when the player decides to end the Level. |
---|
| 535 | */ |
---|
| 536 | ErrorMessage World::stop() |
---|
| 537 | { |
---|
| 538 | printf("World::stop() - got stop signal\n"); |
---|
| 539 | this->bQuitCurrentGame = true; |
---|
| 540 | } |
---|
| 541 | |
---|
| 542 | /** |
---|
| 543 | \brief pauses the Game |
---|
| 544 | */ |
---|
| 545 | ErrorMessage World::pause() |
---|
| 546 | { |
---|
| 547 | this->isPaused = true; |
---|
| 548 | } |
---|
| 549 | |
---|
| 550 | /** |
---|
| 551 | \brief ends the pause Phase |
---|
| 552 | */ |
---|
| 553 | ErrorMessage World::resume() |
---|
| 554 | { |
---|
| 555 | this->isPaused = false; |
---|
| 556 | } |
---|
| 557 | |
---|
| 558 | /** |
---|
| 559 | \brief destroys the World |
---|
| 560 | */ |
---|
| 561 | ErrorMessage World::destroy() |
---|
| 562 | { |
---|
| 563 | delete trackManager; |
---|
| 564 | } |
---|
| 565 | |
---|
| 566 | /** |
---|
| 567 | \brief shows the loading screen |
---|
| 568 | */ |
---|
| 569 | void World::displayLoadScreen () |
---|
| 570 | { |
---|
| 571 | printf ("World::displayLoadScreen - start\n"); |
---|
| 572 | |
---|
| 573 | //GLMenuImageScreen* |
---|
| 574 | this->glmis = GLMenuImageScreen::getInstance(); |
---|
| 575 | this->glmis->init(); |
---|
| 576 | this->glmis->setMaximum(10); |
---|
| 577 | this->glmis->draw(); |
---|
| 578 | |
---|
| 579 | printf ("World::displayLoadScreen - end\n"); |
---|
| 580 | } |
---|
| 581 | |
---|
| 582 | /** |
---|
| 583 | \brief removes the loadscreen, and changes over to the game |
---|
| 584 | |
---|
| 585 | \todo take out the delay |
---|
| 586 | */ |
---|
| 587 | void World::releaseLoadScreen () |
---|
| 588 | { |
---|
| 589 | printf ("World::releaseLoadScreen - start\n"); |
---|
| 590 | this->glmis->setValue(this->glmis->getMaximum()); |
---|
| 591 | SDL_Delay(500); |
---|
| 592 | printf ("World::releaseLoadScreen - end\n"); |
---|
| 593 | } |
---|
| 594 | |
---|
| 595 | |
---|
[2636] | 596 | /** |
---|
[2551] | 597 | \brief checks for collisions |
---|
| 598 | |
---|
| 599 | This method runs through all WorldEntities known to the world and checks for collisions |
---|
| 600 | between them. In case of collisions the collide() method of the corresponding entities |
---|
| 601 | is called. |
---|
[1858] | 602 | */ |
---|
[2190] | 603 | void World::collide () |
---|
[1858] | 604 | { |
---|
[2816] | 605 | /* |
---|
| 606 | List *a, *b; |
---|
[2551] | 607 | WorldEntity *aobj, *bobj; |
---|
[2816] | 608 | |
---|
| 609 | a = entities; |
---|
[2551] | 610 | |
---|
| 611 | while( a != NULL) |
---|
| 612 | { |
---|
[2816] | 613 | aobj = a->nextElement(); |
---|
[2551] | 614 | if( aobj->bCollide && aobj->collisioncluster != NULL) |
---|
[2190] | 615 | { |
---|
[2816] | 616 | b = a->nextElement(); |
---|
[2551] | 617 | while( b != NULL ) |
---|
| 618 | { |
---|
[2816] | 619 | bobj = b->nextElement(); |
---|
[2551] | 620 | if( bobj->bCollide && bobj->collisioncluster != NULL ) |
---|
[2190] | 621 | { |
---|
[2551] | 622 | unsigned long ahitflg, bhitflg; |
---|
| 623 | if( check_collision ( &aobj->place, aobj->collisioncluster, |
---|
| 624 | &ahitflg, &bobj->place, bobj->collisioncluster, |
---|
| 625 | &bhitflg) ); |
---|
| 626 | { |
---|
| 627 | aobj->collide (bobj, ahitflg, bhitflg); |
---|
| 628 | bobj->collide (aobj, bhitflg, ahitflg); |
---|
| 629 | } |
---|
[2190] | 630 | } |
---|
[2816] | 631 | b = b->nextElement(); |
---|
[2551] | 632 | } |
---|
[2190] | 633 | } |
---|
[2816] | 634 | a = a->enumerate(); |
---|
[2551] | 635 | } |
---|
[2816] | 636 | */ |
---|
[1858] | 637 | } |
---|
| 638 | |
---|
| 639 | /** |
---|
[2551] | 640 | \brief runs through all entities calling their draw() methods |
---|
[1931] | 641 | */ |
---|
[2190] | 642 | void World::draw () |
---|
[2077] | 643 | { |
---|
[3462] | 644 | /* draw entities */ |
---|
[2551] | 645 | WorldEntity* entity; |
---|
[2822] | 646 | entity = this->entities->enumerate(); |
---|
[2816] | 647 | while( entity != NULL ) |
---|
[2551] | 648 | { |
---|
[2822] | 649 | if( entity->bDraw ) entity->draw(); |
---|
| 650 | entity = this->entities->nextElement(); |
---|
[3365] | 651 | } |
---|
[2551] | 652 | |
---|
[2731] | 653 | glCallList (objectList); |
---|
[3419] | 654 | //! \todo skysphere is a WorldEntity and should be inside of the world-entity-list. |
---|
| 655 | skySphere->draw(); |
---|
| 656 | |
---|
[3456] | 657 | testFont->printText(0, 0, 1, "orxonox_" PACKAGE_VERSION); |
---|
[3455] | 658 | |
---|
[1931] | 659 | } |
---|
| 660 | |
---|
[2816] | 661 | |
---|
[2190] | 662 | /** |
---|
[3225] | 663 | \brief function to put your own debug stuff into it. it can display informations about |
---|
| 664 | the current class/procedure |
---|
| 665 | */ |
---|
[2640] | 666 | void World::debug() |
---|
| 667 | { |
---|
[3365] | 668 | printf ("World::debug() - starting debug\n"); |
---|
| 669 | PNode* p1 = NullParent::getInstance (); |
---|
| 670 | PNode* p2 = new PNode (new Vector(2, 2, 2), p1); |
---|
| 671 | PNode* p3 = new PNode (new Vector(4, 4, 4), p1); |
---|
| 672 | PNode* p4 = new PNode (new Vector(6, 6, 6), p2); |
---|
| 673 | |
---|
| 674 | p1->debug (); |
---|
| 675 | p2->debug (); |
---|
| 676 | p3->debug (); |
---|
| 677 | p4->debug (); |
---|
| 678 | |
---|
| 679 | p1->shiftCoor (new Vector(-1, -1, -1)); |
---|
| 680 | |
---|
| 681 | printf("World::debug() - shift\n"); |
---|
| 682 | p1->debug (); |
---|
| 683 | p2->debug (); |
---|
| 684 | p3->debug (); |
---|
| 685 | p4->debug (); |
---|
| 686 | |
---|
| 687 | p1->update (1); |
---|
| 688 | |
---|
| 689 | printf ("World::debug() - update\n"); |
---|
| 690 | p1->debug (); |
---|
| 691 | p2->debug (); |
---|
| 692 | p3->debug (); |
---|
| 693 | p4->debug (); |
---|
| 694 | |
---|
| 695 | p2->shiftCoor (new Vector(-1, -1, -1)); |
---|
| 696 | p1->update (2); |
---|
| 697 | |
---|
| 698 | p1->debug (); |
---|
| 699 | p2->debug (); |
---|
| 700 | p3->debug (); |
---|
| 701 | p4->debug (); |
---|
| 702 | |
---|
| 703 | p2->setAbsCoor (new Vector(1,2,3)); |
---|
| 704 | |
---|
| 705 | |
---|
| 706 | p1->update (2); |
---|
| 707 | |
---|
| 708 | p1->debug (); |
---|
| 709 | p2->debug (); |
---|
| 710 | p3->debug (); |
---|
| 711 | p4->debug (); |
---|
| 712 | |
---|
| 713 | p1->destroy (); |
---|
| 714 | |
---|
| 715 | |
---|
| 716 | /* |
---|
[2640] | 717 | WorldEntity* entity; |
---|
| 718 | printf("counting all entities\n"); |
---|
[2816] | 719 | printf("World::debug() - enumerate()\n"); |
---|
| 720 | entity = entities->enumerate(); |
---|
| 721 | while( entity != NULL ) |
---|
[2640] | 722 | { |
---|
| 723 | if( entity->bDraw ) printf("got an entity\n"); |
---|
[2816] | 724 | entity = entities->nextElement(); |
---|
[2640] | 725 | } |
---|
[3365] | 726 | */ |
---|
[2640] | 727 | } |
---|
[2636] | 728 | |
---|
[2640] | 729 | |
---|
[3449] | 730 | /** |
---|
[3225] | 731 | \brief main loop of the world: executing all world relevant function |
---|
| 732 | |
---|
| 733 | in this loop we synchronize (if networked), handle input events, give the heart-beat to |
---|
| 734 | all other member-entities of the world (tick to player, enemies etc.), checking for |
---|
| 735 | collisions drawing everything to the screen. |
---|
| 736 | */ |
---|
[2636] | 737 | void World::mainLoop() |
---|
| 738 | { |
---|
[3365] | 739 | this->lastFrame = SDL_GetTicks (); |
---|
[3220] | 740 | printf("World::mainLoop() - Entering main loop\n"); |
---|
[3215] | 741 | while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* \todo implement pause */ |
---|
[2551] | 742 | { |
---|
[2636] | 743 | // Network |
---|
[3365] | 744 | this->synchronize (); |
---|
[2636] | 745 | // Process input |
---|
[3365] | 746 | this->handleInput (); |
---|
[3215] | 747 | if( this->bQuitCurrentGame || this->bQuitOrxonox) |
---|
| 748 | { |
---|
| 749 | printf("World::mainLoop() - leaving loop earlier...\n"); |
---|
| 750 | break; |
---|
| 751 | } |
---|
[2636] | 752 | // Process time |
---|
[3365] | 753 | this->timeSlice (); |
---|
[2636] | 754 | // Process collision |
---|
[3459] | 755 | this->collide (); |
---|
[2636] | 756 | // Draw |
---|
[3365] | 757 | this->display (); |
---|
[2816] | 758 | |
---|
[3365] | 759 | for( int i = 0; i < 5000000; i++) {} |
---|
| 760 | /* \todo this is to slow down the program for openGl Software emulator computers, reimplement*/ |
---|
[2551] | 761 | } |
---|
[3215] | 762 | printf("World::mainLoop() - Exiting the main loop\n"); |
---|
[1899] | 763 | } |
---|
| 764 | |
---|
[3459] | 765 | |
---|
[2190] | 766 | /** |
---|
[2636] | 767 | \brief synchronize local data with remote data |
---|
[1855] | 768 | */ |
---|
[2636] | 769 | void World::synchronize () |
---|
[1855] | 770 | { |
---|
[2636] | 771 | // Get remote input |
---|
| 772 | // Update synchronizables |
---|
[1855] | 773 | } |
---|
[2636] | 774 | |
---|
[3459] | 775 | |
---|
[2636] | 776 | /** |
---|
| 777 | \brief run all input processing |
---|
[3225] | 778 | |
---|
| 779 | the command node is the central input event dispatcher. the node uses the even-queue from |
---|
| 780 | sdl and has its own event-passing-queue. |
---|
[2636] | 781 | */ |
---|
[3225] | 782 | void World::handleInput () |
---|
[2636] | 783 | { |
---|
| 784 | // localinput |
---|
[3225] | 785 | CommandNode* cn = Orxonox::getInstance()->getLocalInput(); |
---|
[3216] | 786 | cn->process(); |
---|
[2636] | 787 | // remoteinput |
---|
| 788 | } |
---|
| 789 | |
---|
[3459] | 790 | |
---|
[2636] | 791 | /** |
---|
| 792 | \brief advance the timeline |
---|
[3225] | 793 | |
---|
| 794 | this calculates the time used to process one frame (with all input handling, drawing, etc) |
---|
| 795 | the time is mesured in ms and passed to all world-entities and other classes that need |
---|
| 796 | a heart-beat. |
---|
[2636] | 797 | */ |
---|
[3225] | 798 | void World::timeSlice () |
---|
[2636] | 799 | { |
---|
| 800 | Uint32 currentFrame = SDL_GetTicks(); |
---|
| 801 | if(!this->bPause) |
---|
| 802 | { |
---|
| 803 | Uint32 dt = currentFrame - this->lastFrame; |
---|
[2816] | 804 | |
---|
[2636] | 805 | if(dt > 0) |
---|
| 806 | { |
---|
| 807 | float fps = 1000/dt; |
---|
| 808 | printf("fps = %f\n", fps); |
---|
| 809 | } |
---|
| 810 | else |
---|
| 811 | { |
---|
[3225] | 812 | /* the frame-rate is limited to 100 frames per second, all other things are for |
---|
| 813 | nothing. |
---|
| 814 | */ |
---|
[3194] | 815 | printf("fps = 1000 - frame rate is adjusted\n"); |
---|
| 816 | SDL_Delay(10); |
---|
| 817 | dt = 10; |
---|
[2636] | 818 | } |
---|
[3459] | 819 | //this->timeSlice (dt); |
---|
[3500] | 820 | printf("testing trackNode: x:%f\n", TrackNode::getInstance()->absCoordinate.x); |
---|
| 821 | |
---|
[3459] | 822 | /* function to let all entities tick (iterate through list) */ |
---|
| 823 | WorldEntity* entity; |
---|
| 824 | float seconds = dt / 1000.0; |
---|
| 825 | this->nullParent->update (seconds); |
---|
| 826 | entity = entities->enumerate(); |
---|
| 827 | while( entity != NULL) |
---|
| 828 | { |
---|
| 829 | entity->tick (seconds); |
---|
| 830 | entity = entities->nextElement(); |
---|
| 831 | } |
---|
| 832 | skySphere->updatePosition(localCamera->absCoordinate); |
---|
| 833 | |
---|
| 834 | /* update tick the rest */ |
---|
[3225] | 835 | this->localCamera->timeSlice(dt); |
---|
[3433] | 836 | this->trackManager->tick(dt); |
---|
[2636] | 837 | } |
---|
| 838 | this->lastFrame = currentFrame; |
---|
| 839 | } |
---|
| 840 | |
---|
[3216] | 841 | |
---|
[2636] | 842 | /** |
---|
[3225] | 843 | \brief render the current frame |
---|
| 844 | |
---|
| 845 | clear all buffers and draw the world |
---|
[2636] | 846 | */ |
---|
| 847 | void World::display () |
---|
| 848 | { |
---|
| 849 | // clear buffer |
---|
| 850 | glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
---|
| 851 | // set camera |
---|
| 852 | this->localCamera->apply (); |
---|
| 853 | // draw world |
---|
| 854 | this->draw(); |
---|
| 855 | // draw HUD |
---|
[3365] | 856 | /* \todo draw HUD */ |
---|
[2636] | 857 | // flip buffers |
---|
| 858 | SDL_GL_SwapBuffers(); |
---|
[3365] | 859 | //SDL_Surface* screen = Orxonox::getInstance()->getScreen (); |
---|
| 860 | //SDL_Flip (screen); |
---|
[2636] | 861 | } |
---|
| 862 | |
---|
[2644] | 863 | |
---|
[3225] | 864 | /** |
---|
| 865 | \brief add and spawn a new entity to this world |
---|
| 866 | \param entity to be added |
---|
| 867 | */ |
---|
[2644] | 868 | void World::spawn(WorldEntity* entity) |
---|
| 869 | { |
---|
[3365] | 870 | if( this->nullParent != NULL && entity->parent == NULL) |
---|
| 871 | this->nullParent->addChild (entity); |
---|
[2816] | 872 | |
---|
[3365] | 873 | this->entities->add (entity); |
---|
| 874 | |
---|
[3233] | 875 | entity->postSpawn (); |
---|
[2816] | 876 | } |
---|
| 877 | |
---|
| 878 | |
---|
[3225] | 879 | /** |
---|
| 880 | \brief add and spawn a new entity to this world |
---|
| 881 | \param entity to be added |
---|
[3449] | 882 | \param absCoor At what coordinates to add this entity. |
---|
| 883 | \param absDir In which direction should it look. |
---|
[3225] | 884 | */ |
---|
[3365] | 885 | void World::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir) |
---|
[2816] | 886 | { |
---|
[3365] | 887 | entity->setAbsCoor (absCoor); |
---|
| 888 | entity->setAbsDir (absDir); |
---|
| 889 | |
---|
| 890 | if( this->nullParent != NULL && entity->parent == NULL) |
---|
| 891 | this->nullParent->addChild (entity); |
---|
| 892 | |
---|
[2816] | 893 | this->entities->add (entity); |
---|
[3365] | 894 | |
---|
[3233] | 895 | entity->postSpawn (); |
---|
[2644] | 896 | } |
---|
[2816] | 897 | |
---|
| 898 | |
---|
[3216] | 899 | |
---|
[3449] | 900 | /** |
---|
[3225] | 901 | \brief commands that the world must catch |
---|
| 902 | \returns false if not used by the world |
---|
| 903 | */ |
---|
[3216] | 904 | bool World::command(Command* cmd) |
---|
| 905 | { |
---|
| 906 | return false; |
---|
| 907 | } |
---|
[3365] | 908 | |
---|