Changeset 10071 in orxonox.OLD for branches/ai
- Timestamp:
- Dec 13, 2006, 6:59:23 PM (18 years ago)
- Location:
- branches/ai/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ai/src/ai/ai_team_member.cc
r10045 r10071 34 34 for(int i=0; i < moduleCount; i++ ) 35 35 { 36 std::cout << "Processing AIModule " << i << " (" << moduleCount << ")\n";36 //std::cout << "Processing AIModule " << i << " (" << moduleCount << ")\n"; 37 37 modules.at(i)->process(); 38 38 } … … 48 48 int teamNumber=aiEngine->newTeam(); 49 49 aiEngine->getTeam(teamNumber)->addMember(this); 50 50 51 MovementModule* nMod=new MovementModule; 51 nMod->process(); 52 modules.push_back(nMod); 53 modules.at(0)->process(); 52 addModule(nMod); 53 //nMod->testModule=nMod; 54 54 } 55 55 -
branches/ai/src/ai/movement_module.cc
r10045 r10071 19 19 #include "state.h" 20 20 #include "debug.h" 21 #include "player.h" 22 #include "playable.h" 23 #include "aabb.h" 24 #include "npcs/npc_test.h" 25 26 #include "shell_command.h" 27 /*SHELL_COMMAND(model, WorldEntity, loadModel) 28 ->describe("sets the Model of the WorldEntity") 29 ->defaultValues("models/ships/fighter.obj", 1.0f);*/ 30 21 31 22 32 //class AIEngine; … … 30 40 31 41 32 void MovementModule::process()42 float MovementModule::getSize(WorldEntity* object) 33 43 { 34 //float dt=AIEngine::getInstance()->dtS; 35 std::cout << "///////////////////Processing Movement Module/////////////////////\n"; 44 AABB* aabb = object->getModelAABB(); 45 Vector a = aabb->getAxisX(); 46 Vector b = aabb->getAxisY(); 47 Vector c = aabb->getAxisZ(); 36 48 37 //How does the Module know the AITeamMember it belongs to??38 //partialy solved...39 /*40 Vector absPosition = owner->getAbsCoor();49 float da=a.len(); 50 float db=b.len(); 51 float dc=c.len(); 52 float size; 41 53 42 PRINTF(0)(" npc abs coor: %f, %f, %f\n", absPosition.x, absPosition.y, absPosition.z); 54 if(da>db){ 55 size=(dc>da)?dc:da; 56 }else{ 57 size=(dc>db)?dc:db; 58 } 43 59 44 //Player* pl = State::getPlayer(); 45 /*Vector playerAbsPos = pl->getPlayable()->getAbsCoor(); 46 47 //PRINTF(0)(" player abs coor: %f, %f, %f\n", playerAbsPos.x, playerAbsPos.y, playerAbsPos.z); 48 49 50 // intelligent reaction 51 52 Vector distanceVector = playerAbsPos - absPosition; 53 distanceVector.normalize(); 54 55 float speed = 10.0f; 56 57 owner->shiftCoor( distanceVector * speed * dt);*/ 60 return size; 58 61 } 59 62 60 63 64 65 66 void MovementModule::process() 67 { 68 float dt=AIEngine::getInstance()->dtS; 69 if( owner == NULL) return; 70 Vector myAbsPos = owner->getAbsCoor(); 71 72 //PRINTF(0)(" NPC abs coor: %f, %f, %f\n", myAbsPos.x, myAbsPos.y, myAbsPos.z); 73 74 Player* pl = State::getPlayer(); 75 if( pl == NULL) return; 76 Vector playerAbsPos = pl->getPlayable()->getAbsCoor(); 77 78 //PRINTF(0)(" Player abs coor: %f, %f, %f\n", playerAbsPos.x, playerAbsPos.y, playerAbsPos.z); 79 80 //////////// 81 82 float a=50.0f; 83 float keepDist= this->getSize(owner);//+ this->getSize(pl->getPlayable()); 84 std::cout << "Distance: " << keepDist << "\n"; 85 86 87 Vector vectorToPlayer = playerAbsPos - myAbsPos; 88 float dist=vectorToPlayer.len(); 89 Vector nVectorToPlayer=vectorToPlayer/dist*(dist-keepDist); 90 91 92 93 94 95 // std::vector<Vector> collisonCorrection; 96 // get all npcs 97 98 Vector tempNPCpos; 99 Vector tempCorrectionVect; 100 Vector antiCollision; 101 102 for (ObjectList<NPC2>::const_iterator it = NPC2::objectList().begin(); 103 it != NPC2::objectList().end(); 104 ++it) 105 { 106 if(*it==owner)continue; 107 tempNPCpos=(*it)->getAbsCoor(); 108 tempCorrectionVect = myAbsPos-tempNPCpos; 109 tempCorrectionVect=tempCorrectionVect*1/(tempCorrectionVect.len()); 110 //PRINTF(0)("class: %s\n", (*it)->getCName()); 111 antiCollision=antiCollision+tempCorrectionVect; 112 } 113 114 115 116 Vector correction=antiCollision+nVectorToPlayer-v; 117 //Vector nCorrection= 118 correction.y=0; 119 float correctionLen=correction.len(); 120 if(correctionLen>a*dt)correction=correction/correctionLen*a*dt; 121 v+=correction; 122 123 124 //Move NPC... 125 owner->shiftCoor(v*dt); 126 127 //Rotate NPC 128 Vector view = v+correction; 129 //if(vectorToPlayer.dot(view)<0){ 130 //view = v.cross( Vector(0,1,0) ).getNormalized(); 131 //}else{ 132 view = v.cross( Vector(0,-1,0) ).getNormalized(); 133 //} 134 //if(dist<keepDist)view=view*-1; 135 owner->setAbsDir( Quaternion( view, Vector(0,1,0))); 136 //owner->setAbsDirSoft( Quaternion( view, Vector(0,1,0)),1.5); 137 } 138 139 -
branches/ai/src/ai/movement_module.h
r10045 r10071 4 4 5 5 #include "ai_module.h" 6 #include "player.h" 7 #include "playable.h" 6 8 7 9 class MovementModule : public AIModule{ … … 11 13 virtual void process(); 12 14 private: 13 //AITeamMember* owner; 15 Vector v; 16 float getSize(WorldEntity* object); 14 17 }; 15 18 -
branches/ai/src/world_entities/npcs/npc_test.cc
r10045 r10071 61 61 { 62 62 // animating the md2 model 63 if( likely(this->getModel(0) != NULL))63 if( likely(this->getModel(0) != NULL) && this->getModel(0)->isA(MD2Model::staticClassID())) 64 64 ((MD2Model*)this->getModel(0))->tick(dt); 65 65 }
Note: See TracChangeset
for help on using the changeset viewer.