Changeset 3399 in orxonox.OLD for orxonox/branches/nico/src/world.cc
- Timestamp:
- Feb 6, 2005, 11:27:25 PM (20 years ago)
- Location:
- orxonox/branches/nico
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/nico
- Property svn:externals set to
-
orxonox/branches/nico/src/world.cc
r3238 r3399 18 18 #include "world_entity.h" 19 19 #include "collision.h" 20 #include "track_manager.h" 20 21 #include "track.h" 21 22 #include "player.h" … … 23 24 #include "camera.h" 24 25 #include "environment.h" 26 #include "p_node.h" 27 #include "null_parent.h" 28 #include "helper_parent.h" 29 #include "glmenu_imagescreen.h" 25 30 26 31 using namespace std; … … 34 39 World::World (char* name) 35 40 { 41 this->setClassName ("World"); 36 42 this->worldName = name; 37 43 this->debugWorldNr = -1; … … 48 54 /** 49 55 \brief remove the World from memory 56 57 delete everything explicitly, that isn't contained in the parenting tree! 58 things contained in the tree are deleted automaticaly 50 59 */ 51 60 World::~World () … … 57 66 this->localCamera->destroy(); 58 67 68 this->nullParent->destroy (); 69 70 //delete this->trackManager; 71 72 /* 59 73 WorldEntity* entity = entities->enumerate(); 60 74 while( entity != NULL ) … … 64 78 } 65 79 this->entities->destroy(); 66 67 delete this->entities; 68 delete this->localCamera; 80 */ 81 82 /* FIX the parent list has to be cleared - not possible if we got the old list also*/ 83 84 85 //delete this->entities; 86 //delete this->localCamera; 69 87 /* this->localPlayer hasn't to be deleted explicitly, it is 70 88 contained in entities*/ 71 89 } 90 91 GLfloat ctrlpoints[4][3] = { 92 {20.0, 10.0, 5.0}, {40.0, -10.0, 0.0}, 93 {60.0, -10.0, 5.0}, {80.0, 10.0, 5.0}}; 72 94 73 95 … … 78 100 cn->addToWorld(this); 79 101 cn->enable(true); 80 } 102 103 //glMap1f (GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &ctrlpoints[0][0]); 104 //glEnable (GL_MAP1_VERTEX_3); 105 106 //theNurb = gluNewNurbsRenderer (); 107 //gluNurbsProperty (theNurb, GLU_NURBS_MODE, GLU_NURBS_TESSELLATOR); 108 //gluNurbsProperty (theNurb, GLU_NURBS_VERTEX, vertexCallback ); 109 110 } 111 112 81 113 82 114 ErrorMessage World::start() … … 99 131 } 100 132 133 101 134 ErrorMessage World::resume() 102 135 { … … 104 137 } 105 138 139 106 140 void World::destroy() 107 141 { 108 109 } 142 } 143 144 145 void World::displayLoadScreen () 146 { 147 printf ("World::displayLoadScreen - start\n"); 148 149 //GLMenuImageScreen* 150 this->glmis = new GLMenuImageScreen(); 151 this->glmis->init(); 152 this->glmis->setMaximum(10); 153 this->glmis->draw(); 154 155 printf ("World::displayLoadScreen - end\n"); 156 } 157 158 159 void World::releaseLoadScreen () 160 { 161 printf ("World::releaseLoadScreen - start\n"); 162 this->glmis->setValue(this->glmis->getMaximum()); 163 SDL_Delay(500); 164 printf ("World::releaseLoadScreen - end\n"); 165 } 166 110 167 111 168 void World::load() 112 169 { 170 // BezierCurve* tmpCurve = new BezierCurve(); 113 171 if(this->debugWorldNr != -1) 114 172 { 173 trackManager = TrackManager::getInstance(); 174 trackManager->addPoint(Vector(0,-5,0)); 175 trackManager->addPoint(Vector(10,0,5)); 176 trackManager->addPoint(Vector(20,0,-5)); 177 trackManager->addPoint(Vector(30,0,5)); 178 trackManager->addPoint(Vector(40,0,5)); 179 trackManager->setDuration(.5); 180 trackManager->setSavePoint(); 181 trackManager->addPoint(Vector(50,10,10)); 182 trackManager->addPoint(Vector(60,0, 10)); 183 trackManager->addPoint(Vector(70,0, 10)); 184 trackManager->addPoint(Vector(80,0,-10)); 185 trackManager->addPoint(Vector(90,0,-10)); 186 trackManager->setDuration(.5); 187 trackManager->setSavePoint(); 188 trackManager->addPoint(Vector(110,0,5)); 189 trackManager->addPoint(Vector(120,0, 10)); 190 trackManager->addPoint(Vector(130,0, 10)); 191 trackManager->addPoint(Vector(140,0,-10)); 192 trackManager->addPoint(Vector(150,0,-10)); 193 trackManager->setDuration(.5); 194 int fork11, fork12, fork13, fork14; 195 trackManager->fork(4, &fork11, &fork12, &fork13, &fork14); 196 trackManager->workOn(fork11); 197 trackManager->addPoint(Vector(170, 0, -15)); 198 trackManager->addPoint(Vector(180, 0, -15)); 199 trackManager->workOn(fork12); 200 trackManager->addPoint(Vector(170, 0, 10)); 201 trackManager->addPoint(Vector(180, 0, 10)); 202 trackManager->addPoint(Vector(190,2,5)); 203 trackManager->addPoint(Vector(200,2,5)); 204 int fork21, fork22; 205 trackManager->fork(2, &fork21, &fork22); 206 trackManager->workOn(fork21); 207 trackManager->addPoint(Vector(220, 10,-10)); 208 trackManager->addPoint(Vector(230, 0,-10)); 209 trackManager->addPoint(Vector(240, 0, 2)); 210 trackManager->addPoint(Vector(250, 0, 0)); 211 trackManager->addPoint(Vector(260, 0, 5)); 212 trackManager->join(2, fork12, fork11); 213 trackManager->workOn(fork22); 214 trackManager->addPoint(Vector(220, -10,10)); 215 trackManager->addPoint(Vector(230, 0, 10)); 216 trackManager->addPoint(Vector(240, 0, 10)); 217 trackManager->addPoint(Vector(250, 0, 5)); 218 trackManager->workOn(fork13); 219 trackManager->addPoint(Vector(200,-10,5)); 220 trackManager->addPoint(Vector(250,-10,5)); 221 printf("fork14: %d\n", fork14); 222 trackManager->workOn(fork14); 223 trackManager->addPoint(Vector(200,15,0)); 224 trackManager->addPoint(Vector(210,0,10)); 225 226 227 228 trackManager->join(4, fork21, fork22, fork13, fork14); 229 230 /*monitor progress*/ 231 this->glmis->step(); 232 233 /* 234 tmpCurve->addNode(Vector(10,0,-10)); 235 //tmpCurve->addNode(Vector(10,2,5)); 236 //tmpCurve->addNode(Vector(10,3,-5)); 237 // tmpCurve->addNode(Vector(10,1,5)); 238 tmpCurve->addNode(Vector(10,0,5)); 239 */ 115 240 switch(this->debugWorldNr) 116 241 { … … 123 248 case DEBUG_WORLD_0: 124 249 { 250 this->nullParent = NullParent::getInstance (); 251 this->nullParent->setName ("NullParent"); 252 125 253 // create some path nodes 126 254 this->pathnodes = new Vector[6]; … … 141 269 // !\todo old track-system has to be removed 142 270 271 //create helper for player 272 HelperParent* hp = new HelperParent (); 273 /* the player has to be added to this helper */ 274 143 275 // create a player 144 WorldEntity* myPlayer = new Player(); 145 this->spawn(myPlayer); 146 this->localPlayer = myPlayer; 276 WorldEntity* myPlayer = new Player (); 277 myPlayer->setName ("player"); 278 this->spawn (myPlayer); 279 this->localPlayer = myPlayer; 280 281 /*monitor progress*/ 282 this->glmis->step(); 147 283 148 284 // bind input 149 Orxonox *orx = Orxonox::getInstance ();285 Orxonox *orx = Orxonox::getInstance (); 150 286 orx->getLocalInput()->bind (myPlayer); 151 287 152 288 // bind camera 153 289 this->localCamera = new Camera(this); 154 this->getCamera()->bind (myPlayer); 155 156 Placement* plc = new Placement; 157 plc->r = Vector(100, 10, 10); 158 plc->w = Quaternion(); 290 this->localCamera->setName ("camera"); 291 this->getCamera()->bind (myPlayer); 292 this->localPlayer->addChild (this->localCamera); 293 294 /*monitor progress*/ 295 this->glmis->step(); 296 297 Vector* es = new Vector (50, 2, 0); 298 Quaternion* qs = new Quaternion (); 159 299 WorldEntity* env = new Environment(); 160 this->spawn(env, plc); 300 env->setName ("env"); 301 this->spawn(env, es, qs); 302 303 /*monitor progress*/ 304 this->glmis->step(); 161 305 162 306 break; … … 164 308 case DEBUG_WORLD_1: 165 309 { 310 /* 311 this->testCurve = new UPointCurve(); 312 this->testCurve->addNode(Vector( 0, 0, 0)); 313 this->testCurve->addNode(Vector(10, 0, 5)); 314 this->testCurve->addNode(Vector(20, -5,-5)); 315 this->testCurve->addNode(Vector(30, 5, 10)); 316 this->testCurve->addNode(Vector(40, 0,-10)); 317 this->testCurve->addNode(Vector(50, 0,-10)); 318 */ 319 320 this->nullParent = NullParent::getInstance (); 321 this->nullParent->setName ("NullParent"); 322 166 323 // create some path nodes 167 324 this->pathnodes = new Vector[6]; … … 173 330 this->pathnodes[5] = Vector(30, 50, 0); 174 331 332 333 334 175 335 // create the tracks 176 336 this->tracklen = 6; … … 183 343 // create a player 184 344 WorldEntity* myPlayer = new Player(); 345 myPlayer->setName ("player"); 185 346 this->spawn(myPlayer); 186 347 this->localPlayer = myPlayer; … … 191 352 192 353 // bind camera 193 this->localCamera = new Camera(this); 354 this->localCamera = new Camera (this); 355 this->localCamera->setName ("camera"); 194 356 this->getCamera()->bind (myPlayer); 357 this->localPlayer->addChild (this->localCamera); 195 358 break; 196 359 } … … 212 375 213 376 int sizeX = 100; 214 int size Y= 80;377 int sizeZ = 80; 215 378 float length = 1000; 216 379 float width = 200; 217 380 float widthX = float (length /sizeX); 218 float width Y = float (width /sizeY);219 220 float height [sizeX][size Y];221 Vector normal_vectors[sizeX][size Y];381 float widthZ = float (width /sizeZ); 382 383 float height [sizeX][sizeZ]; 384 Vector normal_vectors[sizeX][sizeZ]; 222 385 223 386 224 387 for ( int i = 0; i<sizeX-1; i+=1) 225 for (int j = 0; j<size Y-1;j+=1)388 for (int j = 0; j<sizeZ-1;j+=1) 226 389 //height[i][j] = rand()/20046 + (j-25)*(j-25)/30; 227 390 #ifdef __WIN32__ … … 231 394 #endif 232 395 233 //Die H ügel ein wenig glätten396 //Die Huegel ein wenig glaetten 234 397 for (int h=1; h<2;h++) 235 398 for (int i=1;i<sizeX-2 ;i+=1 ) 236 for(int j=1;j<size Y-2;j+=1)399 for(int j=1;j<sizeZ-2;j+=1) 237 400 height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4; 238 401 239 402 //Berechnung von normalen Vektoren 240 241 403 for(int i=1;i<sizeX-2;i+=1) 242 for(int j=1;j<size Y-2 ;j+=1)404 for(int j=1;j<sizeZ-2 ;j+=1) 243 405 { 244 Vector v1 = Vector (widthX*(1), widthY*(j) , height[i][j]);245 Vector v2 = Vector (widthX*(i-1), widthY*(j) , height[i-1][j]);246 Vector v3 = Vector (widthX*(i), widthY*(j+1), height[i][j+1]);247 Vector v4 = Vector (widthX*(i+1), widthY*(j), height[i+1][j]);248 Vector v5 = Vector (widthX*(i), widthY*(j-1), height[i][j-1]);406 Vector v1 = Vector (widthX*(1), height[i][j], widthZ*(j) ); 407 Vector v2 = Vector (widthX*(i-1), height[i-1][j], widthZ*(j)); 408 Vector v3 = Vector (widthX*(i), height[i][j+1], widthZ*(j+1)); 409 Vector v4 = Vector (widthX*(i+1), height[i+1][j], widthZ*(j)); 410 Vector v5 = Vector (widthX*(i), height[i][j-1], widthZ*(j-1)); 249 411 250 412 Vector c1 = v2 - v1; … … 253 415 Vector c4 = v5 - v1; 254 416 Vector zero = Vector (0,0,0); 255 normal_vectors[i][j]=c1.cross(v 4-v2)+c2.cross(v1-v3)+c3.cross(v2-v4)+c4.cross(v3-v1);417 normal_vectors[i][j]=c1.cross(v3-v5)+c2.cross(v4-v2)+c3.cross(v5-v3)+c4.cross(v2-v4); 256 418 normal_vectors[i][j].normalize(); 257 419 } … … 259 421 int snowheight=3; 260 422 for ( int i = 0; i<sizeX; i+=1) 261 for (int j = 0; j<size Y;j+=1)423 for (int j = 0; j<sizeZ;j+=1) 262 424 { 263 Vector v1 = Vector (widthX*(i), widthY*(j) -width/2, height[i][j]-20);264 Vector v2 = Vector (widthX*(i+1), widthY*(j) -width/2, height[i+1][j]-20);265 Vector v3 = Vector (widthX*(i+1), widthY*(j+1)-width/2, height[i+1][j+1]-20);266 Vector v4 = Vector (widthX*(i), widthY*(j+1)-width/2, height[i][j+1]-20);425 Vector v1 = Vector (widthX*(i), height[i][j]-20, widthZ*(j) -width/2); 426 Vector v2 = Vector (widthX*(i+1), height[i+1][j]-20, widthZ*(j) -width/2); 427 Vector v3 = Vector (widthX*(i+1), height[i+1][j+1]-20, widthZ*(j+1)-width/2); 428 Vector v4 = Vector (widthX*(i), height[i][j+1]-20, widthZ*(j+1)-width/2); 267 429 float a[3]; 268 430 if(height[i][j]<snowheight){ … … 371 533 //draw track 372 534 glBegin(GL_LINES); 373 glColor3f(0 ,1,1);535 glColor3f(0.0, 1.0, 1.0); 374 536 for( int i = 0; i < tracklen; i++) 375 537 { … … 378 540 } 379 541 glEnd(); 542 543 /* 544 glBegin(GL_LINE_STRIP); 545 glColor3f(1.0, 5.0, 1.0); 546 for( int i = 0; i <= 30; i++) 547 { 548 glEvalCoord1f ((GLfloat) i/30.0); 549 } 550 glEnd(); 551 */ 552 553 trackManager->drawGraph(.01); 554 trackManager->debug(2); 555 delete trackManager; 556 557 /* 558 glBegin(GL_LINES); 559 float i; 560 for(i = 0.0; i<1; i+=.01) 561 { 562 printf("%f, %f, %f\n",tmpCurve->calcPos(i).x, tmpCurve->calcPos(i).y, tmpCurve->calcPos(i).z); 563 glVertex3f(tmpCurve->calcPos(i).x, tmpCurve->calcPos(i).y, tmpCurve->calcPos(i).z); 564 } 565 glEnd(); 566 */ 380 567 glEndList(); 381 568 } … … 430 617 void World::draw () 431 618 { 432 // draw geometry433 434 619 // draw entities 435 620 WorldEntity* entity; 436 437 621 entity = this->entities->enumerate(); 438 622 while( entity != NULL ) … … 440 624 if( entity->bDraw ) entity->draw(); 441 625 entity = this->entities->nextElement(); 442 } 443 444 626 } 627 628 //glmis = new GLMenuImageScreen(); 629 ///glmis->init(); 630 445 631 // draw debug coord system 446 632 glCallList (objectList); 447 448 633 449 634 } … … 459 644 void World::update () 460 645 { 646 /* 461 647 //List<WorldEntity> *l; 462 648 WorldEntity* entity; … … 477 663 t = loc->part; 478 664 479 /* check if entity has still a legal track-id */480 665 if( t >= tracklen ) 481 666 { … … 500 685 else 501 686 { 502 /* \todo: implement check whether this particular free entity503 is out of the game area504 \todo: call function to notify the entity that it left505 the game area506 */507 687 } 508 688 509 689 entity = entities->nextElement(); 510 690 } 511 691 */ 512 692 } 513 693 … … 522 702 float seconds = deltaT / 1000.0; 523 703 704 this->nullParent->update (seconds); 705 //this->nullParent->processTick (seconds); 706 524 707 entity = entities->enumerate(); 525 708 while( entity != NULL) … … 542 725 543 726 544 545 /**546 \brief calls the correct mapping function to convert a given "look at"-Location to a547 Camera Placement548 */549 void World::calcCameraPos (Location* loc, Placement* plc)550 {551 track[loc->part].mapCamera (loc, plc);552 }553 554 555 727 void World::setTrackLen(Uint32 len) 556 728 { … … 571 743 void World::debug() 572 744 { 573 //List<WorldEntity> *l; 745 printf ("World::debug() - starting debug\n"); 746 PNode* p1 = NullParent::getInstance (); 747 PNode* p2 = new PNode (new Vector(2, 2, 2), p1); 748 PNode* p3 = new PNode (new Vector(4, 4, 4), p1); 749 PNode* p4 = new PNode (new Vector(6, 6, 6), p2); 750 751 p1->debug (); 752 p2->debug (); 753 p3->debug (); 754 p4->debug (); 755 756 p1->shiftCoor (new Vector(-1, -1, -1)); 757 758 printf("World::debug() - shift\n"); 759 p1->debug (); 760 p2->debug (); 761 p3->debug (); 762 p4->debug (); 763 764 p1->update (1); 765 766 printf ("World::debug() - update\n"); 767 p1->debug (); 768 p2->debug (); 769 p3->debug (); 770 p4->debug (); 771 772 p2->shiftCoor (new Vector(-1, -1, -1)); 773 p1->update (2); 774 775 p1->debug (); 776 p2->debug (); 777 p3->debug (); 778 p4->debug (); 779 780 p2->setAbsCoor (new Vector(1,2,3)); 781 782 783 p1->update (2); 784 785 p1->debug (); 786 p2->debug (); 787 p3->debug (); 788 p4->debug (); 789 790 p1->destroy (); 791 792 793 /* 574 794 WorldEntity* entity; 575 576 795 printf("counting all entities\n"); 577 796 printf("World::debug() - enumerate()\n"); … … 582 801 entity = entities->nextElement(); 583 802 } 803 */ 584 804 } 585 805 … … 594 814 void World::mainLoop() 595 815 { 596 this->lastFrame = SDL_GetTicks ();816 this->lastFrame = SDL_GetTicks (); 597 817 printf("World::mainLoop() - Entering main loop\n"); 598 818 while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* \todo implement pause */ 599 819 { 600 820 // Network 601 synchronize();821 this->synchronize (); 602 822 // Process input 603 handleInput();823 this->handleInput (); 604 824 if( this->bQuitCurrentGame || this->bQuitOrxonox) 605 825 { … … 608 828 } 609 829 // Process time 610 t imeSlice();830 this->timeSlice (); 611 831 // Process collision 612 collision();832 this->collision (); 613 833 // Draw 614 display(); 615 616 for(int i = 0; i < 10000000; i++) {} 834 this->display (); 835 836 for( int i = 0; i < 5000000; i++) {} 837 /* \todo this is to slow down the program for openGl Software emulator computers, reimplement*/ 617 838 } 618 839 printf("World::mainLoop() - Exiting the main loop\n"); … … 701 922 this->draw(); 702 923 // draw HUD 924 /* \todo draw HUD */ 703 925 // flip buffers 704 926 SDL_GL_SwapBuffers(); 927 //SDL_Surface* screen = Orxonox::getInstance()->getScreen (); 928 //SDL_Flip (screen); 705 929 } 706 930 … … 723 947 void World::spawn(WorldEntity* entity) 724 948 { 725 Location zeroloc; 726 Location* loc = NULL; 727 WorldEntity* owner; 728 729 entities->add (entity); 730 zeroloc.dist = 0; 731 zeroloc.part = 0; 732 zeroloc.pos = Vector(); 733 zeroloc.rot = Quaternion(); 734 loc = &zeroloc; 735 entity->init (loc, owner); 736 if (entity->bFree) 737 { 738 this->track[loc->part].mapCoords( loc, entity->getPlacement()); 739 } 949 if( this->nullParent != NULL && entity->parent == NULL) 950 this->nullParent->addChild (entity); 951 952 this->entities->add (entity); 953 740 954 entity->postSpawn (); 741 955 } … … 747 961 \param location where to add 748 962 */ 749 void World::spawn(WorldEntity* entity, Location* loc) 750 { 751 Location zeroLoc; 752 WorldEntity* owner; 963 void World::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir) 964 { 965 entity->setAbsCoor (absCoor); 966 entity->setAbsDir (absDir); 967 968 if( this->nullParent != NULL && entity->parent == NULL) 969 this->nullParent->addChild (entity); 970 753 971 this->entities->add (entity); 754 if( loc == NULL) 755 { 756 zeroLoc.dist = 0; 757 zeroLoc.part = 0; 758 zeroLoc.pos = Vector(); 759 zeroLoc.rot = Quaternion(); 760 loc = &zeroLoc; 761 } 762 entity->init (loc, owner); 763 if (entity->bFree) 764 { 765 this->track[loc->part].mapCoords( loc, entity->getPlacement()); 766 } 972 767 973 entity->postSpawn (); 768 //return entity; 769 } 770 771 772 /** 773 \brief add and spawn a new entity to this world 774 \param entity to be added 775 \param place where to be added 776 */ 777 void World::spawn(WorldEntity* entity, Placement* plc) 778 { 779 Placement zeroPlc; 780 WorldEntity* owner; 781 if( plc == NULL) 782 { 783 zeroPlc.r = Vector(); 784 zeroPlc.w = Quaternion(); 785 plc = &zeroPlc; 786 } 787 this->entities->add (entity); 788 entity->init (plc, owner); 789 entity->postSpawn (); 790 //return entity; 791 } 974 } 975 792 976 793 977 … … 800 984 return false; 801 985 } 986 987 988 989 990 void World::swap (unsigned char &a, unsigned char &b) 991 { 992 unsigned char temp; 993 temp = a; 994 a = b; 995 b = temp; 996 }
Note: See TracChangeset
for help on using the changeset viewer.