Changeset 3365 in orxonox.OLD for orxonox/trunk/src/world.cc
- Timestamp:
- Jan 7, 2005, 1:14:33 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/world.cc
r3233 r3365 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 glmis = new GLMenuImageScreen(); 151 glmis->init(); 152 glmis->draw(); 153 154 printf ("World::displayLoadScreen - end\n"); 155 } 156 157 158 void World::releaseLoadScreen () 159 { 160 printf ("World::releaseLoadScreen - start\n"); 161 162 printf ("World::releaseLoadScreen - end\n"); 163 } 164 110 165 111 166 void World::load() 112 167 { 168 // BezierCurve* tmpCurve = new BezierCurve(); 113 169 if(this->debugWorldNr != -1) 114 170 { 171 trackManager = TrackManager::getInstance(); 172 trackManager->addPoint(Vector(0,-5,0)); 173 trackManager->addPoint(Vector(10,0,5)); 174 trackManager->addPoint(Vector(20,0,-5)); 175 trackManager->addPoint(Vector(30,0,5)); 176 trackManager->addPoint(Vector(40,0,5)); 177 trackManager->setDuration(.5); 178 trackManager->setSavePoint(); 179 trackManager->addPoint(Vector(50,10,10)); 180 trackManager->addPoint(Vector(60,0, 10)); 181 trackManager->addPoint(Vector(70,0, 10)); 182 trackManager->addPoint(Vector(80,0,-10)); 183 trackManager->addPoint(Vector(90,0,-10)); 184 trackManager->setDuration(.5); 185 trackManager->setSavePoint(); 186 trackManager->addPoint(Vector(110,0,5)); 187 trackManager->addPoint(Vector(120,0, 10)); 188 trackManager->addPoint(Vector(130,0, 10)); 189 trackManager->addPoint(Vector(140,0,-10)); 190 trackManager->addPoint(Vector(150,0,-10)); 191 trackManager->setDuration(.5); 192 int fork11, fork12, fork13, fork14; 193 trackManager->fork(4, &fork11, &fork12, &fork13, &fork14); 194 trackManager->workOn(fork11); 195 trackManager->addPoint(Vector(170, 0, -15)); 196 trackManager->addPoint(Vector(180, 0, -15)); 197 trackManager->workOn(fork12); 198 trackManager->addPoint(Vector(170, 0, 10)); 199 trackManager->addPoint(Vector(180, 0, 10)); 200 trackManager->addPoint(Vector(190,2,5)); 201 trackManager->addPoint(Vector(200,2,5)); 202 int fork21, fork22; 203 trackManager->fork(2, &fork21, &fork22); 204 trackManager->workOn(fork21); 205 trackManager->addPoint(Vector(220, 10,-10)); 206 trackManager->addPoint(Vector(230, 0,-10)); 207 trackManager->addPoint(Vector(240, 0, 2)); 208 trackManager->addPoint(Vector(250, 0, 0)); 209 trackManager->addPoint(Vector(260, 0, 5)); 210 trackManager->join(2, fork12, fork11); 211 trackManager->workOn(fork22); 212 trackManager->addPoint(Vector(220, -10,10)); 213 trackManager->addPoint(Vector(230, 0, 10)); 214 trackManager->addPoint(Vector(240, 0, 10)); 215 trackManager->addPoint(Vector(250, 0, 5)); 216 trackManager->workOn(fork13); 217 trackManager->addPoint(Vector(200,-10,5)); 218 trackManager->addPoint(Vector(250,-10,5)); 219 printf("fork14: %d\n", fork14); 220 trackManager->workOn(fork14); 221 trackManager->addPoint(Vector(200,15,0)); 222 trackManager->addPoint(Vector(210,0,10)); 223 224 225 226 trackManager->join(4, fork21, fork22, fork13, fork14); 227 228 /* 229 tmpCurve->addNode(Vector(10,0,-10)); 230 //tmpCurve->addNode(Vector(10,2,5)); 231 //tmpCurve->addNode(Vector(10,3,-5)); 232 // tmpCurve->addNode(Vector(10,1,5)); 233 tmpCurve->addNode(Vector(10,0,5)); 234 */ 115 235 switch(this->debugWorldNr) 116 236 { … … 123 243 case DEBUG_WORLD_0: 124 244 { 245 this->nullParent = NullParent::getInstance (); 246 this->nullParent->setName ("NullParent"); 247 125 248 // create some path nodes 126 249 this->pathnodes = new Vector[6]; … … 141 264 // !\todo old track-system has to be removed 142 265 266 //create helper for player 267 HelperParent* hp = new HelperParent (); 268 /* the player has to be added to this helper */ 269 143 270 // create a player 144 WorldEntity* myPlayer = new Player(); 145 this->spawn(myPlayer); 271 WorldEntity* myPlayer = new Player (); 272 myPlayer->setName ("player"); 273 this->spawn (myPlayer); 146 274 this->localPlayer = myPlayer; 147 275 148 276 // bind input 149 Orxonox *orx = Orxonox::getInstance ();277 Orxonox *orx = Orxonox::getInstance (); 150 278 orx->getLocalInput()->bind (myPlayer); 151 279 152 280 // bind camera 153 281 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(); 282 this->localCamera->setName ("camera"); 283 this->getCamera()->bind (myPlayer); 284 this->localPlayer->addChild (this->localCamera); 285 286 287 Vector* es = new Vector (50, 2, 0); 288 Quaternion* qs = new Quaternion (); 159 289 WorldEntity* env = new Environment(); 160 this->spawn(env, plc); 290 env->setName ("env"); 291 this->spawn(env, es, qs); 292 161 293 162 294 break; … … 164 296 case DEBUG_WORLD_1: 165 297 { 298 /* 299 this->testCurve = new UPointCurve(); 300 this->testCurve->addNode(Vector( 0, 0, 0)); 301 this->testCurve->addNode(Vector(10, 0, 5)); 302 this->testCurve->addNode(Vector(20, -5,-5)); 303 this->testCurve->addNode(Vector(30, 5, 10)); 304 this->testCurve->addNode(Vector(40, 0,-10)); 305 this->testCurve->addNode(Vector(50, 0,-10)); 306 */ 307 308 this->nullParent = NullParent::getInstance (); 309 this->nullParent->setName ("NullParent"); 310 166 311 // create some path nodes 167 312 this->pathnodes = new Vector[6]; … … 173 318 this->pathnodes[5] = Vector(30, 50, 0); 174 319 320 321 322 175 323 // create the tracks 176 324 this->tracklen = 6; … … 183 331 // create a player 184 332 WorldEntity* myPlayer = new Player(); 333 myPlayer->setName ("player"); 185 334 this->spawn(myPlayer); 186 335 this->localPlayer = myPlayer; … … 191 340 192 341 // bind camera 193 this->localCamera = new Camera(this); 342 this->localCamera = new Camera (this); 343 this->localCamera->setName ("camera"); 194 344 this->getCamera()->bind (myPlayer); 345 this->localPlayer->addChild (this->localCamera); 195 346 break; 196 347 } … … 212 363 213 364 int sizeX = 100; 214 int size Y= 80;365 int sizeZ = 80; 215 366 float length = 1000; 216 367 float width = 200; 217 368 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];369 float widthZ = float (width /sizeZ); 370 371 float height [sizeX][sizeZ]; 372 Vector normal_vectors[sizeX][sizeZ]; 222 373 223 374 224 375 for ( int i = 0; i<sizeX-1; i+=1) 225 for (int j = 0; j<size Y-1;j+=1)376 for (int j = 0; j<sizeZ-1;j+=1) 226 377 //height[i][j] = rand()/20046 + (j-25)*(j-25)/30; 227 378 #ifdef __WIN32__ … … 231 382 #endif 232 383 233 //Die H ügel ein wenig glätten384 //Die Huegel ein wenig glaetten 234 385 for (int h=1; h<2;h++) 235 386 for (int i=1;i<sizeX-2 ;i+=1 ) 236 for(int j=1;j<size Y-2;j+=1)387 for(int j=1;j<sizeZ-2;j+=1) 237 388 height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4; 238 389 239 390 //Berechnung von normalen Vektoren 240 241 391 for(int i=1;i<sizeX-2;i+=1) 242 for(int j=1;j<size Y-2 ;j+=1)392 for(int j=1;j<sizeZ-2 ;j+=1) 243 393 { 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]);394 Vector v1 = Vector (widthX*(1), height[i][j], widthZ*(j) ); 395 Vector v2 = Vector (widthX*(i-1), height[i-1][j], widthZ*(j)); 396 Vector v3 = Vector (widthX*(i), height[i][j+1], widthZ*(j+1)); 397 Vector v4 = Vector (widthX*(i+1), height[i+1][j], widthZ*(j)); 398 Vector v5 = Vector (widthX*(i), height[i][j-1], widthZ*(j-1)); 249 399 250 400 Vector c1 = v2 - v1; … … 253 403 Vector c4 = v5 - v1; 254 404 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);405 normal_vectors[i][j]=c1.cross(v3-v5)+c2.cross(v4-v2)+c3.cross(v5-v3)+c4.cross(v2-v4); 256 406 normal_vectors[i][j].normalize(); 257 407 } … … 259 409 int snowheight=3; 260 410 for ( int i = 0; i<sizeX; i+=1) 261 for (int j = 0; j<size Y;j+=1)411 for (int j = 0; j<sizeZ;j+=1) 262 412 { 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);413 Vector v1 = Vector (widthX*(i), height[i][j]-20, widthZ*(j) -width/2); 414 Vector v2 = Vector (widthX*(i+1), height[i+1][j]-20, widthZ*(j) -width/2); 415 Vector v3 = Vector (widthX*(i+1), height[i+1][j+1]-20, widthZ*(j+1)-width/2); 416 Vector v4 = Vector (widthX*(i), height[i][j+1]-20, widthZ*(j+1)-width/2); 267 417 float a[3]; 268 418 if(height[i][j]<snowheight){ … … 371 521 //draw track 372 522 glBegin(GL_LINES); 373 glColor3f(0 ,1,1);523 glColor3f(0.0, 1.0, 1.0); 374 524 for( int i = 0; i < tracklen; i++) 375 525 { … … 378 528 } 379 529 glEnd(); 530 531 /* 532 glBegin(GL_LINE_STRIP); 533 glColor3f(1.0, 5.0, 1.0); 534 for( int i = 0; i <= 30; i++) 535 { 536 glEvalCoord1f ((GLfloat) i/30.0); 537 } 538 glEnd(); 539 */ 540 541 trackManager->drawGraph(.01); 542 trackManager->debug(2); 543 delete trackManager; 544 545 /* 546 glBegin(GL_LINES); 547 float i; 548 for(i = 0.0; i<1; i+=.01) 549 { 550 printf("%f, %f, %f\n",tmpCurve->calcPos(i).x, tmpCurve->calcPos(i).y, tmpCurve->calcPos(i).z); 551 glVertex3f(tmpCurve->calcPos(i).x, tmpCurve->calcPos(i).y, tmpCurve->calcPos(i).z); 552 } 553 glEnd(); 554 */ 380 555 glEndList(); 381 556 } … … 430 605 void World::draw () 431 606 { 432 // draw geometry433 434 607 // draw entities 435 608 WorldEntity* entity; 436 437 609 entity = this->entities->enumerate(); 438 610 while( entity != NULL ) … … 440 612 if( entity->bDraw ) entity->draw(); 441 613 entity = this->entities->nextElement(); 442 } 443 444 614 } 615 616 //glmis = new GLMenuImageScreen(); 617 ///glmis->init(); 618 445 619 // draw debug coord system 446 620 glCallList (objectList); 447 448 621 449 622 } … … 459 632 void World::update () 460 633 { 634 /* 461 635 //List<WorldEntity> *l; 462 636 WorldEntity* entity; … … 477 651 t = loc->part; 478 652 479 /* check if entity has still a legal track-id */480 653 if( t >= tracklen ) 481 654 { … … 500 673 else 501 674 { 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 675 } 508 676 509 677 entity = entities->nextElement(); 510 678 } 511 679 */ 512 680 } 513 681 … … 522 690 float seconds = deltaT / 1000.0; 523 691 692 this->nullParent->update (seconds); 693 //this->nullParent->processTick (seconds); 694 524 695 entity = entities->enumerate(); 525 696 while( entity != NULL) … … 542 713 543 714 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 715 void World::setTrackLen(Uint32 len) 556 716 { … … 571 731 void World::debug() 572 732 { 573 //List<WorldEntity> *l; 733 printf ("World::debug() - starting debug\n"); 734 PNode* p1 = NullParent::getInstance (); 735 PNode* p2 = new PNode (new Vector(2, 2, 2), p1); 736 PNode* p3 = new PNode (new Vector(4, 4, 4), p1); 737 PNode* p4 = new PNode (new Vector(6, 6, 6), p2); 738 739 p1->debug (); 740 p2->debug (); 741 p3->debug (); 742 p4->debug (); 743 744 p1->shiftCoor (new Vector(-1, -1, -1)); 745 746 printf("World::debug() - shift\n"); 747 p1->debug (); 748 p2->debug (); 749 p3->debug (); 750 p4->debug (); 751 752 p1->update (1); 753 754 printf ("World::debug() - update\n"); 755 p1->debug (); 756 p2->debug (); 757 p3->debug (); 758 p4->debug (); 759 760 p2->shiftCoor (new Vector(-1, -1, -1)); 761 p1->update (2); 762 763 p1->debug (); 764 p2->debug (); 765 p3->debug (); 766 p4->debug (); 767 768 p2->setAbsCoor (new Vector(1,2,3)); 769 770 771 p1->update (2); 772 773 p1->debug (); 774 p2->debug (); 775 p3->debug (); 776 p4->debug (); 777 778 p1->destroy (); 779 780 781 /* 574 782 WorldEntity* entity; 575 576 783 printf("counting all entities\n"); 577 784 printf("World::debug() - enumerate()\n"); … … 582 789 entity = entities->nextElement(); 583 790 } 791 */ 584 792 } 585 793 … … 594 802 void World::mainLoop() 595 803 { 596 this->lastFrame = SDL_GetTicks ();804 this->lastFrame = SDL_GetTicks (); 597 805 printf("World::mainLoop() - Entering main loop\n"); 598 806 while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* \todo implement pause */ 599 807 { 600 808 // Network 601 synchronize();809 this->synchronize (); 602 810 // Process input 603 handleInput();811 this->handleInput (); 604 812 if( this->bQuitCurrentGame || this->bQuitOrxonox) 605 813 { … … 608 816 } 609 817 // Process time 610 t imeSlice();818 this->timeSlice (); 611 819 // Process collision 612 collision();820 this->collision (); 613 821 // Draw 614 display(); 615 616 for(int i = 0; i < 10000000; i++) {} 822 this->display (); 823 824 for( int i = 0; i < 5000000; i++) {} 825 /* \todo this is to slow down the program for openGl Software emulator computers, reimplement*/ 617 826 } 618 827 printf("World::mainLoop() - Exiting the main loop\n"); … … 701 910 this->draw(); 702 911 // draw HUD 912 /* \todo draw HUD */ 703 913 // flip buffers 704 914 SDL_GL_SwapBuffers(); 915 //SDL_Surface* screen = Orxonox::getInstance()->getScreen (); 916 //SDL_Flip (screen); 705 917 } 706 918 … … 723 935 void World::spawn(WorldEntity* entity) 724 936 { 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 } 937 if( this->nullParent != NULL && entity->parent == NULL) 938 this->nullParent->addChild (entity); 939 940 this->entities->add (entity); 941 740 942 entity->postSpawn (); 741 943 } … … 747 949 \param location where to add 748 950 */ 749 void World::spawn(WorldEntity* entity, Location* loc) 750 { 751 Location zeroLoc; 752 WorldEntity* owner; 951 void World::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir) 952 { 953 entity->setAbsCoor (absCoor); 954 entity->setAbsDir (absDir); 955 956 if( this->nullParent != NULL && entity->parent == NULL) 957 this->nullParent->addChild (entity); 958 753 959 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 } 960 767 961 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 } 962 } 963 792 964 793 965 … … 800 972 return false; 801 973 } 974 975 976 977 978 void World::swap (unsigned char &a, unsigned char &b) 979 { 980 unsigned char temp; 981 temp = a; 982 a = b; 983 b = temp; 984 }
Note: See TracChangeset
for help on using the changeset viewer.