Changeset 10158 in orxonox.OLD for branches/ai/src
- Timestamp:
- Jan 2, 2007, 9:47:28 PM (18 years ago)
- Location:
- branches/ai/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ai/src/ai/ai_module.h
r10138 r10158 14 14 inline void setEnemyList(std::vector<WorldEntity*>* enemyList){this->enemyList=enemyList;} 15 15 inline Vector getPosition(){return myWorldEntity->getAbsCoor();} 16 inline Vector getMovement(){return this->movement;} 16 17 inline void setDestination(Vector destination){this->destination=destination;} 18 inline void setDestinationMovement(Vector destinationMovement){this->destinationMovement=destinationMovement;} 17 19 18 20 protected: … … 21 23 std::vector<WorldEntity*>* enemyList; 22 24 Vector destination; 25 Vector destinationMovement; 26 Vector movement; 23 27 }; 24 28 -
branches/ai/src/ai/ai_swarm.cc
r10138 r10158 16 16 #include "ai_swarm.h" 17 17 #include "debug.h" 18 #include <stdio.h> 18 19 19 20 void AISwarm::process(float dt) 20 21 { 21 22 std::set<AIModule*>::iterator it; 22 it= swarmMembers.begin(); 23 Vector leaderPosition=(*it)->getPosition(); 24 (*it)->setDestination(destination); 25 (*it)->setEnemyList(enemyList); 26 (*it)->process(dt); 27 28 for (it++; it!= swarmMembers.end(); it++ ){ 29 (*it)->setDestination(leaderPosition); 23 Vector swarmPosition=this->getPosition(); 24 //std::cout << swarmPosition.x << " " << swarmPosition.z << "\n"; 25 26 float aMax=70.0f; 27 float vMax=1000.0f; 28 29 Vector correction=(destination-swarmPosition)-movement; 30 correction.y=0; 31 32 float correctionLen=correction.len(); 33 if(correctionLen>aMax*dt)correction=correction/correctionLen*aMax*dt; 34 35 //std::cout << angleRad(correction,movement) << "\n"; 36 movement+=correction; 37 38 float movementLen=movement.len(); 39 if(movementLen>vMax)movement=movement/movementLen*vMax; 40 41 42 for (it= swarmMembers.begin(); it!= swarmMembers.end(); it++ ){ 43 (*it)->setDestination(swarmPosition); 44 (*it)->setDestinationMovement(movement); 30 45 (*it)->setEnemyList(enemyList); 31 46 (*it)->process(dt); -
branches/ai/src/ai/ai_swarm.h
r10138 r10158 19 19 private: 20 20 Vector destination; 21 Vector movement; 21 22 std::vector<WorldEntity*>* enemyList; 22 23 std::set<AIModule*> swarmMembers; -
branches/ai/src/ai/ai_team.cc
r10138 r10158 19 19 void AITeam::process(float dt) 20 20 { 21 //int x; 22 //int z; 23 //Vector random; 24 21 25 std::map<int,AISwarm*>::iterator it; 22 26 for (it= swarms.begin(); it!= swarms.end(); it++ ){ 27 28 //x = 20*(rand()%10 + 1)-100; 29 //z = 20*(rand()%10 + 1)-100; 30 //random=Vector(x,0,z); 31 23 32 it->second->setEnemyList(enemyList); 24 33 if(enemyList->size()>0) -
branches/ai/src/ai/movement_module.cc
r10138 r10158 202 202 Vector vectorToDestination=destination-myPosition; 203 203 204 Vector correction=playerCollision*50+npcCollision*50+vectorToDestination+Vector(0,0,0)-myMovement; 204 Vector correction= playerCollision*50*3 205 + npcCollision*50*3 206 + Vector(0,0,0) 207 + destinationMovement*2//-myMovement 208 + (vectorToDestination-myMovement)*3; 205 209 206 210 correction.y=0; … … 225 229 //myNPC->setAbsDir( Quaternion( view, Vector(0,1,0))); 226 230 myNPC->setAbsDirSoft( Quaternion( view, Vector(0,1,0)),3); 231 movement=myMovement; 227 232 } 228 233 -
branches/ai/src/lib/math/vector.h
r9110 r10158 114 114 * @return the angle between the vectors in radians 115 115 */ 116 inline float angle Deg(const Vector& v1, const Vector& v2) { return acos( v1 * v2 / (v1.len() * v2.len())); };116 inline float angleRad (const Vector& v1, const Vector& v2) { return acos( v1 * v2 / (v1.len() * v2.len())); }; 117 117 /** 118 118 * calculate the angle between two vectors in degrees … … 121 121 * @return the angle between the vectors in degrees 122 122 */ 123 inline float angle Rad(const Vector& v1, const Vector& v2) { return acos( v1 * v2 / (v1.len() * v2.len())) * 180/M_PI; };123 inline float angleDeg (const Vector& v1, const Vector& v2) { return acos( v1 * v2 / (v1.len() * v2.len())) * 180/M_PI; }; 124 124 125 125 /** an easy way to create a Random Vector @param sideLength the length of the Vector (x not sqrt(x^2...)) */
Note: See TracChangeset
for help on using the changeset viewer.