gwnavruntime/world/cylinderobstacle.h Source File

cylinderobstacle.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 // primary contact: LAPA - secondary contact: none
8 #ifndef Navigation_CylinderObstacle_H
9 #define Navigation_CylinderObstacle_H
10 
14 
15 
16 namespace Kaim
17 {
18 
19 class World;
20 class DatabaseBinding;
21 
22 
25 {
26  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_CylinderObstacle)
27 
28 public:
29  // ---------------------------------- Public Member Functions ----------------------------------
30 
32 
34  void SetDefaults()
35  {
36  m_world = KY_NULL;
38  m_navTag.Clear();
39  m_navTag.SetAsExclusive();
40  m_startPosition.Set(0.0f, 0.0f, 0.0f);
41  m_userData = KY_NULL;
42  m_radius = 0.3f;
43  m_height = 1.8f;
44  }
45 
46 
47  // ---------------------------------- Public Data Members ----------------------------------
48 
50  World* m_world;
51 
55  Ptr<DatabaseBinding> m_databaseBinding;
56 
59  DynamicNavTag m_navTag;
60 
61  Vec3f m_startPosition;
62  void* m_userData;
63  KyFloat32 m_radius;
64  KyFloat32 m_height;
65 };
66 
67 
68 
78 class CylinderObstacle: public WorldElement
79 {
80  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_CylinderObstacle)
82 
83 public:
84  static WorldElementType GetStaticType() { return TypeCylinderObstacle; }
85  virtual WorldElementType GetType() const { return TypeCylinderObstacle; }
86 
87  virtual const char* GetTypeName() const { return "CylinderObstacle"; }
88 
89  // ---------------------------------- Main API Functions ----------------------------------
90 
93 
94  virtual ~CylinderObstacle();
95 
96 
102  void Init(const CylinderObstacleInitConfig& initConfig);
103 
106  void Clear();
107 
115  void AddToWorld();
116 
123  void RemoveFromWorld();
124 
125  void SetPosition(const Vec3f& position);
126  void SetVelocity(const Vec3f& velocity);
127 
137  void SetDoesTriggerTagVolume(bool triggerTagVolume);
138 
139 
140  // ---------------------------------- Getters ----------------------------------
141 
142  const DynamicNavTag& GetNavTag() const;
143  const SpatializedCylinder& GetSpatializedCylinder() const;
144  SpatializedCylinder& GetSpatializedCylinder();
145 
146  KyFloat32 GetRadius() const;
147  KyFloat32 GetHeight() const;
148  const Vec3f& GetPosition() const;
149  const Vec3f& GetVelocity() const;
150 
151  bool DoesTriggerTagVolume() const;
152  const TagVolume* GetTagVolume() const;
153  TagVolume::IntegrationStatus GetTagVolumeIntegrationStatus() const;
154 
155  const DatabaseBinding* GetDatabaseBinding() const;
156 
157 public: // internal
158  virtual void DoSendVisualDebug(VisualDebugServer& server, VisualDebugSendChangeEvent changeEvent); // Inherited from WorldElement
159 
160  // Updates the SpatializedCylinder position and velocity with the data provided
161  // in the CylinderObstacleUpdateConfig.
162  // Computes then the spatialization of the SpatializedCylinder.
163  void UpdateSpatialization();
164 
165 
166  // Setup the TagVolume with its DynamicNavTag and the contour that best fits the obstacle.
167  // This is called by TagVolumeTrigger when the CylinderObstacle is updated with
168  // DoesTriggerTagVolume set to true.
169  void SetupTagVolumeInitConfig(TagVolumeInitConfig& tagVolumeInitConfig);
170 
171  // Called when the TagVolume integration is complete. It invalidates all Db spatializations.
172  void OnTagVolumeIntegration();
173 
174 
175 private:
176  // ---------- Input ----------
177 
178  Vec3f m_position;
179  Vec3f m_velocity;
180  bool m_doesTriggerTagVolume;
181 
182  DynamicNavTag m_navTag;
183  Ptr<DatabaseBinding> m_databaseBinding;
184 
185  // ------- Obstacle state --------
186 
187  TagVolumeTrigger<CylinderObstacle> m_tagVolumeTrigger;
188  SpatializedCylinder m_spatializedCylinder;
189 };
190 
191 
192 KY_INLINE const DynamicNavTag& CylinderObstacle::GetNavTag() const { return m_navTag; }
193 
194 KY_INLINE SpatializedCylinder& CylinderObstacle::GetSpatializedCylinder() { return m_spatializedCylinder; }
195 KY_INLINE const SpatializedCylinder& CylinderObstacle::GetSpatializedCylinder() const { return m_spatializedCylinder; }
196 KY_INLINE KyFloat32 CylinderObstacle::GetRadius() const { return m_spatializedCylinder.GetRadius(); }
197 KY_INLINE KyFloat32 CylinderObstacle::GetHeight() const { return m_spatializedCylinder.GetHeight(); }
198 
199 KY_INLINE const Vec3f& CylinderObstacle::GetPosition() const { return m_position; }
200 KY_INLINE const Vec3f& CylinderObstacle::GetVelocity() const { return m_velocity; }
201 
202 KY_INLINE void CylinderObstacle::SetPosition(const Vec3f& position) { m_position = position; }
203 KY_INLINE void CylinderObstacle::SetVelocity(const Vec3f& velocity) { m_velocity = velocity; }
204 
205 KY_INLINE bool CylinderObstacle::DoesTriggerTagVolume() const { return m_doesTriggerTagVolume; }
206 KY_INLINE const TagVolume* CylinderObstacle::GetTagVolume() const { return m_tagVolumeTrigger.GetTagVolume(); }
207 KY_INLINE TagVolume::IntegrationStatus CylinderObstacle::GetTagVolumeIntegrationStatus() const { return m_tagVolumeTrigger.GetIntegrationStatus(); }
208 
209 KY_INLINE const DatabaseBinding* CylinderObstacle::GetDatabaseBinding() const { return m_databaseBinding; }
210 
211 KY_INLINE void CylinderObstacle::SetDoesTriggerTagVolume(bool doesTriggerTagVolume) { m_doesTriggerTagVolume = doesTriggerTagVolume; }
213 KY_INLINE void CylinderObstacle::OnTagVolumeIntegration()
214 {
215  m_spatializedCylinder.InvalidateAllDbSpatializations();
217 }
218 
219 
220 KY_INLINE void CylinderObstacle::UpdateSpatialization()
221 {
222  m_tagVolumeTrigger.Update(m_doesTriggerTagVolume);
223 
224  if (m_tagVolumeTrigger.GetIntegrationStatus() != TagVolume::IntegrationStatus_Integrated)
225  m_spatializedCylinder.UpdateSpatialization(m_position);
226  else
227  m_spatializedCylinder.SetPosition(m_position);
228 
229  m_spatializedCylinder.SetVelocity(m_velocity);
230 
232 }
233 
234 } // namespace Kaim
235 
236 #endif // Navigation_CylinderObstacle_H
Class used to provide TagVolume initialization parameters.
Definition: tagvolume.h:36
CylinderObstacles represent dynamic objects of your game engine that prevent your Bots from moving fr...
Definition: cylinderobstacle.h:87
void ForceSendAllVisualDebug()
Call this when something impacts all your visual debug data.
World * m_world
Mandatory: you must provide a World when calling CylinderObstacle::Init.
Definition: cylinderobstacle.h:59
void Set(KyFloat32 _x, KyFloat32 _y, KyFloat32 _z)
Sets the coordinates.
Definition: vec3f.h:52
DynamicNavTag m_navTag
This DynamicNavTag will be used to set up the TagVolume NavTag when the CylinderObstacle will trigger...
Definition: cylinderobstacle.h:68
void RemoveFromWorld()
Removes the CylinderObstacle from the World: it is removed from the simulation, it is no longer updat...
#define KY_NULL
Null value.
Definition: types.h:247
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:387
This class is a runtime container for Gameware Navigation WorldElements such as NavData, Bots, BoxObstacles, TagVolumes...
Definition: world.h:54
This class represents runtime-defined volumes with customized NavTag.
Definition: tagvolume.h:108
KyFloat32 GetHeight() const
Used only for visual debugging. Not relevant for navigation.
Definition: cylinderobstacle.h:234
void SetVelocity(const Vec3f &velocity)
The CylinderObstacle velocity expressed in meter per seconds.
Definition: cylinderobstacle.h:240
TagVolumeTrigger is dedicated to TagVolume creation / removal management.
Definition: tagvolumetrigger.h:25
DatabaseBinding is a collection of the databases to be used for world elements spatialization.
Definition: databasebinding.h:24
WorldElementType
Enumerates the WorldElement types.
Definition: worldelementtype.h:15
Ptr< DatabaseBinding > m_databaseBinding
Defines the Databases in which the CylinderObstacle will be spatialized.
Definition: cylinderobstacle.h:64
KyFloat32 GetHeight() const
Note: height is only used for visual debugging, it is not relevant for navigation.
Definition: spatializedcylinder.h:137
Base internal class used to represent elements that can be added to a World, such as instances of Dat...
Definition: worldelement.h:45
Definition: gamekitcrowddispersion.h:20
void AddToWorld()
Adds the CylinderObstacle to the World: it becomes active in the simulation, it is updated...
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
void SetDefaults()
Sets all members to their default value.
Definition: cylinderobstacle.h:39
The VisualDebugServer manages the sending of data to clients.
Definition: visualdebugserver.h:254
void SetDoesTriggerTagVolume(bool triggerTagVolume)
This information is copied and applied in the next World::Update.
Definition: cylinderobstacle.h:248
Internal representation of world elements, using a vertical cylinder shape.
Definition: spatializedcylinder.h:56
void Clear()
Prepares this instance for destruction or reuse; it sets all members to their default values...
Vec3f m_velocity
The CylinderObstacle velocity expressed in meter per seconds.
Definition: cylinderobstacle.h:212
void Init(const CylinderObstacleInitConfig &initConfig)
Sets m_world and allocates memory depending on m_databaseBinding but does not add the CylinderObstacl...
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43
This class defines a three-dimensional vector whose coordinates are stored using floating-point numbe...
Definition: vec3f.h:23
Class used to provide CylinderObstacle initialization parameters.
Definition: cylinderobstacle.h:24