Successfully reported this slideshow.
Upcoming SlideShare
×

# 3장 자동적으로 움직이는 게임 에이전트 생성법_2

692 views

Published on

• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

### 3장 자동적으로 움직이는 게임 에이전트 생성법_2

1. 1. 집단 행동
2. 2. 집단 행동(group behavior) 기본적인 집단 행동 결합(cohesion) 분리(separation) 정렬(alignment) 집단 행동의 예 : 무리짓기 행동(flocking behavior) (새떼,물고기떼 등)- 결합(cohesion),분리(separation),정렬(alignment)의 조합 집단에 속하는 각 운반기(vehicle)의 조종힘(steering force)은 이 웃 반경(neighborhood radius) 내의 모든 운반기를 고려하여 결정 됨.
3. 3. 이웃 반경 tagging template <class T, class conT> void TagNeighbors(const T* entity, conT& ContainerOfEntities, double radius) { //iterate through all entities checking for range for (typename conT::iterator curEntity = ContainerOfEntities.begin(); curEntity != ContainerOfEntities.end();++curEntity) { //first clear any current tag (*curEntity)->UnTag(); Vector2D to = (*curEntity)->Pos() - entity->Pos(); //the bounding radius of the other is taken into account by adding it //to the range double range = radius + (*curEntity)->BRadius(); //if entity within range, tag for further consideration. (working in //distance-squared space to avoid sqrts) if ( ((*curEntity) != entity) && (to.LengthSq() < range*range)) { (*curEntity)->Tag(); } }//next entity } tip - tagging시 가시범위(field-of-view)를 제한 하는 것을 통한 사실감 향상
4. 4. 분리(separation) Vector2D SteeringBehaviors::Separation(const std::vector<Vehicle*>& neighbors) { Vector2D SteeringForce; for (int a=0; a<neighbors.size(); ++a) { //make sure this agent isn't included in the calculations and that //the agent being examined is close enough. if((neighbors[a] != m_pVehicle) && neighbors[a]->IsTagged()) { Vector2D ToAgent = m_pVehicle->Pos() - neighbors[a]->Pos(); //scale the force inversely proportional to the agent's distance //from its neighbor. SteeringForce += Vec2DNormalize(ToAgent)/ToAgent.Length(); } } return SteeringForce; }
5. 5. 정렬(alignment) Vector2D SteeringBehaviors::Alignment(const std::vector<Vehicle*>& neighbors) { //used to record the average heading of the neighbors Vector2D AverageHeading; //used to count the number of vehicles in the neighborhood int NeighborCount = 0 //iterate through all the tagged vehicles and sum their heading vectors for (int a=0; a<neighbors.size(); ++a) { //make sure *this* agent isn't included in the calculations and that //the agent being examined is close enough if((neighbors[a] != m_pVehicle) && neighbors[a]->IsTagged) { AverageHeading += neighbors[a]->Heading(); ++NeighborCount; } } //if the neighborhood contained one or more vehicles, average their //heading vectors. if (NeighborCount > 0) { AverageHeading /= (double)NeighborCount; AverageHeading -= m_pVehicle->Heading(); } return AverageHeading; }
6. 6. 결합(cohesion) Vector2D SteeringBehaviors::Cohesion(const std::vector<Vehicle*>& neighbors) { //first find the center of mass of all the agents Vector2D CenterOfMass, SteeringForce; int NeighborCount = 0; //iterate through the neighbors and sum up all the position vectors for (int a=0; a<neighbors.size(); ++a) { //make sure *this* agent isn't included in the calculations and that //the agent being examined is a neighbor if((neighbors[a] != m_pVehicle) && neighbors[a]->IsTagged()) { CenterOfMass += neighbors[a]->Pos(); ++NeighborCount; } } if (NeighborCount > 0) { //the center of mass is the average of the sum of positions CenterOfMass /= (double)NeighborCount; //now seek toward that position SteeringForce = Seek(CenterOfMass); } return SteeringForce; }
7. 7. 무리짓기? 떼지어 다니기?(flocking) 발현성 행동(emergent behavior) - 복잡하고 의도 된 mass game인 듯 보이지만, 실재로는 인접한 이웃의 정보만을 가지고 간단한 법칙으로 자연 발생적으로 나타나는 행동. 무리짓기 - 분리,정렬,결합의 조합. + 제한 된 시야(tagging range?)때문에 고립되는 걸 막기 위해 배 회하기 행동을 추가하는 것이 선호됨.
8. 8. 조종 행동들의 조합 (combining steering behaviors) 가중 절단된 합(Weighted Truncated Sum) 우선순위와 함께 가중 절단된 연속합 (Weighted Truncated Running Sum with Prioritization) 우선순위가 주어진 디더링(Prioritized Dithering)
9. 9. 가중 절단된 합(Weighted Truncated Sum) SVector2D Calculate() { SVector2D SteeringForce; SteeringForce += Wander() * dWanderAmount; SteeringForce += ObstacleAvoidance() * dObstacleAvoidanceAmount; SteeringForce += Separation() * dSeparationAmount; return SteeringForce.Truncate(MAX_STEERING_FORCE); } 문제점. 모든 활동들을 계산해야함으로 계산할 양이 많아 짐. 적절하게 parameter값을 조절 하는게 빡심.
10. 10. 우선순위와 함께 가중 절단된 연속합 (Weighted Truncated Running Sum with Prioritization) SVector2D SteeringBehaviors::Calculate() { //reset the force. m_vSteeringForce.Zero(); SVector2D force; if (On(wall_avoidance)) { force = WallAvoidance(m_pVehicle->World()->Walls()) *m_dMultWallAvoidance; if (!AccumulateForce(m_vSteeringForce, force)) return m_vSteeringForce; } if (On(obstacle_avoidance)){ force = ObstacleAvoidance(m_pVehicle->World()->Obstacles()) *m_dMultObstacleAvoidance; if (!AccumulateForce(m_vSteeringForce, force)) return m_vSteeringForce; } if (On(separation)){ force = Separation(m_pVehicle->World()->Agents()) *m_dMultSeparation; if (!AccumulateForce(m_vSteeringForce, force)) return m_vSteeringForce; } /* EXTRANEOUS STEERING FORCES OMITTED */ return m_vSteeringForce; } X 순서대로 힘에 붙일때까지만 행위들을 수행함.