VR-Forces 4.3 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
modFollowAgent.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2012 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
6 #pragma once
7 
8 #include <vrfutil/soilFactors.h>
9 
11 #include <kyruntime.h>
12 
13 #include <kyruntime/pathfinding/pathfinder.h>
14 
15 
16 namespace Kaim
17 {
18 
19 class ActionTorsoRotate;
20 class PointLockManager;
21 
22 
27 {
28  KY_DEFINE_NEW_DELETE_OPERATORS
29 
30  /* The modFollowAgent creates and initializes an instance of this class to ensure that any Body that is removed
31  from the World is also un-registered from the modFollowAgent if it is the current Leader of the modFollowAgent.
32  \ingroup kyruntime_agents */
34  {
35  public:
36  /* Default constructor. */
37  WorldObserver() : m_followAgent(KY_NULL) {}
38 
39  /* Sets up the WorldObserver for use.
40  \param modFollowAgent The instance of the modFollowAgent whose Leader will be updated. */
41  void Initialize(modFollowAgent& followAgent) { m_followAgent = &followAgent; }
42 
43  virtual void OnActivateBody(Body& ) {}
44  /* This implementation of IWorldObserver::OnActivateBody() tests each Body removed from the World to see if
45  it matches the Leader Body of the modFollowAgent. If it is, the Leader Body of the modFollowAgent is reset to #KY_NULL. */
46  virtual void OnDeactivateBody(Body& body)
47  {
48  if (m_followAgent->GetLeader() == &body)
49  m_followAgent->SetLeader(KY_NULL);
50  }
51  protected:
53  };
54 
55 public:
59 
62 
64  ~modFollowAgent();
65 
71  KyResult Initialize(Bot& bot, TimeManager::TaskId computeRealDestinationTaskId);
72 
74  void Clear();
75 
77  void ReInit();
78 
82  KyBool Think();
83 
87 
89  void SetLeader(Body* target);
90 
92  Body* GetLeader() const { return m_leaderBody;}
93 
98  void SetDistFromLeader (KyFloat32 distFromTarget);
99 
101  KyFloat32 GetDistFromLeader() const {return m_desiredDistFromLeader;}
102 
109  void SetAngleFromLeader(KyFloat32 angleFromTarget);
110 
112  KyFloat32 GetAngleFromLeader() const { return m_desiredAngleFromLeader; }
113 
119  void SetMinimalImportantMove(const KyFloat32 value);
120 
122  KyFloat32 GetMinimalImportantMove() const { return m_minimalImportantMove; }
123 
130  void SetSpeed(const KyFloat32 speed);
131 
133  KyFloat32 GetSpeed() const { return m_desiredSpeed; }
134 
139  void SetMaxTimeToReachIdealDestination(KyFloat32 interval);
140 
144 
146  const Vec3f& GetDestination() const { return m_destination.GetPosition(); }
147 
149  KyBool HasArrived() const { return m_hasArrived; }
150 
154 protected:
155  /* Compute the agent's destination to put them at the correct station
156  * offset from the leader. The station will be a position at the desired
157  * range and angle from the leader unless
158  * 1- this location cannot be seen from the leader; in which case the
159  * location is moved toward the leader until it is visible; or
160  * 2- path following fails; in which case path following is set to just
161  * move toward the leader and stop when it gets the desired distance
162  * away (regardless of angle).
163  */
164  void computeAndLockDestination(Vec3f &offsetPosNow);
165 
166  /* Checks if follow agent should recompute its destination.
167  * True if the desired destination has moved more than a threshold.
168  * We use leader direction of motion instead of heading if the leader
169  * is moving.
170  * Returns the current ideal offset position in offsetPosNow.*/
171  KyBool NeedRecomputation(Vec3f &offsetPosNow);
172 
173  /* If idealPos is not visible from the leader, then this function
174  * will move the destination position toward the leader until it is
175  * visible. This is called from computeAndLockDestination.*/
176  void computeVisibleDestination(Vec3f& idealPos);
177 
181 protected:
183 
186  Body* m_leaderBody; //< Accessor to Leader entity
187  KyFloat32 m_minDistBetweenAgents; //<Sum of radii of leader and this
188 
189  KyFloat32 m_desiredDistFromLeader; //< Follow instruction (distance from Leader)
190  KyFloat32 m_desiredAngleFromLeader; //< Follow instruction (angle from Leader)
191 
193  PointLockManager* m_pointLockManager; //< Pointer to point lock manager world
195 
197  TimeManager::TaskId m_computeRealDestinationTaskId; //< Id of
198  //ComputeRealDistance time-managed task
199  KyFloat32 m_computeRealDistTimer; //< This timer is used to force a minimal
200  //delay between two calls
201  KyFloat32 m_minimalIntervalToReevaluate; //< Minimal time to wait between
202  //two destination update
203  KyFloat32 m_maximalIntervalToReachDestination; //< Maximal time to reach an
204  //Ideal Destination
205  KyFloat32 m_timerToReach; //< time used to force a recomputation when agent
206  //take too much time to reach its ideal destination
207 
208  ActionTorsoRotate* m_torsoRotateAttr; //< Bot Torso Rotate Action, used to
210 
212  PointWrapper m_destination; //< Agent destination point.
213  PointInfo_NavTriangleId m_DestPointInfo; //< Ideal destination Mesh Point Info
214  KyBool m_hasArrived; //< A flag to know if the agent has arrived
215 
217  KyFloat32 m_desiredSpeed;//< Contains agents move speed
218  KyFloat32 m_leaderLastSpeed;//< The speed that the leader is moving;
220  KyBool m_useDistanceToLeaderMode;//< Agent cannot get to the desired
223  Vec3f m_lastIdealOffsetPos; //< The last computed ideal offset position,
225 
226 
227  /* MinimalImportantMove is a distance that determines whether the desired
228  offset position has moved enough to warrant a path following update.
229  The smaller this value is,
230  the more reactive the entity will be, but it will also perform more
231  computations to update its goal. */
233 
238  KyFloat32 m_currentMaxAccel;
239  KyFloat32 m_currentMaxDecel;
240 
241 };
242 
243 }

Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)