gwnavruntime/world/cylinderobstacle.h Source File

cylinderobstacle.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 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 #pragma once
8 
12 
13 
14 namespace Kaim
15 {
16 
17 class World;
18 class DatabaseBinding;
19 
20 
23 {
24  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_CylinderObstacle)
25 
26 public:
27  // ------------------------------ Functions -----------------------------
28 
30 
32  void SetDefaults()
33  {
34  m_world = nullptr;
35  m_databaseBinding = nullptr;
36  m_navTag.Clear();
37  m_navTag.SetAsExclusive();
38  m_startPosition.Set(0.0f, 0.0f, 0.0f);
39  m_userData = nullptr;
40  m_radius = 0.3f;
41  m_height = 1.8f;
42  }
43 
44 
45  // ---------------------------------- Public Data Members ----------------------------------
46 
49 
53  Ptr<DatabaseBinding> m_databaseBinding;
54 
57  DynamicNavTag m_navTag;
58 
59  Vec3f m_startPosition;
60  void* m_userData;
61  KyFloat32 m_radius;
62  KyFloat32 m_height;
63 };
64 
65 
66 
77 {
78  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_CylinderObstacle)
80 
81 public:
82  static WorldElementType GetStaticType() { return TypeCylinderObstacle; }
83  virtual WorldElementType GetType() const { return TypeCylinderObstacle; }
84 
85  virtual const char* GetTypeName() const { return "CylinderObstacle"; }
86 
87  // ---------------------------------- Main API Functions ----------------------------------
88 
91 
92  virtual ~CylinderObstacle();
93 
94 
100  void Init(const CylinderObstacleInitConfig& initConfig);
101 
104  void Clear();
105 
113  void AddToWorld();
114 
121  void RemoveFromWorld();
122 
123  void SetPosition(const Vec3f& position);
124  void SetVelocity(const Vec3f& velocity);
125 
135  void SetDoesTriggerTagVolume(bool triggerTagVolume);
136 
137 
138  // ---------------------------------- Getters ----------------------------------
139 
140  const DynamicNavTag& GetNavTag() const;
141  const SpatializedCylinder& GetSpatializedCylinder() const;
142  SpatializedCylinder& GetSpatializedCylinder();
143 
144  KyFloat32 GetRadius() const;
145  KyFloat32 GetHeight() const;
146  const Vec3f& GetPosition() const;
147  const Vec3f& GetVelocity() const;
148 
149  bool DoesTriggerTagVolume() const;
150  const TagVolume* GetTagVolume() const;
151  TagVolume::IntegrationStatus GetTagVolumeIntegrationStatus() const;
152 
153  const DatabaseBinding* GetDatabaseBinding() const;
154 
155 public: // internal
156  virtual void DoSendVisualDebug(VisualDebugServer& server, VisualDebugSendChangeEvent changeEvent); // Inherited from WorldElement
157 
158  // Updates the SpatializedCylinder position and velocity with the data provided
159  // in the CylinderObstacleUpdateConfig.
160  // Computes then the spatialization of the SpatializedCylinder.
161  void UpdateSpatialization();
162 
163  // Setup the TagVolume with its DynamicNavTag and the contour that best fits the obstacle.
164  // This is called by TagVolumeTrigger when the CylinderObstacle is updated with
165  // DoesTriggerTagVolume set to true.
166  void SetupTagVolumeInitConfig(TagVolumeInitConfig& tagVolumeInitConfig);
167 
168  // Called when the TagVolume integration is complete. It invalidates all Db spatializations.
169  void OnTagVolumeIntegration();
170 
171 
172 private:
173  // ---------- Input ----------
174 
175  Vec3f m_position;
177  bool m_doesTriggerTagVolume;
178 
179  DynamicNavTag m_navTag;
180  Ptr<DatabaseBinding> m_databaseBinding;
181 
182  // ------- Obstacle state --------
183 
184  TagVolumeTrigger<CylinderObstacle> m_tagVolumeTrigger;
185  SpatializedCylinder m_spatializedCylinder;
186 };
187 
188 
189 KY_INLINE const DynamicNavTag& CylinderObstacle::GetNavTag() const { return m_navTag; }
190 
191 KY_INLINE SpatializedCylinder& CylinderObstacle::GetSpatializedCylinder() { return m_spatializedCylinder; }
192 KY_INLINE const SpatializedCylinder& CylinderObstacle::GetSpatializedCylinder() const { return m_spatializedCylinder; }
193 KY_INLINE KyFloat32 CylinderObstacle::GetRadius() const { return m_spatializedCylinder.GetRadius(); }
194 KY_INLINE KyFloat32 CylinderObstacle::GetHeight() const { return m_spatializedCylinder.GetHeight(); }
195 
196 KY_INLINE const Vec3f& CylinderObstacle::GetPosition() const { return m_position; }
197 KY_INLINE const Vec3f& CylinderObstacle::GetVelocity() const { return m_velocity; }
198 
199 KY_INLINE void CylinderObstacle::SetPosition(const Vec3f& position) { m_position = position; }
200 KY_INLINE void CylinderObstacle::SetVelocity(const Vec3f& velocity) { m_velocity = velocity; }
201 
202 KY_INLINE bool CylinderObstacle::DoesTriggerTagVolume() const { return m_doesTriggerTagVolume; }
203 KY_INLINE const TagVolume* CylinderObstacle::GetTagVolume() const { return m_tagVolumeTrigger.GetTagVolume(); }
204 KY_INLINE TagVolume::IntegrationStatus CylinderObstacle::GetTagVolumeIntegrationStatus() const { return m_tagVolumeTrigger.GetIntegrationStatus(); }
205 
206 KY_INLINE const DatabaseBinding* CylinderObstacle::GetDatabaseBinding() const { return m_databaseBinding; }
207 
208 KY_INLINE void CylinderObstacle::SetDoesTriggerTagVolume(bool doesTriggerTagVolume) { m_doesTriggerTagVolume = doesTriggerTagVolume; }
209 
210 KY_INLINE void CylinderObstacle::OnTagVolumeIntegration()
211 {
212  m_spatializedCylinder.InvalidateAllDbSpatializations();
214 }
215 
216 
217 
218 } // namespace Kaim
219 
TagVolumeInitConfig provides TagVolume initialization parameters.
Definition: tagvolume.h:34
CylinderObstacles represent dynamic objects of your game engine that prevent your Bots from moving fr...
Definition: cylinderobstacle.h:76
void ForceSendAllVisualDebug()
Call this when something impacts all your visual debug data.
Definition: worldelement.h:123
World * m_world
Mandatory: you must provide a World when calling CylinderObstacle::Init.
Definition: cylinderobstacle.h:48
void Set(KyFloat32 _x, KyFloat32 _y, KyFloat32 _z)
Sets {_x, _y, _z}.
Definition: vec3f.h:29
DynamicNavTag m_navTag
This DynamicNavTag will be used to set up the TagVolume NavTag when the CylinderObstacle will trigger...
Definition: cylinderobstacle.h:57
void RemoveFromWorld()
Removes the CylinderObstacle from the World: it is removed from the simulation, it is no longer updat...
Definition: cylinderobstacle.cpp:99
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:196
This class is a runtime container for Autodesk Navigation WorldElements such as NavData, Bots, BoxObstacles, TagVolumes...
Definition: world.h:52
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
This class represents runtime-defined volumes with customized NavTag.
Definition: tagvolume.h:119
KyFloat32 GetHeight() const
Used only for visual debugging. Not relevant for navigation.
Definition: cylinderobstacle.h:194
void SetVelocity(const Vec3f &velocity)
The CylinderObstacle velocity expressed in meter per seconds.
Definition: cylinderobstacle.h:200
TagVolumeTrigger is dedicated to TagVolume creation / removal management.
Definition: tagvolumetrigger.h:22
DatabaseBinding is a collection of the databases to be used for world elements spatialization.
Definition: databasebinding.h:21
WorldElementType
Enumerates the WorldElement types.
Definition: worldelementtype.h:13
Ptr< DatabaseBinding > m_databaseBinding
Defines the Databases in which the CylinderObstacle will be spatialized.
Definition: cylinderobstacle.h:53
KyFloat32 GetHeight() const
Note: height is only used for visual debugging, it is not relevant for navigation.
Definition: spatializedcylinder.h:106
Base internal class used to represent elements that can be added to a World, such as instances of Dat...
Definition: worldelement.h:41
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
void AddToWorld()
Adds the CylinderObstacle to the World: it becomes active in the simulation, it is updated...
Definition: cylinderobstacle.cpp:86
void SetDefaults()
Sets all members to their default value.
Definition: cylinderobstacle.h:32
void SetDoesTriggerTagVolume(bool triggerTagVolume)
This information is copied and applied in the next World::Update.
Definition: cylinderobstacle.h:208
Internal representation of world elements, using a vertical cylinder shape.
Definition: spatializedcylinder.h:44
void Clear()
Prepares this instance for destruction or reuse; it sets all members to their default values...
Definition: cylinderobstacle.cpp:75
Vec3f m_velocity
The CylinderObstacle velocity expressed in meter per seconds.
Definition: cylinderobstacle.h:176
void Init(const CylinderObstacleInitConfig &initConfig)
Sets m_world and allocates memory depending on m_databaseBinding but does not add the CylinderObstacl...
Definition: cylinderobstacle.cpp:36
float KyFloat32
float
Definition: types.h:32
3d vector using 32bits floating points.
Definition: vec3f.h:16
Class used to provide CylinderObstacle initialization parameters.
Definition: cylinderobstacle.h:22