gwnavruntime/basesystem/coordsystem.h Source File

coordsystem.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 #ifndef Navigation_CoordSystem_H
9 #define Navigation_CoordSystem_H
10 
19 
20 
21 namespace Kaim
22 {
23 
24 class BlobFieldsMapping;
25 class BlobAggregate;
26 
27 
32 {
33  CLIENT_X = 0,
35  CLIENT_Y = 2,
37  CLIENT_Z = 4,
39 };
40 
41 
44 class CoordSystemConfig
45 {
46  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
47 public:
50  {
55  }
56 
58  void Init_Zup(KyFloat32 oneMeterInClientUnits = 1.0f)
59  {
60  Init(oneMeterInClientUnits, CLIENT_X, CLIENT_Y, CLIENT_Z);
61  }
62 
64  void Init_Yup(KyFloat32 oneMeterInClientUnits = 1.0f)
65  {
66  Init(oneMeterInClientUnits, CLIENT_X, CLIENT_MINUS_Z, CLIENT_Y);
67  }
68 
69  void Init(
70  KyFloat32 oneMeterInClientUnits,
71  CoordSystemClientAxis clientAxisForNavigationX,
72  CoordSystemClientAxis clientAxisForNavigationY,
73  CoordSystemClientAxis clientAxisForNavigationZ)
74  {
75  m_oneMeterInClientUnits = oneMeterInClientUnits;
76  m_clientAxisForNavigationX = (KyUInt32)clientAxisForNavigationX;
77  m_clientAxisForNavigationY = (KyUInt32)clientAxisForNavigationY;
78  m_clientAxisForNavigationZ = (KyUInt32)clientAxisForNavigationZ;
79  }
80 
82  //void AddMapping(BlobFieldsMapping& mapping);
83 
84  bool operator==(const CoordSystemConfig& other) const
85  {
86  return m_oneMeterInClientUnits == other.m_oneMeterInClientUnits
87  && m_clientAxisForNavigationX == other.m_clientAxisForNavigationX
88  && m_clientAxisForNavigationY == other.m_clientAxisForNavigationY
89  && m_clientAxisForNavigationZ == other.m_clientAxisForNavigationZ;
90  }
91 
92  bool operator!=(const CoordSystemConfig& other) const { return !operator==(other); }
93 
94 public:
104 };
105 
107 // internal
108 inline void SwapEndianness(Endianness::Target e, CoordSystemConfig& self)
109 {
110  SwapEndianness(e, self.m_oneMeterInClientUnits);
111  SwapEndianness(e, self.m_clientAxisForNavigationX);
112  SwapEndianness(e, self.m_clientAxisForNavigationY);
113  SwapEndianness(e, self.m_clientAxisForNavigationZ);
114 }
115 
116 
120 class CoordSystem
121 {
122  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
123 public:
125 
126  static const ClientAxis CLIENT_X = Kaim::CLIENT_X;
127  static const ClientAxis CLIENT_MINUS_X = Kaim::CLIENT_MINUS_X;
128  static const ClientAxis CLIENT_Y = Kaim::CLIENT_Y;
129  static const ClientAxis CLIENT_MINUS_Y = Kaim::CLIENT_MINUS_Y;
130  static const ClientAxis CLIENT_Z = Kaim::CLIENT_Z;
131  static const ClientAxis CLIENT_MINUS_Z = Kaim::CLIENT_MINUS_Z;
134 public:
135  CoordSystem() { Setup(1.0f, CLIENT_X, CLIENT_Y, CLIENT_Z); }
142  void Setup(KyFloat32 oneMeterInClientUnits, ClientAxis clientAxisForNavigationX, ClientAxis clientAxisForNavigationY, ClientAxis clientAxisForNavigationZ);
143 
146  void Setup(const CoordSystemConfig& config);
147 
149  void SetOneMeterInClientUnits(KyFloat32 oneMeter);
150 
152  void SetClientAxisForNavigationX(ClientAxis clientAxisForNavigationX);
153 
155  void SetClientAxisForNavigationY(ClientAxis clientAxisForNavigationY);
156 
158  void SetClientAxisForNavigationZ(ClientAxis clientAxisForNavigationZ);
159 
162 
165 
168 
169 public:
170  // ------------------ Client <-> Gameware Navigation: Distances ------------------
171 
175  KyFloat32 ClientToNavigation_Dist(KyFloat32 clientDist) const; // Dist
176 
180  KyFloat32 NavigationToClient_Dist(KyFloat32 navigationDist) const; // Dist
181 
182 
183  // ------------------ Client <-> Gameware Navigation: Square Distances ------------------
184 
188  KyFloat32 ClientToNavigation_SquareDist(KyFloat32 clientSquareDist) const; // SquareDist
189 
193  KyFloat32 NavigationToClient_SquareDist(KyFloat32 navigationSquareDist) const; // SquareDist
194 
195 
196  // ------------------ Client <-> Gameware Navigation: Position Vectors ------------------
198 
202  void ClientToNavigation_Pos(const Vec3f& clientPos, Vec3f& navigationPos) const;
203 
207  void NavigationToClient_Pos(const Vec3f& navigationPos, Vec3f& clientPos) const;
208 
212  Vec3f ClientToNavigation_Pos(const Vec3f& clientPos) const;
213 
217  Vec3f NavigationToClient_Pos(const Vec3f& navigationPos) const;
218 
219  // ------------------ Client <-> Gameware Navigation: Normal Vectors ------------------
221 
225  void ClientToNavigation_Normal(const Vec3f& clientNormal, Vec3f& navigationNormal) const;
226 
230  void NavigationToClient_Normal(const Vec3f& navigationNormal, Vec3f& clientNormal) const;
231 
235  Vec3f ClientToNavigation_Normal(const Vec3f& clientNormal) const;
236 
240  Vec3f NavigationToClient_Normal(const Vec3f& navigationNormal) const;
241 
242  // ------------------ Client <-> Gameware Navigation: Angular Velocity Vectors ------------------
244 
248  void ClientToNavigation_AngularVelocity(const Vec3f& clientAngularVelocity, Vec3f& navigationAngularVelocity) const;
249 
253  void NavigationToClient_AngularVelocity(const Vec3f& navigationAngularVelocity, Vec3f& clientAngularVelocity) const;
254 
258  Vec3f ClientToNavigation_AngularVelocity(const Vec3f& clientAngularVelocity) const;
259 
263  Vec3f NavigationToClient_AngularVelocity(const Vec3f& navigationAngularVelocity) const;
264 
265 
266  // ------------------ Client <-> Gameware Navigation: Extents Vectors ------------------
268 
273  void ClientToNavigation_Extents(const Vec3f& clientExtents, Vec3f& navigationExtents) const;
274 
279  void NavigationToClient_Extents(const Vec3f& navigationExtents, Vec3f& clientExtents) const;
280 
285  Vec3f ClientToNavigation_Extents(const Vec3f& clientExtents) const;
286 
291  Vec3f NavigationToClient_Extents(const Vec3f& navigationExtents) const;
292 
293 
294  // ------------------ Client <-> Gameware Navigation: Triangle ------------------
295 
299  void ClientToNavigation_Triangle(const Triangle3f& clientTriangle, Triangle3f& navigationTriangle) const;
300 
304  void NavigationToClient_Triangle(const Triangle3f& navigationTriangle, Triangle3f& clientTriangle) const;
305 
306 
307  // ------------------ Client <-> Gameware Navigation: Boxes ------------------
308 
313  void ClientToNavigation_Box(const Vec3f& clientMin, const Vec3f& clientMax, Box3f& navigationBox) const;
314 
318  void ClientToNavigation_Box(const Box3f& clientBox, Box3f& navigationBox) const;
319 
324  void NavigationToClient_Box(const Box3f& navigationBox, Vec3f& clientMin, Vec3f& clientMax) const;
325 
329  void NavigationToClient_Box(const Box3f& navigationBox, Box3f& clientBox) const;
330 
331 
332  // ------------------ Client <-> Gameware Navigation: Matrixes & Transforms ------------------
333 
337  void ClientToNavigation_Matrix(const Matrix3x3f& clientMatrix, Matrix3x3f& navigationMatrix) const;
338 
342  void NavigationToClient_Matrix(const Matrix3x3f& navigationMatrix, Matrix3x3f& clientMatrix) const;
343 
344 
348  void ClientToNavigation_Transform(const Transform& clientTransform, Transform& navigationTransform) const;
349 
353  void NavigationToClient_Transform(const Transform& navigationTransform, Transform& clientTransform) const;
354 
356  bool operator==(const CoordSystem& other) const;
357 
359  bool operator!=(const CoordSystem& other) const;
360 
362  bool IsRightHanded() const;
363 
364 public:
365  // Client axis <=> Gameware Navigation axis
366  // navigation_x = m_navigationX_sign * clientPos[m_navigationX_idx];
367  // clientPos[m_navigationX_idx] = m_navigationX_sign * navigation_x;
370 
373 
376 
377  // client dist <=> navigation dist
380 
381 };
382 
385 inline void SwapEndianness(Endianness::Target e, CoordSystem& self)
386 {
387  SwapEndianness(e, self.m_navigationX_idx);
388  SwapEndianness(e, self.m_navigationX_sign);
389 
390  SwapEndianness(e, self.m_navigationY_idx);
391  SwapEndianness(e, self.m_navigationY_sign);
392 
393  SwapEndianness(e, self.m_navigationZ_idx);
394  SwapEndianness(e, self.m_navigationZ_sign);
395 
396  SwapEndianness(e, self.m_oneMeter);
397  SwapEndianness(e, self.m_inv_oneMeter);
398 }
399 
400 
401 }
402 
404 
405 
406 
407 #endif
408 
KyFloat32 m_oneMeter
The number of world units in the game engine that add up to one meter in length.
Definition: coordsystem.h:422
void NavigationToClient_Normal(const Vec3f &navigationNormal, Vec3f &clientNormal) const
Converts a normalized vector from the Gameware Navigation coordinate system to the game engine coordi...
Definition: coordsystem.inl:114
KyInt32 m_navigationY_idx
Identifies the index within each Vec3f that contains game engine coordinates that is mapped to the Y ...
Definition: coordsystem.h:415
void Setup(KyFloat32 oneMeterInClientUnits, ClientAxis clientAxisForNavigationX, ClientAxis clientAxisForNavigationY, ClientAxis clientAxisForNavigationZ)
Sets the mapping between the coordinate system used in the Gameware Navigation Engine and the game en...
Definition: coordsystem.inl:32
bool operator==(const CoordSystem &other) const
Indicates whether or not the two CoordSystem instances contain the same data members.
Definition: coordsystem.inl:305
void ClientToNavigation_Normal(const Vec3f &clientNormal, Vec3f &navigationNormal) const
Converts a normalized vector from the game engine coordinate system to the Gameware Navigation coordi...
Definition: coordsystem.inl:108
bool operator!=(const CoordSystem &other) const
Indicates whether or not the two CoordSystem instances contain at least one different data member...
Definition: coordsystem.inl:313
static const ClientAxis CLIENT_Y
Represents the positive direction of the Y axis in the game engine.
Definition: coordsystem.h:133
KyFloat32 m_navigationZ_sign
Indicates whether coordinates on the Gameware Navigation Z axis need to be negated when converting be...
Definition: coordsystem.h:419
void NavigationToClient_Pos(const Vec3f &navigationPos, Vec3f &clientPos) const
Converts a position from the Gameware Navigation engine coordinate system to the game coordinate syst...
Definition: coordsystem.inl:88
void Init_Zup(KyFloat32 oneMeterInClientUnits=1.0f)
Initialize with NavX=ClientX, NavY=ClientY, NavZ=Up=ClientZ, custom oneMeterInClientUnits.
Definition: coordsystem.h:60
Represents the positive direction of the client game engine X axis.
Definition: coordsystem.h:34
bool IsRightHanded() const
Indicates whether or not CoordSystem instance is right-handed.
Definition: coordsystem.inl:318
bool operator==(const CoordSystemConfig &other) const
For internal use.
Definition: coordsystem.h:86
void ClientToNavigation_AngularVelocity(const Vec3f &clientAngularVelocity, Vec3f &navigationAngularVelocity) const
Converts an angular velocity vector from the game engine coordinate system to the Gameware Navigation...
Definition: coordsystem.inl:133
This class represents a triangle in three-dimensional space, whose dimensions are stored using float ...
Definition: triangle3f.h:22
KyUInt32 m_clientAxisForNavigationZ
The axis in the game engine coordinate system that should be mapped to the Z axis within the Gameware...
Definition: coordsystem.h:106
This class maintains the mapping between the system of coordinate axes used by the client game engine...
Definition: coordsystem.h:124
Represents the positive direction of the client game engine Y axis.
Definition: coordsystem.h:36
void ClientToNavigation_Transform(const Transform &clientTransform, Transform &navigationTransform) const
Converts a Transform from the game engine coordinate system to the Gameware Navigation coordinate sys...
Definition: coordsystem.inl:290
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
void SetOneMeterInClientUnits(KyFloat32 oneMeter)
Sets the number of world units in the game engine that add up to one meter in length.
Definition: coordsystem.inl:56
KyInt32 m_navigationZ_idx
Identifies the index within each Vec3f that contains game engine coordinates that is mapped to the Z ...
Definition: coordsystem.h:418
3x3 matrix.
Definition: matrix3x3f.h:21
KyFloat32 ClientToNavigation_Dist(KyFloat32 clientDist) const
Converts a distance measurement from the game engine coordinate system to the Gameware Navigation coo...
Definition: coordsystem.inl:73
A structure that sets up the mapping between the coordinate system used in the Gameware Navigation En...
Definition: coordsystem.h:45
void Init_Yup(KyFloat32 oneMeterInClientUnits=1.0f)
Initialize with NavX=ClientX, NavY=-ClientZ, NavZ=Up=ClientY, custom oneMeterInClientUnits.
Definition: coordsystem.h:66
void NavigationToClient_Extents(const Vec3f &navigationExtents, Vec3f &clientExtents) const
Converts an extents vector from the Gameware Navigation engine coordinate system to the game coordina...
Definition: coordsystem.inl:163
KyUInt32 m_clientAxisForNavigationY
The axis in the game engine coordinate system that should be mapped to the Y axis within the Gameware...
Definition: coordsystem.h:104
void SetClientAxisForNavigationZ(ClientAxis clientAxisForNavigationZ)
Sets the axis in the game engine coordinate system that should be mapped to the Z axis within the Gam...
Definition: coordsystem.inl:64
void SetClientAxisForNavigationX(ClientAxis clientAxisForNavigationX)
Sets the axis in the game engine coordinate system that should be mapped to the X axis within the Gam...
Definition: coordsystem.inl:62
CoordSystemClientAxis
Enumerates the possible axis orientations that can be assigned to m_clientAxisForNavigationX, m_clientAxisForNavigationX and m_clientAxisForNavigationX axes used within Gameware Navigation.
Definition: coordsystem.h:32
static const ClientAxis CLIENT_MINUS_X
Represents the negative direction of the X axis in the game engine.
Definition: coordsystem.h:132
static const ClientAxis CLIENT_Z
Represents the positive direction of the Z axis in the game engine.
Definition: coordsystem.h:135
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:35
This class represents a three-dimensional axis-aligned bounding box whose dimensions are stored using...
Definition: box3f.h:25
Represents the positive direction of the client game engine Z axis.
Definition: coordsystem.h:38
KyFloat32 m_navigationX_sign
Indicates whether coordinates on the Gameware Navigation X axis need to be negated when converting be...
Definition: coordsystem.h:413
ClientAxis GetClientAxisForNavigationY()
Retrieves the axis in the game engine coordinate system that is mapped to the Y axis within the Gamew...
Definition: coordsystem.inl:67
void ClientToNavigation_Matrix(const Matrix3x3f &clientMatrix, Matrix3x3f &navigationMatrix) const
Converts a matrix from the game engine coordinate system to the Gameware Navigation coordinate system...
Definition: coordsystem.inl:252
KyFloat32 NavigationToClient_SquareDist(KyFloat32 navigationSquareDist) const
Converts a squared distance measurement from the Gameware Navigation coordinate system to the game en...
Definition: coordsystem.inl:77
void ClientToNavigation_Triangle(const Triangle3f &clientTriangle, Triangle3f &navigationTriangle) const
Converts a triangle from the game engine coordinate system to the Gameware Navigation coordinate syst...
Definition: coordsystem.inl:188
void SetClientAxisForNavigationY(ClientAxis clientAxisForNavigationY)
Sets the axis in the game engine coordinate system that should be mapped to the Y axis within the Gam...
Definition: coordsystem.inl:63
KyFloat32 m_oneMeterInClientUnits
The number of world units in the game engine that add up to one meter in length.
Definition: coordsystem.h:100
ClientAxis GetClientAxisForNavigationZ()
Retrieves the axis in the game engine coordinate system that is mapped to the Z axis within the Gamew...
Definition: coordsystem.inl:68
Represents the negative direction of the client game engine Z axis.
Definition: coordsystem.h:39
static const ClientAxis CLIENT_X
Represents the positive direction of the X axis in the game engine.
Definition: coordsystem.h:131
static const ClientAxis CLIENT_MINUS_Y
Represents the negative direction of the Y axis in the game engine.
Definition: coordsystem.h:134
Definition: gamekitcrowddispersion.h:20
static const ClientAxis CLIENT_MINUS_Z
Represents the negative direction of the Z axis in the game engine.
Definition: coordsystem.h:136
void NavigationToClient_Triangle(const Triangle3f &navigationTriangle, Triangle3f &clientTriangle) const
Converts a triangle from the Gameware Navigation coordinate system to the game engine coordinate syst...
Definition: coordsystem.inl:205
void NavigationToClient_Transform(const Transform &navigationTransform, Transform &clientTransform) const
Converts a Transform from the Gameware Navigation coordinate system to the game engine coordinate sys...
Definition: coordsystem.inl:295
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
CoordSystemConfig()
Initialize with NavX=ClientX, NavY=ClientY, NavZ=Up=ClientZ, ClientUnits = meters.
Definition: coordsystem.h:51
Represents the negative direction of the client game engine Y axis.
Definition: coordsystem.h:37
void NavigationToClient_AngularVelocity(const Vec3f &navigationAngularVelocity, Vec3f &clientAngularVelocity) const
Converts an angular velocity vector from the Gameware Navigation coordinate system to the game engine...
Definition: coordsystem.inl:137
void NavigationToClient_Matrix(const Matrix3x3f &navigationMatrix, Matrix3x3f &clientMatrix) const
Converts a matrix from the Gameware Navigation coordinate system to the game engine coordinate system...
Definition: coordsystem.inl:271
KyUInt32 m_clientAxisForNavigationX
The axis in the game engine coordinate system that should be mapped to the X axis within the Gameware...
Definition: coordsystem.h:102
KyInt32 m_navigationX_idx
Identifies the index within each Vec3f that contains game engine coordinates that is mapped to the X ...
Definition: coordsystem.h:412
KyFloat32 m_inv_oneMeter
One divided by the m_oneMeter value.
Definition: coordsystem.h:423
Represents the negative direction of the client game engine X axis.
Definition: coordsystem.h:35
void NavigationToClient_Box(const Box3f &navigationBox, Vec3f &clientMin, Vec3f &clientMax) const
Converts a bounding box from the Gameware Navigation coordinate system to the game engine coordinate ...
Definition: coordsystem.inl:234
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
void ClientToNavigation_Pos(const Vec3f &clientPos, Vec3f &navigationPos) const
Converts a position from the game engine coordinate system to the Gameware Navigation coordinate syst...
Definition: coordsystem.inl:82
ClientAxis GetClientAxisForNavigationX()
Retrieves the axis in the game engine coordinate system that is mapped to the X axis within the Gamew...
Definition: coordsystem.inl:66
This class represents a three-dimensional 6 freedom degrees unit transform.
Definition: transform.h:20
KyFloat32 m_navigationY_sign
Indicates whether coordinates on the Gameware Navigation Y axis need to be negated when converting be...
Definition: coordsystem.h:416
KyFloat32 ClientToNavigation_SquareDist(KyFloat32 clientSquareDist) const
Converts a squared distance measurement from the game engine coordinate system to the Gameware Naviga...
Definition: coordsystem.inl:76
void ClientToNavigation_Extents(const Vec3f &clientExtents, Vec3f &navigationExtents) const
Converts an extents vector from the game engine coordinate system to the Gameware Navigation coordina...
Definition: coordsystem.inl:154
KyFloat32 NavigationToClient_Dist(KyFloat32 navigationDist) const
Converts a distance measurement from the Gameware Navigation coordinate system to the game engine coo...
Definition: coordsystem.inl:74
void ClientToNavigation_Box(const Vec3f &clientMin, const Vec3f &clientMax, Box3f &navigationBox) const
Converts a bounding box from the game engine coordinate system to the Gameware Navigation coordinate ...
Definition: coordsystem.inl:224
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