VR-Forces 4.1.1 Class Documentation
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 
24 // orientation of the Leader Body.
26 {
27  KY_DEFINE_NEW_DELETE_OPERATORS
28 
29  /* The modFollowAgent creates and initializes an instance of this class to ensure that any Body that is removed
30  from the World is also un-registered from the modFollowAgent if it is the current Leader of the modFollowAgent.
31  \ingroup kyruntime_agents */
33  {
34  public:
35  /* Default constructor. */
36  WorldObserver() : m_followAgent(KY_NULL) {}
37 
38  /* Sets up the WorldObserver for use.
39  \param modFollowAgent The instance of the modFollowAgent whose Leader will be updated. */
40  void Initialize(modFollowAgent& followAgent) { m_followAgent = &followAgent; }
41 
42  virtual void OnActivateBody(Body& ) {}
43  /* This implementation of IWorldObserver::OnActivateBody() tests each Body removed from the World to see if
44  it matches the Leader Body of the modFollowAgent. If it is, the Leader Body of the modFollowAgent is reset to #KY_NULL. */
45  virtual void OnDeactivateBody(Body& body)
46  {
47  if (m_followAgent->GetLeader() == &body)
48  m_followAgent->SetLeader(KY_NULL);
49  }
50  protected:
52  };
53 
54 public:
58 
61 
64 
70  KyResult Initialize(Bot& bot, TimeManager::TaskId computeRealDestinationTaskId);
71 
73  void Clear();
74 
76  void ReInit();
77 
81  KyBool Think();
82 
86 
88  void SetLeader(Body* target);
89 
91  Body* GetLeader() const { return m_leaderBody;}
92 
97  void SetDistFromLeader (KyFloat32 distFromTarget);
98 
100  KyFloat32 GetDistFromLeader() const {return m_desiredDistFromLeader;}
101 
108  void SetAngleFromLeader(KyFloat32 angleFromTarget);
109 
111  KyFloat32 GetAngleFromLeader() const { return m_desiredAngleFromLeader; }
112 
118  void SetMinimalImportantMove(const KyFloat32 value);
119 
121  KyFloat32 GetMinimalImportantMove() const { return m_minimalImportantMove; }
122 
129  void SetSpeed(const KyFloat32 speed);
130 
132  KyFloat32 GetSpeed() const { return m_desiredSpeed; }
133 
138  void SetMaxTimeToReachIdealDestination(KyFloat32 interval);
139 
143 
145  const Vec3f& GetDestination() const { return m_destination.GetPosition(); }
146 
148  KyBool HasArrived() const { return m_hasArrived; }
149 
153 protected:
154  /* Compute the agent's destination to put them at the correct station
155  * offset from the leader. The station will be a position at the desired
156  * range and angle from the leader unless
157  * 1- this location cannot be seen from the leader; in which case the
158  * location is moved toward the leader until it is visible; or
159  * 2- path following fails; in which case path following is set to just
160  * move toward the leader and stop when it gets the desired distance
161  * away (regardless of angle).
162  */
163  void computeAndLockDestination(Vec3f &offsetPosNow);
164 
165  /* Checks if follow agent should recompute its destination.
166  * True if the desired destination has moved more than a threshold.
167  * We use leader direction of motion instead of heading if the leader
168  * is moving.
169  * Returns the current ideal offset position in offsetPosNow.*/
170  KyBool NeedRecomputation(Vec3f &offsetPosNow);
171 
172  /* If idealPos is not visible from the leader, then this function
173  * will move the destination position toward the leader until it is
174  * visible. This is called from computeAndLockDestination.*/
175  void computeVisibleDestination(Vec3f& idealPos);
176 
180 protected:
182 
185  Body* m_leaderBody; //< Accessor to Leader entity
186  KyFloat32 m_minDistBetweenAgents; //<Sum of radii of leader and this
187 
188  KyFloat32 m_desiredDistFromLeader; //< Follow instruction (distance from Leader)
189  KyFloat32 m_desiredAngleFromLeader; //< Follow instruction (angle from Leader)
190 
192  PointLockManager* m_pointLockManager; //< Pointer to point lock manager world
194 
196  TimeManager::TaskId m_computeRealDestinationTaskId; //< Id of
197  //ComputeRealDistance time-managed task
198  KyFloat32 m_computeRealDistTimer; //< This timer is used to force a minimal
199  //delay between two calls
200  KyFloat32 m_minimalIntervalToReevaluate; //< Minimal time to wait between
201  //two destination update
202  KyFloat32 m_maximalIntervalToReachDestination; //< Maximal time to reach an
203  //Ideal Destination
204  KyFloat32 m_timerToReach; //< time used to force a recomputation when agent
205  //take too much time to reach its ideal destination
206 
207  ActionTorsoRotate* m_torsoRotateAttr; //< Bot Torso Rotate Action, used to
209 
211  PointWrapper m_destination; //< Agent destination point.
212  PointInfo_NavTriangleId m_DestPointInfo; //< Ideal destination Mesh Point Info
213  KyBool m_hasArrived; //< A flag to know if the agent has arrived
214 
216  KyFloat32 m_desiredSpeed;//< Contains agents move speed
217  KyFloat32 m_leaderLastSpeed;//< The speed that the leader is moving;
219  KyBool m_useDistanceToLeaderMode;//< Agent cannot get to the desired
222  Vec3f m_lastIdealOffsetPos; //< The last computed ideal offset position,
224 
225 
226  /* MinimalImportantMove is a distance that determines whether the desired
227  offset position has moved enough to warrant a path following update.
228  The smaller this value is,
229  the more reactive the entity will be, but it will also perform more
230  computations to update its goal. */
232 
237  KyFloat32 m_currentMaxAccel;
238  KyFloat32 m_currentMaxDecel;
239 
240 };
241 
242 }

Document ID: Generated on Mon Apr 8 19:24:01 EDT 2013 from SVN revision 125877
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)