Академический Документы
Профессиональный Документы
Культура Документы
Volha Kolchyna
Contents
1.The Goal ............................................................................................................................................... 3 2. Flocking System Research ............................................................................................................... 3
3. System Design ..................................................................................................................................... 6 3.1 Planning......................................................................................................................................... 6 3.2 Main classes design ....................................................................................................................... 6 3.3 Polices-based design ..................................................................................................................... 7 3.4 Classes Diagram ............................................................................................................................ 9 3.5 Advantages of Extendable Flocking System design ....................................................................... 10 4. Algorithms ..................................................................................................................................... 10 4.1 Spherical Rotation ....................................................................................................................... 10 4.2 Collision Avoidance ..................................................................................................................... 11 4.3 Reducing computational complexity ........................................................................................ 133 5.Screenshots........................................................................................................................................14 References............................................................................................................................................15
1. The Goal
The goal of this project is to create Extendable flocking system. Minimum requirements are: - Possibility to dynamically create entities; - Implementation of few types of behaviour (seek, flee, followLeader, etc.) - Obstacle avoidance; The idea is to design flexible and reusable system, which can be easily expanded to satisfy additional requirements.
Figure 2.1 Separation. (Reynolds, 1999) Alignment: Is a behaviour that describes the process of steering to match the velocity of an agent with its neighbours, see Figure 2.2. The mathematical description is the average velocity of the neighbours.
Figure 2.2 Alignment. (Reynolds, 1999) Cohesion: Refers to steering towards the average relative position of all the other agents in the flock), see Figure 2.3. This steering is responsible of causing a herd movement, by generating a tendency that all agents follow, thus herding together. Mathematical description -sum of the position of neighbours, divided by number of neighbours.
For Reynolds an agent has incomplete information regarding the all the entities within a flock. The averaged movement compensates for the restricted amount of information on each one the agents while allowing the movement of the herd as a unity. Reynolds extends his analysis to consider that an agent only requires information regarding the agents within its radius of perception. Originally Reynolds describes a sphere of perception and later adds a field of view, see Figure 2.4.
The scripted behaviour of the three basic steering forces is combined with obstacle avoidance to emulate the flock/herd movement, see Figure 2.5. Obstacles generate a steering force that directs the boids to the edge of the obstacle. It is mentioned that obstacle could be also bigger agent that move with their own script of steering forces.
Reynolds criticizes in his own work the difficulty of combining the forces adequately to generate the desired behaviour. Precisely because of this the adjustment of the behaviour to the desired level can be a time consuming. Definitely this is an area that has enough room for improvement.
Reynolds mentions that it is possible to extend his approach to include other behaviours: Flee, Seek, Pursuit, Evasion, Wander, Path Following, etc. This additional behaviour enriches the ethological model simulations proposed by the Reynolds papers. Taking the Reynlods framework as a starting point several authors have been working on different methods of either optimizing the herd interaction or reducing the calculation complexity. In this sense Le Bajec proposes weighting the steering behaviours to optimize the flock movements and the boids interaction during navigation. Treuille(2006) introduces the concept of individual potential fields instead of individual agent perception. By these means Treuille is looking to create global paths that combine local avoidance in to a combined calculation. This section briefly summarizes the key aspects of the Reynolds framework for flock systems and mentions areas of development by other authors or that can be developed.
3. System Design
3.1 Planning
The initial idea of the project is to develop design, which can be easily expanded to create simulations of different types of groups of autonomous characters. One example of application is simulation of ecosystem. In every ecosystem different types of organisms live together and interact. Every type of organisms can be presented in a system as a separate flock. This means, that to simulate real life environment, the system should support possibility to create multiple flocks in one simulation. The interaction between the members of one flock or members of different flocks can be implemented as various types of behaviour. The addition of new type of behaviour to the system should not require modification of the main classes.
Boid is a child class of MovingObject. All thinking characters are instances of this class. Objects of this class analyse the environment and calculate steeringForce to define the direction of next movement. Essential for flock behaviours such as Alignment, Cohesion and Separation are calculated within the class. Implementation of other types of behaviour is delegated to the policy classes. When all forces affecting the boid are defined, the final force is calculated taking in account the weight of each force. Then the properties of the boid are updated and it is redrawn. Flock class represents group of autonomous characters with common scripts. It has a list of all boids which are part of this flock, leader of the flock, list of behaviours which this flock perform, as well as list of weight for each type of behaviour. When the user changes the behaviour of the flock, create or delete boids, define a leader the modifications to the flock will be made according to the user choice. Environment is the class with information about all the entities in ecosystem/space. It contains list of all flocks and obstacles. There is possibility for the user to add/delete obstacles and flocks, change the size of environment.
BasicBehaviour class is a parent class for all possible types of behaviour. It has virtual method CalculateNavigationForce(* Boid), which will be overridden in child classes to provide various unique behaviours. Below is the code of how implementation may look like: class BasicBehaviour { public: virtual void CalculateNavigationForce (); // with parent implementation }; class SpecificBehaviour : public BasicBehaviour { public: virtual void CalculateNavigationForce (); // with child implementation }; ... class Flock { private: std::vector<BasicBehaviour*> m_behaviours; } //... m_behaviours.push_back(new SpecificBehaviour()); m_behaviours.push_back(new SpecificBehaviour2()); //... //After that any call to: m_behaviours[i]-> CalculateNavigationForce () //will call the actual child implementation
There is already existing project MetaAgent (Halleux, 2003), which simulates steering behaviour using policies. The author applies templates in his project and also creates totally different characters/agents by merging different policies: // agent will go round agent< point_mass_model, circle_move_behavior > circle_mover; // this agent will track a target agent< point_mass_model, seek_behavior > seeker;
MetaAgent implementation is limiting the agent to one type of behaviour at a time. In present project the inheritance from BasicBehaviour class is used, what allowed to create listOfNavigationBehaviours of parent type and perform numerous behaviours from this list by each agent.
4. Algorithms
4.1 Spherical Rotatio
When the boid is at the origin, it is required to rotate its position towards point U. the
R is the radial distance from the origin to U, is the angle between U and the xz-plane (latitude of point U) and lies in the interval /2 </2 is the azimuth of U and lies in the interval 0 <2 The relationships between Cartesian coordinates and spherical can be described as following: Ux = Rcos()cos(), Uy = Rsin(), Uz = Rcos()sin() R= , = arctan(Uz, Ux, ), = (Uy/R)
Arctan(y,x) =
This method has few drawbacks. One of them is that it does not allow to the boid to travel parallel or close to the surface. Another problem appears, when collision avoidance forces results in a force vector which points directly to the boid. In this situation no direction is defined for flock member to move. The collision avoidance method which is planned to be used in this project and provides better results is using bounding spheres to divert boids path around the obsticles. When flock member gets inside this bounding sphere of the object, its direction vector will be tested, see Figure 3.2.2. If the is a possibility of collision, method to redirect the boid should be executed.
Figure 4.2.2 Testing for potential collision with a bounding sphere. (Parent, 2002, p.403)
In order to avoid the collision the member of flock will be sent to the boundary point of the bounding sphere. To calculate that point the math from Figure 3.2.3 can be used.
Figure 4.2.3 Calculation of point B on the boundary of sphere. (Parent, 2002, p.403) 12
Figure 4.3 A query sphere inside the bin-lattice spatial data structure. (Reynolds, 2000)
This method allows to reduce the computation expense to O(n). As an alternative Reynolds considered also the use of Binary space partioning trees(BSP).
13
3. Screenshots
Figure 5.3
14
References
[1] Alexandrescu, A. (2001), Modern C++ Design: Generic Programming And Design Patterns Applied [2] Bajec, I., L., Zimic, N. and M. Mraz. The computational beauty of ocking: boids revisited. Mathematical and Computer Modelling of Dynamical Systems.
[3] Bourg, D . 2002. Physics for Game Developers. O'Reilly and Associates [4] Halleux, J.2003. MetaAgent, a Steering Behavior Template Library, Retrived on 17/10/2010 from http://www.codeproject.com/KB/library/metaagent.aspx [5] Macey J, 2003, E.B.P.L. USER GUIDE AND LANGUAGE REFERENCE, Retrved on 09/11/2010 from http://nccastaff.bournemouth.ac.uk/jmacey/MastersProjects/MyMSc/ebpluserguide.pdf [6] Parent R, 2002.Computer Animation Algorithms and Techniques, Morgan Kaufmann Publishers, San Francisco, USA [7] Reynolds, C. W. (1987), Flocks, herds and schools: A distributed behavioral model, ACM SIGGRAPH Computer Graphics, v.21 n.4, p.25-34 [8] Reynolds, C. W. (1999) Steering Behaviors For Autonomous Characters, in the proceedings of Game Developers Conference 1999 held in San Jose, California. Miller Freeman Game Group, San Francisco, California. Pages 763-782. [9] Reynolds, C. W. (2000) Interaction with Groups of Autonomous Characters, in the proceedings of Game Developers Conference 2000, CMP Game Media Group (formerly: Miller Freeman Game Group), San Francisco, California, pages 449-460. [10] Treuille, A., S. Cooper, and Z. Popovic.2006. Continuum crowds. In ACM SIGGRAPH 2006 Papers, page 1168. ACM.
15