Changeset 2860 in orxonox.OLD for orxonox/branches/dave/src/world.cc
- Timestamp:
- Nov 15, 2004, 11:13:21 PM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/dave/src/world.cc
r2731 r2860 22 22 #include "command_node.h" 23 23 #include "camera.h" 24 #include "environment.h" 24 25 25 26 using namespace std; … … 35 36 this->worldName = name; 36 37 this->debugWorldNr = -1; 37 this->entities = new List<WorldEntity>();38 this->entities = new tList<WorldEntity>(); 38 39 } 39 40 … … 42 43 this->debugWorldNr = worldID; 43 44 this->worldName = NULL; 44 this->entities = new List<WorldEntity>();45 this->entities = new tList<WorldEntity>(); 45 46 } 46 47 … … 74 75 this->bQuitCurrentGame = true; 75 76 this->localCamera->setWorld(NULL); 77 this->entities->clear(); 78 Orxonox::getInstance()->get_localinput()->reset(); 76 79 this->~World(); 77 80 } … … 98 101 this->pathnodes = new Vector[6]; 99 102 this->pathnodes[0] = Vector(0, 0, 0); 100 this->pathnodes[1] = Vector( -100, 40, 0);101 this->pathnodes[2] = Vector(-100, 140, 0);102 this->pathnodes[3] = Vector(0, 180, 0);103 this->pathnodes[4] = Vector(100, 140, 0);104 this->pathnodes[5] = Vector(100, 40, 0);103 this->pathnodes[1] = Vector(1000, 0, 0); 104 // this->pathnodes[2] = Vector(-100, 140, 0); 105 // this->pathnodes[3] = Vector(0, 180, 0); 106 // this->pathnodes[4] = Vector(100, 140, 0); 107 // this->pathnodes[5] = Vector(100, 40, 0); 105 108 106 109 // create the tracks 107 this->tracklen = 6;108 this->track = new Track[ 6];110 this->tracklen = 2; 111 this->track = new Track[2]; 109 112 for( int i = 0; i < this->tracklen; i++) 110 113 { … … 113 116 114 117 // create a player 115 //WorldEntity* myPlayer = (WorldEntity*) this->spawn<Player>();116 118 WorldEntity* myPlayer = new Player(); 117 119 this->spawn(myPlayer); … … 125 127 this->localCamera = new Camera(this); 126 128 this->getCamera()->bind (myPlayer); 129 130 Placement* plc = new Placement; 131 plc->r = Vector(100, 10, 10); 132 plc->w = Quaternion(); 133 WorldEntity* env = new Environment(); 134 this->spawn(env, plc); 135 127 136 break; 128 137 } … … 174 183 glNewList (objectList, GL_COMPILE); 175 184 glLoadIdentity(); 185 glColor3f(1.0,0,0); 186 glBegin(GL_QUADS); 187 float height [500][50]; 188 Vector normal_vectors[500][50]; 189 float size = 2; 190 for(int i=0;i<400;i+=1){ 191 for(int j=0;j<50;j+=1){ 192 normal_vectors[i][j].x=0; 193 normal_vectors[i][j].y=1; 194 normal_vectors[i][j].z=0; 195 196 197 198 } 199 } 200 201 202 for ( int i = 0; i<400; i+=1) 203 { 204 for (int j = 0; j<50;j+=1) 205 { 206 //height[i][j] = rand()/20046 + (j-25)*(j-25)/30; 207 height[i][j]=(sin((float)j/3)*rand()*i/182400)*.2; 208 } 209 } 210 for(int a=0;a<2;a+=1){ 211 for (int i=1;i<399 ;i+=1 ){ 212 for(int j=1;j<49;j+=1){ 213 height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4; 214 215 } 216 } 217 } 218 //Berechnung von normalen Vektoren 219 220 for(int i=1;i<399;i+=1){ 221 for(int j=1;j<49 ;j+=1) 222 223 { 224 Vector* v1 = new Vector (size*i, size*(j-25), height[i][j]-20 ); 225 Vector* v2 = new Vector (size*(i+1), size*(j-25), height[i+1][j]-20); 226 Vector* v3 = new Vector (size*(i), size*(j-24), height[i][j+1]-20); 227 Vector* v4 = new Vector (size*(i-1), size*(j-25), height[i-1][j]-20); 228 Vector* v5 = new Vector (size*(i), size*(j-26), height[i][j-1]-20); 229 230 Vector c1 = *v1 - *v2; 231 Vector c2 = *v1 - *v3; 232 Vector c3= *v1 - *v4; 233 Vector c4 = *v1 - *v5; 234 normal_vectors[i][j]=c1.cross(*v1-*v3)+c2.cross(*v1-*v4)+c3.cross(*v1-*v5)+c4.cross(*v1-*v2); 235 normal_vectors[i][j].normalize(); 236 237 238 239 240 } 241 } 242 int snowheight=3; 243 for ( int i = 0; i<400; i+=1) 244 { 245 for (int j = 0; j<50;j+=1) 246 { 247 Vector* v1 = new Vector (size*i, size*(j-25), height[i][j]-20 ); 248 Vector* v2 = new Vector (size*(i+1), size*(j-25), height[i+1][j]-20); 249 Vector* v3 = new Vector (size*(i+1), size*(j-24), height[i+1][j+1]-20); 250 Vector* v4 = new Vector (size*(i), size*(j-24), height[i][j+1]-20); 251 float a[3]; 252 if(height[i][j]<snowheight){ 253 a[0]=0; 254 a[1]=1.0-height[i][j]/10-.3; 255 a[2]=0; 256 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 257 } 258 else{ 259 a[0]=1.0; 260 a[1]=1.0; 261 a[2]=1.0; 262 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 263 264 } 265 glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z); 266 glVertex3f(v1->x, v1->y, v1->z); 267 if(height[i+1][j]<snowheight){ 268 a[0]=0; 269 a[1] =1.0-height[i+1][j]/10-.3; 270 a[2]=0; 271 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 272 } 273 else{ 274 a[0]=1.0; 275 a[1]=1.0; 276 a[2]=1.0; 277 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 278 279 } 280 glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z); 281 glVertex3f(v2->x, v2->y, v2->z); 282 if(height[i+1][j+1]<snowheight){ 283 a[0]=0; 284 a[1] =1.0-height[i+1][j+1]/10-.3; 285 a[2]=0; 286 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 287 } 288 else{ 289 a[0]=1.0; 290 a[1]=1.0; 291 a[2]=1.0; 292 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 293 294 295 } 296 glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z); 297 glVertex3f(v3->x, v3->y, v3->z); 298 if(height[i][j+1]<snowheight){ 299 a[0]=0; 300 a[1] =1.0-height[i+1][j+1]/10-.3; 301 a[2]=0; 302 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 303 } 304 else{ 305 a[0]=1.0; 306 a[1]=1.0; 307 a[2]=1.0; 308 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 309 } 310 glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z); 311 glVertex3f(v4->x, v4->y, v4->z); 312 313 } 314 } 315 glEnd(); 316 /* 176 317 glBegin(GL_LINES); 177 178 318 for( float x = -128.0; x < 128.0; x += 25.0) 179 319 { … … 213 353 214 354 } 215 355 */ 216 356 //draw track 357 glBegin(GL_LINES); 217 358 glColor3f(0,1,1); 218 359 for( int i = 0; i < tracklen; i++) … … 235 376 void World::collide () 236 377 { 237 List<WorldEntity> *a, *b; 378 /* 379 List *a, *b; 238 380 WorldEntity *aobj, *bobj; 239 240 a = entities ->get_next();381 382 a = entities; 241 383 242 384 while( a != NULL) 243 385 { 244 aobj = a-> get_object();386 aobj = a->nextElement(); 245 387 if( aobj->bCollide && aobj->collisioncluster != NULL) 246 388 { 247 b = a-> get_next();389 b = a->nextElement(); 248 390 while( b != NULL ) 249 391 { 250 bobj = b-> get_object();392 bobj = b->nextElement(); 251 393 if( bobj->bCollide && bobj->collisioncluster != NULL ) 252 394 { … … 260 402 } 261 403 } 262 b = b-> get_next();404 b = b->nextElement(); 263 405 } 264 406 } 265 a = a->get_next(); 266 } 407 a = a->enumerate(); 408 } 409 */ 267 410 } 268 411 … … 275 418 276 419 // draw entities 277 List<WorldEntity> *l;278 420 WorldEntity* entity; 279 421 280 l = entities->get_next();281 while( l!= NULL )422 entity = this->entities->enumerate(); 423 while( entity != NULL ) 282 424 { 283 entity = l->get_object();284 425 if( entity->bDraw ) entity->draw(); 285 l = l->get_next();426 entity = this->entities->nextElement(); 286 427 } 287 428 … … 303 444 void World::update () 304 445 { 305 List<WorldEntity> *l;446 //List<WorldEntity> *l; 306 447 WorldEntity* entity; 307 448 Location* loc; … … 309 450 Uint32 t; 310 451 311 l = entities->get_next(); 312 while( l != NULL ) 452 // l = entities->enumerate(); 453 entity = this->entities->enumerate(); 454 while( entity != NULL ) 313 455 { 314 entity = l->get_object(); 456 315 457 316 458 if( !entity->isFree() ) … … 350 492 } 351 493 352 l = l->get_next();494 entity = entities->nextElement(); 353 495 } 354 496 … … 361 503 void World::time_slice (Uint32 deltaT) 362 504 { 363 List<WorldEntity> *l;505 //List<WorldEntity> *l; 364 506 WorldEntity* entity; 365 507 float seconds = deltaT; … … 367 509 seconds /= 1000; 368 510 369 l = entities->get_next();370 while( l!= NULL)511 entity = entities->enumerate(); 512 while( entity != NULL) 371 513 { 372 entity = l->get_object();373 514 entity->tick (seconds); 374 l = l->get_next();375 } 376 515 entity = entities->nextElement(); 516 } 517 377 518 for( int i = 0; i < tracklen; i++) track[i].tick (seconds); 378 519 } … … 411 552 void World::debug() 412 553 { 413 List<WorldEntity> *l;554 //List<WorldEntity> *l; 414 555 WorldEntity* entity; 415 556 416 557 printf("counting all entities\n"); 417 l = entities->get_next(); 418 while( l != NULL ) 558 printf("World::debug() - enumerate()\n"); 559 entity = entities->enumerate(); 560 while( entity != NULL ) 419 561 { 420 entity = l->get_object();421 562 if( entity->bDraw ) printf("got an entity\n"); 422 l = l->get_next();563 entity = entities->nextElement(); 423 564 } 424 565 } … … 445 586 // Draw 446 587 display(); 588 589 //for(int i = 0; i < 1000000; i++){} 590 447 591 } 448 592 printf("World|Exiting the main loop\n"); … … 477 621 { 478 622 Uint32 dt = currentFrame - this->lastFrame; 479 /*623 480 624 if(dt > 0) 481 625 { … … 485 629 else 486 630 { 487 printf("fps = 1000 \n");488 } 489 */631 printf("fps = 1000 but 0ms!\n"); 632 } 633 490 634 this->time_slice (dt); 491 635 this->update (); … … 545 689 Location* loc = NULL; 546 690 WorldEntity* owner; 547 //T* entity = new T(); 548 entities->add (entity, LIST_ADD_NEXT); 549 //if( loc == NULL) 550 //{ 551 zeroloc.dist = 0; 552 zeroloc.part = 0; 553 zeroloc.pos = Vector(); 554 zeroloc.rot = Quaternion(); 555 loc = &zeroloc; 556 //} 691 692 entities->add (entity); 693 zeroloc.dist = 0; 694 zeroloc.part = 0; 695 zeroloc.pos = Vector(); 696 zeroloc.rot = Quaternion(); 697 loc = &zeroloc; 557 698 entity->init (loc, owner); 558 699 if (entity->bFree) … … 561 702 } 562 703 entity->post_spawn (); 704 } 705 706 707 void World::spawn(WorldEntity* entity, Location* loc) 708 { 709 Location zeroLoc; 710 WorldEntity* owner; 711 this->entities->add (entity); 712 if( loc == NULL) 713 { 714 zeroLoc.dist = 0; 715 zeroLoc.part = 0; 716 zeroLoc.pos = Vector(); 717 zeroLoc.rot = Quaternion(); 718 loc = &zeroLoc; 719 } 720 entity->init (loc, owner); 721 if (entity->bFree) 722 { 723 this->track[loc->part].map_coords( loc, entity->get_placement()); 724 } 725 entity->post_spawn (); 563 726 //return entity; 564 727 } 728 729 730 void World::spawn(WorldEntity* entity, Placement* plc) 731 { 732 Placement zeroPlc; 733 WorldEntity* owner; 734 if( plc == NULL) 735 { 736 zeroPlc.r = Vector(); 737 zeroPlc.w = Quaternion(); 738 plc = &zeroPlc; 739 } 740 this->entities->add (entity); 741 entity->init (plc, owner); 742 entity->post_spawn (); 743 //return entity; 744 }
Note: See TracChangeset
for help on using the changeset viewer.