gwnavruntime/world/boxobstacle.h Source File

boxobstacle.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 
8 
9 #pragma once
10 
11 
18 
19 
20 namespace Kaim
21 {
22 
23 class DatabaseBinding;
24 
25 
29 {
34 
39 };
40 
41 
45 {
46  BoxObstacleUp_X = 0,
47  BoxObstacleUp_Minus_X,
48  BoxObstacleUp_Y,
49  BoxObstacleUp_Minus_Y,
50  BoxObstacleUp_Z,
51  BoxObstacleUp_Minus_Z
52 };
53 
54 
57 {
58  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_BoxObstacle)
59 
60 public:
61  // ------------------------------ Functions -----------------------------
62 
64 
66  void SetDefaults()
67  {
68  m_world = nullptr;
69  m_databaseBinding = nullptr;
70  m_navTag.Clear();
71  m_navTag.SetAsExclusive();
72  m_localCenter.Set(0.0f, 0.0f, 0.0f);
73  m_localHalfExtents.Set(0.0f, 0.0f, 0.0f);
74  m_startPosition.Set(0.0f, 0.0f, 0.0f);
75  m_userData = nullptr;
76  m_rotationMode = BoxObstacleRotation_Free;
77  m_upAxis = BoxObstacleUp_Z;
78  }
79 
80 
81  // ---------------------------------- Public Data Members ----------------------------------
82 
85 
89  Ptr<DatabaseBinding> m_databaseBinding;
90 
93  DynamicNavTag m_navTag;
94 
102 
103  Vec3f m_localHalfExtents;
104  Vec3f m_startPosition;
105 
106  void* m_userData;
107 
108  BoxObstacleRotationMode m_rotationMode;
109 
113 };
114 
115 
116 
128 {
129  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_BoxObstacle)
131 
132 public:
133  static WorldElementType GetStaticType() { return TypeBoxObstacle; }
134  virtual WorldElementType GetType() const { return TypeBoxObstacle; }
135 
136  virtual const char* GetTypeName() const { return "BoxObstacle"; }
137 
138 
139  // ---------------------------------- Main API Functions ----------------------------------
140 
141  BoxObstacle();
142  BoxObstacle(const BoxObstacleInitConfig& initConfig);
143 
144  virtual ~BoxObstacle();
145 
150  void Init(const BoxObstacleInitConfig& initConfig);
151 
154  void Clear();
155 
163  void AddToWorld();
164 
171  void RemoveFromWorld();
172 
174  void SetTransform(const Transform& transform) { m_transform = transform; }
175 
177  void SetLinearVelocity(const Vec3f& linearVelocity) { m_linearVelocity = linearVelocity; }
178 
181  void SetAngularVelocity(const Vec3f& angularVelocity) { m_angularVelocity = angularVelocity; };
182 
186  void SetRotationMode(BoxObstacleRotationMode mode) { m_rotationMode = mode; }
187 
197  void SetDoesTriggerTagVolume(bool doesTriggerTagVolume) { m_doesTriggerTagVolume = doesTriggerTagVolume; }
198 
199 
200  // ---------------------------------- Getters ----------------------------------
201 
202  const Vec3f& GetLocalCenter() const { return m_localCenter; }
203  const Vec3f& GetLocalHalfExtents() const { return m_localHalfExtents; }
204 
205  const Vec3f& GetLinearVelocity() const { return m_linearVelocity; }
206  const Vec3f& GetAngularVelocity() const { return m_angularVelocity; }
207  const Transform& GetTransform() const { return m_transform; }
208  BoxObstacleRotationMode GetRotationMode() const { return m_rotationMode; }
209  const TagVolume* GetTagVolume() const { return m_tagVolumeTrigger.GetTagVolume(); }
210  TagVolume* GetTagVolume() { return m_tagVolumeTrigger.GetTagVolume(); }
211  const DynamicNavTag& GetNavTag() const { return m_navTag; }
212 
213  KyUInt32 GetSpatializedCylinderCount() const { return (GetRotationMode() == BoxObstacleRotation_Yaw) ? m_sampledSpatializedCylinderCount : 1; }
214 
215  const SpatializedCylinder& GetSpatializedCylinder(KyUInt32 index) const
216  {
217  return (GetRotationMode() == BoxObstacleRotation_Yaw) ? m_sampledSpatializedCylinders[index] : m_centralSpatializedCylinder;
218  }
219 
220  TagVolume::IntegrationStatus GetTagVolumeIntegrationStatus() const { return m_tagVolumeTrigger.GetIntegrationStatus(); }
221  const DatabaseBinding* GetDatabaseBinding() const { return m_databaseBinding; }
222 
226  bool DoesTriggerTagVolume() const;
227 
229  static const char* GetRotationModeDescription(BoxObstacleRotationMode rotationMode);
230 
231 private:
232  void SetDefaults();
233 
234  // Computes the SpatializedCylinder set that best fit the obstacle extents, in
235  // local coordinates.
236  // This is called each time the BoxObstacle is reinitialized, and the first time
237  // the obstacle is updated with BoxObstacleRotation_Yaw flag.
238  void ComputeSampledPoints();
239 
240  // Computes the SpatializedCylinder positions as sampled on a given plane.
241  // Automatically called by ComputeSampledPoints once the third dimension is reduced
242  // according to the BoxObstacleUpAxis provided in BoxObstacleInitConfig.
243  void ComputeSampledPoints_2D(const Vec3f& baseCenter, const Vec3f& axis0, const Vec3f& axis1,
244  KyFloat32 halfExt0, KyFloat32 halfExt1, KyFloat32 sampledPointsHeight);
245 
246  // Computes the SpatializedCylinder positions as sampled along a given line.
247  // Automatically called by ComputeSampledPoints_2D, once the second dimension is reduced
248  // accordingly to the wider 2D extent.
249  void ComputeSampledPoints_1D(const Vec3f& baseCenter, const Vec3f& axis,
250  KyFloat32 length, KyFloat32 width, KyFloat32 sampledPointsHeight);
251 
252  // Computes the global position and the velocity at a given local position
253  // according to transform, and linear and angular velocities.
254  void ComputePositionAndVelocity(const Vec3f& localPosition, Vec3f& newPosition, Vec3f& newVelocity);
255 
256 
257 public: // internal
258  virtual void DoSendVisualDebug(VisualDebugServer& visualDebugServer, VisualDebugSendChangeEvent changeEvent); // Inherited from WorldElement
259 
260  // Updates the SpatializedCylinders positions and velocities according to
261  // the Transform, and linear and angular velocities of this BoxObstacle;
262  // then computes the spatialization of the set to be used accordingly to update status.
263  void UpdateSpatialization();
264 
265  // Sets up the TagVolume with its DynamicNavTag and the contour that best fits the obstacle.
266  // This is called by TagVolumeTrigger when the BoxObstacle is updated with a
267  // DoesTriggerTagVolume set to true.
268  void SetupTagVolumeInitConfig(TagVolumeInitConfig& tagVolumeInitConfig);
269 
270  // Called when the TagVolume integration is complete. It invalidates all Db spatializations.
271  void OnTagVolumeIntegration();
272 
273  // NOTE: direct access to spatialization sets should not be used.
274  // Use the non-internal public sets that provide information
275  // on the SpatializedCylinder set currently in use according to
276  // rotation mode.
277  // They are used only in unit tests to validate they are well managed
278  // according to the rotation mode and the triggerTagVolume flag.
279  const SpatializedCylinder& GetCentralSpatializedCylinder() const { return m_centralSpatializedCylinder; }
280 
281  KyUInt32 GetSampledSpatializedCylinderCount() const { return m_sampledSpatializedCylinderCount; }
282  const SpatializedCylinder& GetSampledSpatializedCylinder(KyUInt32 index) const { return m_sampledSpatializedCylinders[index]; }
283 
284 private:
285  // -------- Input -----------
286 
287  Ptr<DatabaseBinding> m_databaseBinding;
288 
289  DynamicNavTag m_navTag;
290 
291  Vec3f m_localCenter;
292  Vec3f m_localHalfExtents;
293 
294  BoxObstacleUpAxis m_upAxis;
295 
296  BoxObstacleRotationMode m_rotationMode;
297 
298  bool m_doesTriggerTagVolume;
299 
300  Transform m_transform;
301 
305 
310 
311  // --------- Obstacle state ----------
312 
313  TagVolumeTrigger<BoxObstacle> m_tagVolumeTrigger;
314 
315  SpatializedCylinder m_centralSpatializedCylinder;
316  SpatializedCylinder* m_sampledSpatializedCylinders;
317  Vec3f* m_sampledSpatializedCylinderLocalPositions;
318  KyUInt32 m_sampledSpatializedCylinderCount;
319 };
320 
321 } // Kaim
322 
void Clear()
Prepares this instance for destruction and / or reuse: sets all members to their default values and c...
Definition: boxobstacle.cpp:116
BoxObstacleRotationMode
Enumerates the possible controls for how a BoxObstacle should be internally represented.
Definition: boxobstacle.h:28
void SetTransform(const Transform &transform)
The transform of the box.
Definition: boxobstacle.h:174
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
Used for all obstacles which are freely rotating (for example, concrete blocs just after the explosio...
Definition: boxobstacle.h:38
Vec3f m_localCenter
Defines the local AABBox center relatively to rotation axis.
Definition: boxobstacle.h:101
void Set(KyFloat32 _x, KyFloat32 _y, KyFloat32 _z)
Sets {_x, _y, _z}.
Definition: vec3f.h:29
void SetDefaults()
Sets all members to their default value.
Definition: boxobstacle.h:66
void SetAngularVelocity(const Vec3f &angularVelocity)
The rotational speed as rotation vector.
Definition: boxobstacle.h:181
void AddToWorld()
Adds the BoxObstacle to the World.
Definition: boxobstacle.cpp:147
Vec3f m_angularVelocity
Stores the rotational speed as rotation vector expressed in World coordinate system.
Definition: boxobstacle.h:309
BoxObstacleUpAxis
Enumerates the possible up-axis definition for a BoxObstacle.
Definition: boxobstacle.h:44
#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
static const char * GetRotationModeDescription(BoxObstacleRotationMode rotationMode)
Returns a short description of the rotation mode for visual debug.
Definition: boxobstacle.cpp:359
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
World * m_world
Mandatory: you must provide a World when calling BoxObstacle::Init.
Definition: boxobstacle.h:84
Vec3f m_linearVelocity
The linear velocity, expressed in World coordinate system, at the local transform center of the box...
Definition: boxobstacle.h:304
DynamicNavTag m_navTag
This DynamicNavTag will be used to set up the TagVolume NavTag when the BoxObstacle will trigger it...
Definition: boxobstacle.h:93
Used for obstacles that are moving mainly horizontally (such as cars, doors, etc.).
Definition: boxobstacle.h:33
TagVolumeTrigger is dedicated to TagVolume creation / removal management.
Definition: tagvolumetrigger.h:22
WorldElementType
Enumerates the WorldElement types.
Definition: worldelementtype.h:13
void Init(const BoxObstacleInitConfig &initConfig)
Sets m_world and allocates memory depending on m_databaseBinding; it does not add the obstacle to the...
Definition: boxobstacle.cpp:62
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
Class used to provide BoxObstacle initialization parameters.
Definition: boxobstacle.h:56
void SetRotationMode(BoxObstacleRotationMode mode)
Sets the next rotation mode used to update this BoxObstacle.
Definition: boxobstacle.h:186
void RemoveFromWorld()
Removes the BoxObstacle from the World.
Definition: boxobstacle.cpp:160
bool DoesTriggerTagVolume() const
Returns whether the TriggerTagVolume flag is raised or not; not if the BoxObstacle has actually trigg...
BoxObstacleUpAxis m_upAxis
Used only for BoxObstacles that are yaw-rotating.
Definition: boxobstacle.h:112
Internal representation of world elements, using a vertical cylinder shape.
Definition: spatializedcylinder.h:44
Ptr< DatabaseBinding > m_databaseBinding
Defines the Databases in which the BoxObstacle will be spatialized.
Definition: boxobstacle.h:89
void SetLinearVelocity(const Vec3f &linearVelocity)
The linear velocity at the local transform center of the box.
Definition: boxobstacle.h:177
Matrix3x3f rotation and Vec3f translation.
Definition: transform.h:16
Each instance of the BoxObstacle class represents a dynamic, physical object in your game engine that...
Definition: boxobstacle.h:127
float KyFloat32
float
Definition: types.h:32
3d vector using 32bits floating points.
Definition: vec3f.h:16
void SetDoesTriggerTagVolume(bool doesTriggerTagVolume)
This information is copied and applied in the next World::Update.
Definition: boxobstacle.h:197