|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionThis articles present MetaAgent, a C++ library for creating steering behaviors. ![]() Some history about behaviorsIn 1986, Craig Reynolds was writing boids, a computer model for animated animal motion, such as bird flocks and fish schools. He published a technical paper about it in [Craig Reynolds, 87]. His method was quite astonishing by it's simplicity since the model was based on 3 simple rules:
The resulting forces of these 3 rules were merged together by summing (with weighting) them together and applying to the boid. The Craig Reynolds boids have been and are still flying on his personnal web page[^]. Since then, Craig Reynolds has released another great paper [Craig Reynolds, 99] describing a number of behaviors to "give life" to autonomous characters: target seeking, obstacle avoidance, wandering, etc... MetaAgent and OpenSteerMetaAgent is not the only project around about steering behaviors. In fact it is the little sister of another project, OpenSteer initiated by Craig Reynolds. Why another library ?First of all, playing with autonomous characters is fun and is a great project if you plan to learn C++. That is basically how MetaAgent started: a playground for testing generic programming and meta-programming. The real reason for building another library was that OpenSteer was mainly a collection of C function wrapper into some C++ classes (ok I'm exagerating...). MetaAgent plans (and hopefully will succeed) to use the full power of the C++ and Generic Programming to create behaviors. MetaAgent guidelinesHere are the some of the guidelines that the project tries to follow:
Policies Class DesignI have run into Policy class design in the famous book of Andrei Alexandrescu
"Modern C++ design", see [Alexandrescu, 2001]. The basic idea is to assemble a
class with complex behavior by combining little classes ( called
Andrei Alexandrescu spends an entire chapter about the Policy design, I will try to illustrate it below on the agent-behavior creation. How an autonomous agent works ?The agent is basically a body (dynamics) that moves accordingly to his brain ( behavior ). It can be broken into several parts:
Building an agent using policiesPolicies decomposition"It is as if [some_host_class] acts as a little code generation engine and you configure the ways in which it generates code". Andrei Alexandrescu. Let's start by building the dynamic model of our agent. This body must be able to move and react to a steering force (that will be given by the behavior). As told previously, we want to use policies. So we want to decompose that model into orthogonal policies. Let's take a look at the fact that
![]() The dynamic model and the behavior can be seen as policies: template<
typename ModelPolicy,
typename BehaviorPolicy
>
class agent : public ModelPolicy, public BehaviorPolicy
As you can see, Determining the interfaceUnlike classic interfaces (collection of pure virtual methods), policies interfaces are loosely defined. Just use the policies methods in the host class without any prior declaration, if they are not defined in the policies classes, the compiler will fire an error. Hence, we simply write a method that makes the agent and think and act: template<
typename ModelPolicy,
typename BehaviorPolicy
>
class agent : public ModelPolicy, public BehaviorPolicy
{
public:
void think_and_act()
{
First step, think and compute the steering. This will be the job of the
// vec is some 2D vector
vec steering_force = think( get_acceleration(), get_velocity(), get_position() );
Second step, apply the computed steering force to the model and integrate the equations: act( steering_force ); // move according to the steering force -> ModelPolicy
};
};
Great, we have just defined the interface for Implementing the
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 05-20-2003 | Fixed image links to the new site |
| 05-12-2003 | Initial publication |
| [MetaAgent] | http://metaagent.sourceforge.net[^] |
| [Craig Reynolds, 87] | http://www.red3d.com/cwr/papers/1987/boids.html[^] |
| [Craig Reynolds, 99] | http://www.red3d.com/cwr/papers/1999/gdc99steer.html[^] |
| [OpenSteer] | http://opensteer.sourceforge.net[^] |
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms
of Use
Last Updated: 21 May 2003 Editor: |
Copyright 2003 by Jonathan de Halleux Everything else Copyright © CodeProject, 1999-2008 Web16 | Advertise on the Code Project |