Changeset 9919 in orxonox.OLD for branches/ODE/src/world_entities
- Timestamp:
- Nov 5, 2006, 9:07:04 PM (18 years ago)
- Location:
- branches/ODE/src/world_entities
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ODE/src/world_entities/creatures/fps_player.cc
r9869 r9919 39 39 40 40 #include "shared_network_data.h" 41 #include "terrain.h" 41 42 42 43 … … 167 168 168 169 //subscribe to collision reaction 169 this->subscribeReaction(CREngine::CR_PHYSICS_FULL_WALK, BspEntity::staticClassID()); 170 //this->subscribeReaction(CREngine::CR_PHYSICS_FULL_WALK, BspEntity::staticClassID()); 171 this->subscribeReaction(CREngine::CR_PHYSICS_FULL_WALK, Terrain::staticClassID()); 170 172 171 173 this->initWeapon = false; -
branches/ODE/src/world_entities/npcs/generic_npc.cc
r9869 r9919 32 32 33 33 #include "bsp_entity.h" 34 #include "terrain.h" 34 35 35 36 #include "class_id_DEPRECATED.h" … … 96 97 97 98 // collision reaction registration 98 this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, BspEntity::staticClassID()); 99 //this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, BspEntity::staticClassID()); 100 this->subscribeReaction(CREngine::CR_PHYSICS_FULL_WALK, Terrain::staticClassID()); 99 101 } 100 102 -
branches/ODE/src/world_entities/terrain.cc
r9877 r9919 24 24 25 25 #include "model.h" 26 #include "static_model.h" 27 #include "static_model_data.h" 26 28 #include "network_game_manager.h" 27 29 … … 33 35 #include "state.h" 34 36 #include "debug.h" 37 #include "aabb.h" 38 #include "cr_defs.h" 39 #include "cd_engine.h" 35 40 36 41 #include "class_id_DEPRECATED.h" 42 #include <ode/ode.h> 37 43 ObjectListDefinitionID(Terrain, CL_TERRAIN); 38 44 CREATE_FACTORY(Terrain); … … 43 49 Terrain::Terrain (const TiXmlElement* root) 44 50 { 51 this->loaded = false; 45 52 this->init(); 46 53 … … 49 56 this->loadParams(root); 50 57 58 59 if(this->getModel()) 60 { 61 62 StaticModelData::Pointer ModelData = ((StaticModel*)this->getModel())->dataPointer(); 63 //ModelData->buildTriangleList(); 64 65 PRINTF(0)(" Dieses Model hat %i Vertices \n", ModelData->getVertices().size()); 66 PRINTF(0)(" Dieses Model hat %i Dreiecke \n",((ModelData->getTriangles()).size() )); 67 this->Ind = new unsigned int [(ModelData->getTriangles()).size()*3]; 68 for(int i = 0 ; i < (ModelData->getTriangles()).size(); i++) 69 { 70 Ind[3*i] = (ModelData->getTrianglesExt())[i].indexToVertices[0] / 3 ; 71 Ind[3*i +1] = (ModelData->getTrianglesExt())[i].indexToVertices[1] / 3; 72 Ind[3*i +2] = (ModelData->getTrianglesExt())[i].indexToVertices[2] / 3; 73 74 } 75 76 //((StaticModel*)(this->getModel()))->acquireData(ModelData); 77 this->ODE_Geometry = dGeomTriMeshDataCreate(); 78 dGeomTriMeshDataBuildSingle(this->ODE_Geometry,&((ModelData->getVertices())[0]), 3*sizeof(float),(ModelData->getVertices().size() /3 ) , &Ind[0] ,((ModelData->getTriangles()).size() *3 ), 3*sizeof(unsigned int) ); 79 // Create ODE-Data here! 80 81 this->world = dWorldCreate(); 82 this->space = dSimpleSpaceCreate(0); 83 84 //!fixme 85 for (int i=0; i<30; i++) { 86 contact[i].surface.mode = dContactBounce | dContactSoftCFM; 87 contact[i].surface.mu = dInfinity; 88 contact[i].surface.mu2 = 0; 89 contact[i].surface.bounce = 0.1; 90 contact[i].surface.bounce_vel = 0.1; 91 contact[i].surface.soft_cfm = 0.01; 92 } 93 94 contactgroup = dJointGroupCreate (0); 95 dWorldSetGravity (world,0,0,-0.5); 96 dWorldSetCFM (world,1e-5); 97 98 this->ODE_Geom_ID = dCreateTriMesh(space,this->ODE_Geometry,0 , 0, 0); 99 100 101 CDEngine::getInstance()->setTerrain(this); 102 this->loaded = true; 103 this->toList(OM_ENVIRON); 104 } 51 105 // if (this->model != NULL) 52 106 //this->ssp = new SpatialSeparation((Model*)this->model, 10.0f); … … 62 116 Terrain::Terrain(const std::string& fileName) 63 117 { 118 this->loaded = false; 64 119 this->init(); 65 120 … … 67 122 { 68 123 this->loadModel(fileName); 124 125 69 126 } 70 127 else … … 112 169 113 170 this->heightMapMaterial = new Material(); 171 172 114 173 } 115 174 … … 428 487 return 0; 429 488 } 489 490 void Terrain::go() 491 { 492 PRINTF(0)("It's me! :-)"); 493 } 494 495 void Terrain::checkCollisionTerrain(WorldEntity* worldEntity) { 496 if(!this->loaded) return; 497 498 AABB* box = worldEntity->getModelAABB(); 499 dReal aabbox [6]; 500 501 if( box != NULL) 502 { 503 504 dGeomID RayX = dCreateRay(space,box->halfLength[0] *2.0f); 505 dGeomRaySet (RayX, worldEntity->getAbsCoor().x - box->halfLength[0] ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 506 1.0f, 0.0f, 0.0f); 507 dGeomID RayY = dCreateRay(space,box->halfLength[1] *2.0f); 508 dGeomRaySet (RayY, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y - box->halfLength[1], worldEntity->getAbsCoor().z, 509 0.0f, 1.0f, 0.0f); 510 dGeomID RayZ = dCreateRay(space,box->halfLength[2] *2.0f); 511 dGeomRaySet (RayZ, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z - box->halfLength[2], 512 0.0f, 0.0f, 1.0f); 513 514 dGeomID RayXPos = dCreateRay(space,box->halfLength[0]); 515 dGeomRaySet (RayX, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 516 1.0f, 0.0f, 0.0f); 517 dGeomID RayYPos = dCreateRay(space,box->halfLength[1] ); 518 dGeomRaySet (RayY, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 519 0.0f, 1.0f, 0.0f); 520 dGeomID RayZPos = dCreateRay(space,box->halfLength[2] ); 521 dGeomRaySet (RayZ, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 522 0.0f, 0.0f, 1.0f); 523 524 dGeomID RayXNeg = dCreateRay(space,box->halfLength[0] * 40.0f ); 525 dGeomRaySet (RayX, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 526 -1.0f, 0.0f, 0.0f); 527 dGeomID RayYNeg = dCreateRay(space,box->halfLength[1] ); 528 dGeomRaySet (RayY, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y , worldEntity->getAbsCoor().z, 529 0.0f, -1.0f, 0.0f); 530 dGeomID RayZNeg = dCreateRay(space,box->halfLength[2] ); 531 dGeomRaySet (RayZ, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z , 532 0.0f, 0.0f, -1.0f); 533 534 535 dGeomID BBOX = dCreateBox (space,box->halfLength[0]*2.0f, box->halfLength[1]*40.0f ,2.0f* box->halfLength[2]); 536 //dGeomSetPosition (BBOX, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z); 537 dGeomSetPosition (BBOX, worldEntity->getAbsCoor().x + box->center.x ,worldEntity->getAbsCoor().y+box->center.y, worldEntity->getAbsCoor().z+box->center.z); 538 539 540 541 542 int g; 543 bool collision = false; 544 545 546 // dGeomGetAABB (this->bspFile->ODE_Geom_IDs[i],aabbox ); 547 // BBOX2 = dCreateBox (space, aabbox[1]-aabbox[0], aabbox[3]-aabbox[2], aabbox[5]-aabbox[4]); 548 // dGeomSetPosition (BBOX2,(aabbox[1]+ aabbox[0])/2, (aabbox[3]+ aabbox[2])/2, (aabbox[4]+ aabbox[5])/2); 549 // dGeomDestroy(BBOX2); 550 g = 0; 551 if(true || dCollide(this->ODE_Geom_ID,BBOX, 10, &contact[0].geom, sizeof(dContact)) ) { 552 553 //PRINTF(0)("Collision \n"); 554 for(int i = 0; i <1 ; i++) 555 { 556 // worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this, worldEntity, Vector(0.0f, 1.0f, 0.0f), 557 // Vector(contact[i].geom.pos[0],contact[i].geom.pos[1],contact[i].geom.pos[2]), false); 558 } 559 560 if(dCollide(this->ODE_Geom_ID,RayX, 1, &contact[0].geom, sizeof(dContact))) { 561 if(dCollide(this->ODE_Geom_ID,RayXPos, 1, &contact[0].geom, sizeof(dContact))) { 562 worldEntity->registerCollision(COLLISION_TYPE_AXIS_X , this, worldEntity, Vector(1.0f, 0.0f, 0.0f), 563 Vector((float)contact[0].geom.pos[0],(float)contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 564 565 }//if 566 if(dCollide(this->ODE_Geom_ID,RayXNeg, 1, &contact[0].geom, sizeof(dContact))) { 567 worldEntity->registerCollision(COLLISION_TYPE_AXIS_X_NEG , this, worldEntity, Vector(1.0f, 0.0f, 0.0f), 568 Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 569 570 }//if 571 }//if 572 573 574 if(dCollide(this->ODE_Geom_ID,RayY, 1, &contact[0].geom, sizeof(dContact))) { 575 576 577 if(dCollide(this->ODE_Geom_ID,RayYNeg, 1, &contact[0].geom, sizeof(dContact))) { 578 worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this, worldEntity, Vector(0.0f, 1.0f, 0.0f), 579 Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 580 581 582 }//if 583 else if(dCollide(this->ODE_Geom_ID,RayYPos, 1, &contact[0].geom, sizeof(dContact))) { 584 worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this, worldEntity, Vector(0.0f, 1.0f, 0.0f), 585 Vector(contact[0].geom.pos[0],contact[0].geom.pos[1] ,contact[0].geom.pos[2]), false); 586 587 }//if 588 else { 589 590 worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this, worldEntity, Vector(0.0f, 1.0f, 0.0f), 591 Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 592 593 } 594 595 }//if 596 597 if(dCollide(this->ODE_Geom_ID,RayZ, 1, &contact[0].geom, sizeof(dContact))) { 598 if(dCollide(this->ODE_Geom_ID,RayZPos, 1, &contact[0].geom, sizeof(dContact))) { 599 // worldEntity->registerCollision(COLLISION_TYPE_AXIS_Z , this, worldEntity, Vector(0.0f, 0.0f, 1.0f), 600 // Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 601 602 }//if 603 if(dCollide(this->ODE_Geom_ID,RayZNeg, 1, &contact[0].geom, sizeof(dContact))) { 604 // worldEntity->registerCollision(COLLISION_TYPE_AXIS_Z_NEG , this, worldEntity, Vector(0.0f, 0.0f, 1.0f), 605 // Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 606 607 }//if 608 609 610 }//if 611 612 } //if 613 614 615 dGeomDestroy(RayX); 616 dGeomDestroy(RayY); 617 dGeomDestroy(RayZ); 618 dGeomDestroy(RayXPos); 619 dGeomDestroy(RayYPos); 620 dGeomDestroy(RayZPos); 621 dGeomDestroy(RayXNeg); 622 dGeomDestroy(RayYNeg); 623 dGeomDestroy(RayZNeg); 624 625 dGeomDestroy(BBOX); 626 } // if(bbox != 0) 627 628 } -
branches/ODE/src/world_entities/terrain.h
r9869 r9919 12 12 13 13 #include "world_entity.h" 14 #include <ode/ode.h> 14 15 15 16 // FORWARD DECLARATION … … 26 27 { 27 28 ObjectListDeclaration(Terrain); 28 29 29 30 public: 30 31 Terrain(const TiXmlElement* root = NULL); … … 32 33 Terrain(DebugTerrain debugTerrain); 33 34 virtual ~Terrain(); 35 36 void go(); 37 void checkCollisionTerrain(WorldEntity* worldEntity); /*!< WorldEntities use this function to check wheter they collided with the BspEntity. 38 If a collision has been detected, the collides-function of worldEntity will be called.*/ 34 39 35 40 void init(); … … 53 58 Model* vegetation; 54 59 int modelList; 55 60 bool loaded; 56 61 HeightMap* heightMap; 57 62 Material* heightMapMaterial; 58 63 Vector terrainScale; 64 unsigned int* Ind; 65 66 dTriMeshDataID ODE_Geometry; //!< ODE Geometry Data of the static model 67 dGeomID ODE_Geom_ID; //!< ID of ODE Geometry Data 68 dWorldID world; 69 dSpaceID space; 70 dJointGroupID contactgroup; 71 dContact contact[300]; 59 72 }; 60 73
Note: See TracChangeset
for help on using the changeset viewer.