gwnavruntime/world/boxobstacle.h Source File

boxobstacle.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 
8 
9 // primary contact: LAPA - secondary contact: NOBODY
10 #ifndef Navigation_BoxObstacle_H
11 #define Navigation_BoxObstacle_H
12 
13 
20 
21 
22 namespace Kaim
23 {
24 
25 class DatabaseBinding;
26 
27 
31 {
36 
41 };
42 
43 
47 {
48  BoxObstacleUp_X = 0,
49  BoxObstacleUp_Minus_X,
50  BoxObstacleUp_Y,
51  BoxObstacleUp_Minus_Y,
52  BoxObstacleUp_Z,
53  BoxObstacleUp_Minus_Z
54 };
55 
56 
59 {
60  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_BoxObstacle)
61 
62 public:
63  // ---------------------------------- Public Member Functions ----------------------------------
64 
66 
68  void SetDefaults()
69  {
70  m_world = KY_NULL;
72  m_navTag.Clear();
73  m_navTag.SetAsExclusive();
74  m_localCenter.Set(0.0f, 0.0f, 0.0f);
75  m_localHalfExtents.Set(0.0f, 0.0f, 0.0f);
76  m_startPosition.Set(0.0f, 0.0f, 0.0f);
77  m_userData = KY_NULL;
78  m_rotationMode = BoxObstacleRotation_Free;
79  m_upAxis = BoxObstacleUp_Z;
80  }
81 
82 
83  // ---------------------------------- Public Data Members ----------------------------------
84 
86  World* m_world;
87 
91  Ptr<DatabaseBinding> m_databaseBinding;
92 
95  DynamicNavTag m_navTag;
96 
105  Vec3f m_localHalfExtents;
106  Vec3f m_startPosition;
107 
108  void* m_userData;
109 
110  BoxObstacleRotationMode m_rotationMode;
111 
115 };
116 
117 
118 
129 class BoxObstacle: public WorldElement
130 {
131  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_BoxObstacle)
133 
134 public:
135  static WorldElementType GetStaticType() { return TypeBoxObstacle; }
136  virtual WorldElementType GetType() const { return TypeBoxObstacle; }
137 
138  virtual const char* GetTypeName() const { return "BoxObstacle"; }
140 
141  // ---------------------------------- Main API Functions ----------------------------------
142 
143  BoxObstacle();
144  BoxObstacle(const BoxObstacleInitConfig& initConfig);
145 
146  virtual ~BoxObstacle();
147 
152  void Init(const BoxObstacleInitConfig& initConfig);
153 
156  void Clear();
157 
165  void AddToWorld();
166 
173  void RemoveFromWorld();
174 
176  void SetTransform(const Transform& transform);
177 
179  void SetLinearVelocity(const Vec3f& linearVelocity);
180 
183  void SetAngularVelocity(const Vec3f& angularVelocity);
184 
189 
199  void SetDoesTriggerTagVolume(bool triggerTagVolume);
200 
201 
202  // ---------------------------------- Getters ----------------------------------
203 
204  const Vec3f& GetLocalCenter() const;
205  const Vec3f& GetLocalHalfExtents() const;
206 
207 
208  const Vec3f& GetLinearVelocity() const;
209  const Vec3f& GetAngularVelocity() const;
210  const Transform& GetTransform() const;
211  BoxObstacleRotationMode GetRotationMode() const;
212  const TagVolume* GetTagVolume() const;
213  const DynamicNavTag& GetNavTag() const;
214  KyUInt32 GetSpatializedCylinderCount() const;
215  const SpatializedCylinder& GetSpatializedCylinder(KyUInt32 index) const;
216 
217  TagVolume::IntegrationStatus GetTagVolumeIntegrationStatus() const;
218  const DatabaseBinding* GetDatabaseBinding() const;
219 
223  bool DoesTriggerTagVolume() const;
224 
226  static const char* GetRotationModeDescription(BoxObstacleRotationMode rotationMode);
227 
228 private:
229  void SetDefaults();
230 
231  // Computes the SpatializedCylinder set that best fit the obstacle extents, in
232  // local coordinates.
233  // This is called each time the BoxObstacle is reinitialized, and the first time
234  // the obstacle is updated with BoxObstacleRotation_Yaw flag.
235  void ComputeSampledPoints();
236 
237  // Computes the SpatializedCylinder positions as sampled on a given plane.
238  // Automatically called by ComputeSampledPoints once the third dimension is reduced
239  // according to the BoxObstacleUpAxis provided in BoxObstacleInitConfig.
240  void ComputeSampledPoints_2D(const Vec3f& baseCenter, const Vec3f& axis0, const Vec3f& axis1,
241  KyFloat32 halfExt0, KyFloat32 halfExt1, KyFloat32 sampledPointsHeight);
242 
243  // Computes the SpatializedCylinder positions as sampled along a given line.
244  // Automatically called by ComputeSampledPoints_2D, once the second dimension is reduced
245  // accordingly to the wider 2D extent.
246  void ComputeSampledPoints_1D(const Vec3f& baseCenter, const Vec3f& axis,
247  KyFloat32 length, KyFloat32 width, KyFloat32 sampledPointsHeight);
248 
249  // Computes the global position and the velocity at a given local position
250  // according to transform, and linear and angular velocities.
251  void ComputePositionAndVelocity(const Vec3f& localPosition, Vec3f& newPosition, Vec3f& newVelocity);
252 
253 
254 public: // internal
255  virtual void DoSendVisualDebug(VisualDebugServer& visualDebugServer, VisualDebugSendChangeEvent changeEvent); // Inherited from WorldElement
256 
257  // Updates the SpatializedCylinders positions and velocities according to
258  // the Transform, and linear and angular velocities of this BoxObstacle;
259  // then computes the spatialization of the set to be used accordingly to update status.
260  void UpdateSpatialization();
261 
262  // Sets up the TagVolume with its DynamicNavTag and the contour that best fits the obstacle.
263  // This is called by TagVolumeTrigger when the BoxObstacle is updated with a
264  // DoesTriggerTagVolume set to true.
265  void SetupTagVolumeInitConfig(TagVolumeInitConfig& tagVolumeInitConfig);
266 
267  // Called when the TagVolume integration is complete. It invalidates all Db spatializations.
268  void OnTagVolumeIntegration();
269 
270 
271  // NOTE: direct access to spatialization sets should not be used.
272  // Use the non-internal public sets that provide information
273  // on the SpatializedCylinder set currently in use according to
274  // rotation mode.
275  // They are used only in unit tests to validate they are well managed
276  // according to the rotation mode and the triggerTagVolume flag.
277  SpatializedCylinder& GetCentralSpatializedCylinder();
278  KyUInt32 GetSampledSpatializedCylinderCount();
279  SpatializedCylinder& GetSampledSpatializedCylinder(KyUInt32 index);
280  TagVolume* GetTagVolume();
281 
282 
283 private:
284  // -------- Input -----------
285 
286  Ptr<DatabaseBinding> m_databaseBinding;
287 
288  DynamicNavTag m_navTag;
289 
290  Vec3f m_localCenter;
291  Vec3f m_localHalfExtents;
292 
293  BoxObstacleUpAxis m_upAxis;
294 
295  BoxObstacleRotationMode m_rotationMode;
296 
297  bool m_doesTriggerTagVolume;
298 
299  Transform m_transform;
300 
304 
309 
310  // --------- Obstacle state ----------
311 
312  TagVolumeTrigger<BoxObstacle> m_tagVolumeTrigger;
313 
314  SpatializedCylinder m_centralSpatializedCylinder;
315  SpatializedCylinder* m_sampledSpatializedCylinders;
316  Vec3f* m_sampledSpatializedCylinderLocalPositions;
317  KyUInt32 m_sampledSpatializedCylinderCount;
318 };
319 
320 KY_INLINE const DynamicNavTag& BoxObstacle::GetNavTag() const { return m_navTag; }
321 KY_INLINE const Vec3f& BoxObstacle::GetLocalCenter() const { return m_localCenter; }
322 KY_INLINE const Vec3f& BoxObstacle::GetLocalHalfExtents() const { return m_localHalfExtents; }
323 KY_INLINE BoxObstacleRotationMode BoxObstacle::GetRotationMode() const { return m_rotationMode; }
324 
325 KY_INLINE bool BoxObstacle::DoesTriggerTagVolume() const { return m_doesTriggerTagVolume; }
326 KY_INLINE const TagVolume* BoxObstacle::GetTagVolume() const { return m_tagVolumeTrigger.GetTagVolume(); }
327 KY_INLINE TagVolume::IntegrationStatus BoxObstacle::GetTagVolumeIntegrationStatus() const { return m_tagVolumeTrigger.GetIntegrationStatus(); }
328 KY_INLINE const DatabaseBinding* BoxObstacle::GetDatabaseBinding() const { return m_databaseBinding; }
329 
330 KY_INLINE KyUInt32 BoxObstacle::GetSpatializedCylinderCount() const
331 {
332  return (GetRotationMode() == BoxObstacleRotation_Yaw) ? m_sampledSpatializedCylinderCount : 1;
333 }
334 KY_INLINE const SpatializedCylinder& BoxObstacle::GetSpatializedCylinder(KyUInt32 index) const
335 {
336  return (GetRotationMode() == BoxObstacleRotation_Yaw) ? m_sampledSpatializedCylinders[index] : m_centralSpatializedCylinder;
337 }
338 
339 KY_INLINE const Vec3f& BoxObstacle::GetLinearVelocity() const { return m_linearVelocity; }
340 KY_INLINE const Vec3f& BoxObstacle::GetAngularVelocity() const { return m_angularVelocity; }
341 KY_INLINE const Transform& BoxObstacle::GetTransform() const { return m_transform; }
342 
343 KY_INLINE SpatializedCylinder& BoxObstacle::GetCentralSpatializedCylinder() { return m_centralSpatializedCylinder; }
344 KY_INLINE KyUInt32 BoxObstacle::GetSampledSpatializedCylinderCount() { return m_sampledSpatializedCylinderCount; }
345 KY_INLINE SpatializedCylinder& BoxObstacle::GetSampledSpatializedCylinder(KyUInt32 index) { return m_sampledSpatializedCylinders[index]; }
346 KY_INLINE TagVolume* BoxObstacle::GetTagVolume() { return m_tagVolumeTrigger.GetTagVolume(); }
347 
348 } // Kaim
349 
350 #endif // Navigation_BoxObstacle_H
void Clear()
Prepares this instance for destruction and / or reuse: sets all members to their default values and c...
BoxObstacleRotationMode
Enumerates the possible controls for how a BoxObstacle should be internally represented.
Definition: boxobstacle.h:30
Class used to provide TagVolume initialization parameters.
Definition: tagvolume.h:36
void SetTransform(const Transform &transform)
The transform of the box.
static const char * GetRotationModeDescription(BoxObstacleRotationMode rotationMode)
Returns a short description of the rotation mode for visual debug.
Used for all obstacles which are freely rotating (for example, concrete blocs just after the explosio...
Definition: boxobstacle.h:40
Vec3f m_localCenter
Defines the local AABBox center relatively to rotation axis.
Definition: boxobstacle.h:113
void Set(KyFloat32 _x, KyFloat32 _y, KyFloat32 _z)
Sets the coordinates.
Definition: vec3f.h:52
void SetDefaults()
Sets all members to their default value.
Definition: boxobstacle.h:73
void SetAngularVelocity(const Vec3f &angularVelocity)
The rotational speed as rotation vector.
void AddToWorld()
Adds the BoxObstacle to the World.
Vec3f m_angularVelocity
Stores the rotational speed as rotation vector expressed in World coordinate system.
Definition: boxobstacle.h:345
#define KY_NULL
Null value.
Definition: types.h:247
BoxObstacleUpAxis
Enumerates the possible up-axis definition for a BoxObstacle.
Definition: boxobstacle.h:46
#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
World * m_world
Mandatory: you must provide a World when calling BoxObstacle::Init.
Definition: boxobstacle.h:95
This class represents runtime-defined volumes with customized NavTag.
Definition: tagvolume.h:108
Vec3f m_linearVelocity
The linear velocity, expressed in World coordinate system, at the local transform center of the box...
Definition: boxobstacle.h:340
DynamicNavTag m_navTag
This DynamicNavTag will be used to set up the TagVolume NavTag when the BoxObstacle will trigger it...
Definition: boxobstacle.h:104
Used for obstacles that are moving mainly horizontally (such as cars, doors, etc.).
Definition: boxobstacle.h:35
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
void Init(const BoxObstacleInitConfig &initConfig)
Sets m_world and allocates memory depending on m_databaseBinding; it does not add the obstacle to the...
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
Class used to provide BoxObstacle initialization parameters.
Definition: boxobstacle.h:58
void SetRotationMode(BoxObstacleRotationMode mode)
Sets the next rotation mode used to update this BoxObstacle.
void RemoveFromWorld()
Removes the BoxObstacle from the World.
bool DoesTriggerTagVolume() const
Returns whether the TriggerTagVolume flag is raised or not; not if the BoxObstacle has actually trigg...
Definition: boxobstacle.h:366
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
The VisualDebugServer manages the sending of data to clients.
Definition: visualdebugserver.h:254
BoxObstacleUpAxis m_upAxis
Used only for BoxObstacles that are yaw-rotating.
Definition: boxobstacle.h:124
Internal representation of world elements, using a vertical cylinder shape.
Definition: spatializedcylinder.h:56
Ptr< DatabaseBinding > m_databaseBinding
Defines the Databases in which the BoxObstacle will be spatialized.
Definition: boxobstacle.h:100
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
void SetLinearVelocity(const Vec3f &linearVelocity)
The linear velocity at the local transform center of the box.
This class represents a three-dimensional 6 freedom degrees unit transform.
Definition: transform.h:20
Each instance of the BoxObstacle class represents a dynamic, physical object in your game engine that...
Definition: boxobstacle.h:139
void SetDoesTriggerTagVolume(bool triggerTagVolume)
This information is copied and applied in the next World::Update.
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