AI_Agent.h

Go to the documentation of this file.
00001 #ifndef AI_AGENT_H
00002 #define AI_AGENT_H
00003 
00004 #include "AI_Global.h"
00005 #include "utils/AI_Node.h"
00006 #include "utils/AI_Referenced.h"
00007 #include "utils/AI_Ref.h"
00008 #include "spatialdb/AI_SDB_SpatialAABBTree.h"
00009 
00010 class AI_World;
00011 
00032 class AI_Agent : public AI_Node, public AI_Referenced
00033 {
00034 //*** Embedded
00035 public:
00037     enum TYPE {
00038         AGENT,      
00039         OBSTACLE,   
00040         ACTOR       
00041     };
00042 
00044     typedef AI_Array<AI_Agent*> AgentArray;
00046     typedef AgentArray::iterator AgentArrayIt;
00047 
00048 //*** Attributes
00049 protected:
00051     TYPE m_type;
00053     AI_Vector3 m_v_position;
00055     AI_Vector3 m_v_orientation;
00057     AI_World *m_ptr_world;
00059     bool m_b_enable;
00061     AI_Vector3 m_v_aura;
00063     AI_SDB_BBoxSpatialElement *m_ptr_spatial_element;
00065     void *m_ptr_user_data;
00066 
00067 //*** Methods
00068 public:
00069     //*** Constructor & destructor
00070     AI_Agent(void);
00071     AI_Agent(const TYPE type);
00072     ~AI_Agent();
00073 
00074     //*** Sets
00075     void setPosition( const AI_Vector3 &v_position );
00076     void setOrientation( const AI_Vector3 &v_orientation );
00077     void setAura( const AI_Vector3 &v_aura );
00078     void setSpatialElement( AI_SDB_BBoxSpatialElement *ptr_element );
00079     void setWorld( AI_World *ptr_world );
00080     void setUserData( void *ptr_user_data );
00081     virtual void setEnable( const bool b_enable );
00082 
00083     //*** Gets
00084     const TYPE &getType( void ) const;
00085     const AI_Vector3 &getPosition( void ) const;
00086     const AI_Vector3 &getOrientation( void ) const;
00087     const AI_Vector3 &getAura( void ) const;
00088     AI_SDB_BBoxSpatialElement *getSpatialElement( void );
00089     const bool isEnable( void ) const;
00090     AI_World *getWorld( void );
00091     void *getUserData( void );
00092     AgentArray &getNearAgents( const float f_distance );
00093 
00094     //*** Utils
00095     const float getDistance( const AI_Vector3 &v_position ) const;
00096     const bool isInRange( const AI_Agent *ptr_agent, const float f_range ) const;
00097     void move( void );
00098 };
00099 
00100 
00103 inline
00104 AI_Agent::AI_Agent(void) :
00105     m_type(AGENT),
00106     m_ptr_world(NULL),
00107     m_ptr_spatial_element(NULL),
00108     m_ptr_user_data(NULL),
00109     m_b_enable(false),
00110     m_v_aura(1.0f, 1.0f, 1.0f)
00111 {
00112 }
00113 
00114 
00117 inline
00118 AI_Agent::AI_Agent(const TYPE type) :
00119     m_type(type),
00120     m_ptr_world(NULL),
00121     m_ptr_spatial_element(NULL),
00122     m_ptr_user_data(NULL),
00123     m_b_enable(false),
00124     m_v_aura(1.0f, 1.0f, 1.0f)
00125 {
00126 }
00127 
00128 
00131 inline
00132 const AI_Agent::TYPE &AI_Agent::getType( void ) const
00133 {
00134     return m_type;
00135 }
00136 
00137 
00140 inline
00141 void AI_Agent::setOrientation( const AI_Vector3 &v_orientation )
00142 {
00143     m_v_orientation =  v_orientation;
00144 }
00145 
00146 
00149 inline
00150 void AI_Agent::setPosition( const AI_Vector3 &v_position )
00151 {
00152     m_v_position = v_position;
00153 }
00154 
00155 
00158 inline
00159 const AI_Vector3 &AI_Agent::getPosition( void ) const
00160 {
00161     return m_v_position;
00162 }
00163 
00164 
00167 inline
00168 const AI_Vector3 &AI_Agent::getOrientation( void ) const
00169 {
00170     return m_v_orientation;
00171 }
00172 
00173 
00176 inline
00177 const float AI_Agent::getDistance( const AI_Vector3 &v_position ) const
00178 {
00179     return ai_abs( (m_v_position-v_position).len() );
00180 }
00181 
00182 
00185 inline
00186 const bool AI_Agent::isInRange( const AI_Agent *ptr_agent, const float f_range ) const
00187 {
00188     float x_delta = ptr_agent->getPosition().x - m_v_position.x;
00189     float y_delta = ptr_agent->getPosition().z - m_v_position.z;
00190 
00191     return (f_range*f_range >= x_delta*x_delta + y_delta*y_delta);
00192 }
00193 
00194 
00197 inline
00198 void AI_Agent::setAura( const AI_Vector3 &v_aura )
00199 {
00200     m_v_aura = v_aura;
00201 }
00202 
00203 
00206 inline
00207 const AI_Vector3 &AI_Agent::getAura( void ) const
00208 {
00209     return m_v_aura;
00210 }
00211 
00212 
00215 inline
00216 void AI_Agent::setSpatialElement(AI_SDB_BBoxSpatialElement *ptr_element)
00217 {
00218     m_ptr_spatial_element = ptr_element;
00219 }
00220 
00221 
00224 inline
00225 AI_SDB_BBoxSpatialElement *AI_Agent::getSpatialElement( void )
00226 {
00227     return m_ptr_spatial_element;
00228 }
00229 
00230 
00236 inline
00237 const bool AI_Agent::isEnable(void) const
00238 {
00239     return m_b_enable;
00240 }
00241 
00242 
00245 inline
00246 void AI_Agent::setWorld( AI_World *ptr_world )
00247 {
00248     m_ptr_world = ptr_world;
00249 }
00250 
00251 
00254 inline
00255 AI_World *AI_Agent::getWorld( void )
00256 {
00257     return m_ptr_world;
00258 }
00259 
00260 
00265 inline
00266 void AI_Agent::setUserData( void *ptr_user_data )
00267 {
00268     m_ptr_user_data = ptr_user_data;
00269 }
00270 
00271 
00276 inline
00277 void *AI_Agent::getUserData( void )
00278 {
00279     return m_ptr_user_data;
00280 }
00281 
00282 
00287 inline
00288 void AI_Agent::setEnable( const bool b_enable )
00289 {
00290     if ( !b_enable || m_ptr_world )
00291         m_b_enable = b_enable;
00292 }
00293 
00294 #endif