gwnavruntime/basesystem/coordsystem.h Source File

coordsystem.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 #pragma once
9 
18 
19 
20 namespace Kaim
21 {
22 
23 class BlobFieldsMapping;
24 class BlobAggregate;
25 
26 
31 {
32  CLIENT_X = 0,
34  CLIENT_Y = 2,
36  CLIENT_Z = 4,
38 };
39 
40 
44 {
45  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
46 public:
49  {
54  }
55 
57  void Init_Zup(KyFloat32 oneMeterInClientUnits = 1.0f)
58  {
59  Init(oneMeterInClientUnits, CLIENT_X, CLIENT_Y, CLIENT_Z);
60  }
61 
63  void Init_Yup(KyFloat32 oneMeterInClientUnits = 1.0f)
64  {
65  Init(oneMeterInClientUnits, CLIENT_X, CLIENT_MINUS_Z, CLIENT_Y);
66  }
67 
68  void Init(
69  KyFloat32 oneMeterInClientUnits,
70  CoordSystemClientAxis clientAxisForNavigationX,
71  CoordSystemClientAxis clientAxisForNavigationY,
72  CoordSystemClientAxis clientAxisForNavigationZ)
73  {
74  m_oneMeterInClientUnits = oneMeterInClientUnits;
75  m_clientAxisForNavigationX = (KyUInt32)clientAxisForNavigationX;
76  m_clientAxisForNavigationY = (KyUInt32)clientAxisForNavigationY;
77  m_clientAxisForNavigationZ = (KyUInt32)clientAxisForNavigationZ;
78  }
79 
81  //void AddMapping(BlobFieldsMapping& mapping);
82 
83  bool operator==(const CoordSystemConfig& other) const
84  {
89  }
90 
91  bool operator!=(const CoordSystemConfig& other) const { return !operator==(other); }
92 
93 public:
103 };
104 
105 
106 // internal
107 inline void SwapEndianness(Endianness::Target e, CoordSystemConfig& self)
108 {
109  SwapEndianness(e, self.m_oneMeterInClientUnits);
110  SwapEndianness(e, self.m_clientAxisForNavigationX);
111  SwapEndianness(e, self.m_clientAxisForNavigationY);
112  SwapEndianness(e, self.m_clientAxisForNavigationZ);
113 }
114 
115 
120 {
121  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
122 public:
124 
125  static const ClientAxis CLIENT_X = Kaim::CLIENT_X;
126  static const ClientAxis CLIENT_MINUS_X = Kaim::CLIENT_MINUS_X;
127  static const ClientAxis CLIENT_Y = Kaim::CLIENT_Y;
128  static const ClientAxis CLIENT_MINUS_Y = Kaim::CLIENT_MINUS_Y;
129  static const ClientAxis CLIENT_Z = Kaim::CLIENT_Z;
130  static const ClientAxis CLIENT_MINUS_Z = Kaim::CLIENT_MINUS_Z;
131 
132 
133 public:
134  CoordSystem() { Setup(1.0f, CLIENT_X, CLIENT_Y, CLIENT_Z); }
135 
141  void Setup(KyFloat32 oneMeterInClientUnits, ClientAxis clientAxisForNavigationX, ClientAxis clientAxisForNavigationY, ClientAxis clientAxisForNavigationZ);
142 
145  void Setup(const CoordSystemConfig& config);
146 
148  void SetOneMeterInClientUnits(KyFloat32 oneMeter);
149 
151  void SetClientAxisForNavigationX(ClientAxis clientAxisForNavigationX);
152 
154  void SetClientAxisForNavigationY(ClientAxis clientAxisForNavigationY);
155 
157  void SetClientAxisForNavigationZ(ClientAxis clientAxisForNavigationZ);
158 
160  ClientAxis GetClientAxisForNavigationX() const;
161 
163  ClientAxis GetClientAxisForNavigationY() const;
164 
166  ClientAxis GetClientAxisForNavigationZ() const;
167 
168 public:
169  // ------------------ Client <-> Autodesk Navigation: Distances ------------------
170 
174  KyFloat32 ClientToNavigation_Dist(KyFloat32 clientDist) const; // Dist
175 
179  KyFloat32 NavigationToClient_Dist(KyFloat32 navigationDist) const; // Dist
180 
181 
182  // ------------------ Client <-> Autodesk Navigation: Square Distances ------------------
183 
187  KyFloat32 ClientToNavigation_SquareDist(KyFloat32 clientSquareDist) const; // SquareDist
188 
192  KyFloat32 NavigationToClient_SquareDist(KyFloat32 navigationSquareDist) const; // SquareDist
193 
194 
195  // ------------------ Client <-> Autodesk Navigation: Position Vectors ------------------
197 
201  void ClientToNavigation_Pos(const Vec3f& clientPos, Vec3f& navigationPos) const;
202 
206  void NavigationToClient_Pos(const Vec3f& navigationPos, Vec3f& clientPos) const;
207 
211  Vec3f ClientToNavigation_Pos(const Vec3f& clientPos) const;
212 
216  Vec3f NavigationToClient_Pos(const Vec3f& navigationPos) const;
217 
218  // ------------------ Client <-> Autodesk Navigation: Normal Vectors ------------------
220 
224  void ClientToNavigation_Normal(const Vec3f& clientNormal, Vec3f& navigationNormal) const;
225 
229  void NavigationToClient_Normal(const Vec3f& navigationNormal, Vec3f& clientNormal) const;
230 
234  Vec3f ClientToNavigation_Normal(const Vec3f& clientNormal) const;
235 
239  Vec3f NavigationToClient_Normal(const Vec3f& navigationNormal) const;
240 
241  // ------------------ Client <-> Autodesk Navigation: Angular Velocity Vectors ------------------
243 
247  void ClientToNavigation_AngularVelocity(const Vec3f& clientAngularVelocity, Vec3f& navigationAngularVelocity) const;
248 
252  void NavigationToClient_AngularVelocity(const Vec3f& navigationAngularVelocity, Vec3f& clientAngularVelocity) const;
253 
257  Vec3f ClientToNavigation_AngularVelocity(const Vec3f& clientAngularVelocity) const;
258 
262  Vec3f NavigationToClient_AngularVelocity(const Vec3f& navigationAngularVelocity) const;
263 
264 
265  // ------------------ Client <-> Autodesk Navigation: Extents Vectors ------------------
267 
272  void ClientToNavigation_Extents(const Vec3f& clientExtents, Vec3f& navigationExtents) const;
273 
278  void NavigationToClient_Extents(const Vec3f& navigationExtents, Vec3f& clientExtents) const;
279 
284  Vec3f ClientToNavigation_Extents(const Vec3f& clientExtents) const;
285 
290  Vec3f NavigationToClient_Extents(const Vec3f& navigationExtents) const;
291 
292 
293  // ------------------ Client <-> Autodesk Navigation: Triangle ------------------
294 
298  void ClientToNavigation_Triangle(const Triangle3f& clientTriangle, Triangle3f& navigationTriangle) const;
299 
303  void NavigationToClient_Triangle(const Triangle3f& navigationTriangle, Triangle3f& clientTriangle) const;
304 
305 
306  // ------------------ Client <-> Autodesk Navigation: Boxes ------------------
307 
312  void ClientToNavigation_Box(const Vec3f& clientMin, const Vec3f& clientMax, Box3f& navigationBox) const;
313 
317  void ClientToNavigation_Box(const Box3f& clientBox, Box3f& navigationBox) const;
318 
323  void NavigationToClient_Box(const Box3f& navigationBox, Vec3f& clientMin, Vec3f& clientMax) const;
324 
328  void NavigationToClient_Box(const Box3f& navigationBox, Box3f& clientBox) const;
329 
330 
331  // ------------------ Client <-> Autodesk Navigation: Matrixes & Transforms ------------------
332 
336  void ClientToNavigation_Matrix(const Matrix3x3f& clientMatrix, Matrix3x3f& navigationMatrix) const;
337 
341  void NavigationToClient_Matrix(const Matrix3x3f& navigationMatrix, Matrix3x3f& clientMatrix) const;
342 
343 
347  void ClientToNavigation_Transform(const Transform& clientTransform, Transform& navigationTransform) const;
348 
352  void NavigationToClient_Transform(const Transform& navigationTransform, Transform& clientTransform) const;
353 
355  bool operator==(const CoordSystem& other) const;
356 
358  bool operator!=(const CoordSystem& other) const;
359 
361  bool IsRightHanded() const;
362 
363 public:
364  // Client axis <=> Autodesk Navigation axis
365  // navigation_x = m_navigationX_sign * clientPos[m_navigationX_idx];
366  // clientPos[m_navigationX_idx] = m_navigationX_sign * navigation_x;
369 
372 
375 
376  // client dist <=> navigation dist
379 
380 };
381 
382 inline void SwapEndianness(Endianness::Target e, CoordSystem& self)
383 {
384  SwapEndianness(e, self.m_navigationX_idx);
385  SwapEndianness(e, self.m_navigationX_sign);
386 
387  SwapEndianness(e, self.m_navigationY_idx);
388  SwapEndianness(e, self.m_navigationY_sign);
389 
390  SwapEndianness(e, self.m_navigationZ_idx);
391  SwapEndianness(e, self.m_navigationZ_sign);
392 
393  SwapEndianness(e, self.m_oneMeter);
394  SwapEndianness(e, self.m_inv_oneMeter);
395 }
396 
397 
398 }
399 
401 
402 
403 
404 
KyFloat32 m_oneMeter
The number of world units in the game engine that add up to one meter in length.
Definition: coordsystem.h:377
void NavigationToClient_Normal(const Vec3f &navigationNormal, Vec3f &clientNormal) const
Converts a normalized vector from the Autodesk Navigation coordinate system to the game engine coordi...
Definition: coordsystem.inl:110
KyInt32 m_navigationY_idx
Identifies the index within each Vec3f that contains game engine coordinates that is mapped to the Y ...
Definition: coordsystem.h:370
void Setup(KyFloat32 oneMeterInClientUnits, ClientAxis clientAxisForNavigationX, ClientAxis clientAxisForNavigationY, ClientAxis clientAxisForNavigationZ)
Sets the mapping between the coordinate system used in the Autodesk Navigation Engine and the game en...
Definition: coordsystem.inl:28
bool operator==(const CoordSystem &other) const
Indicates whether or not the two CoordSystem instances contain the same data members.
Definition: coordsystem.inl:301
void ClientToNavigation_Normal(const Vec3f &clientNormal, Vec3f &navigationNormal) const
Convert normals or any other vectors which length has to be kept when converted.
Definition: coordsystem.inl:104
bool operator!=(const CoordSystem &other) const
Indicates whether or not the two CoordSystem instances contain at least one different data member...
Definition: coordsystem.inl:309
static const ClientAxis CLIENT_Y
Represents the positive direction of the Y axis in the game engine.
Definition: coordsystem.h:127
KyFloat32 m_navigationZ_sign
Indicates whether coordinates on the Autodesk Navigation Z axis need to be negated when converting be...
Definition: coordsystem.h:374
void NavigationToClient_Pos(const Vec3f &navigationPos, Vec3f &clientPos) const
Converts a position from the Autodesk Navigation engine coordinate system to the game coordinate syst...
Definition: coordsystem.inl:84
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
void Init_Zup(KyFloat32 oneMeterInClientUnits=1.0f)
Initialize with NavX=ClientX, NavY=ClientY, NavZ=Up=ClientZ, custom oneMeterInClientUnits.
Definition: coordsystem.h:57
Represents the positive direction of the client game engine X axis.
Definition: coordsystem.h:32
ClientAxis GetClientAxisForNavigationY() const
Retrieves the axis in the game engine coordinate system that is mapped to the Y axis within the Autod...
Definition: coordsystem.inl:63
bool IsRightHanded() const
Indicates whether or not CoordSystem instance is right-handed.
Definition: coordsystem.inl:314
bool operator==(const CoordSystemConfig &other) const
For internal use.
Definition: coordsystem.h:83
void ClientToNavigation_AngularVelocity(const Vec3f &clientAngularVelocity, Vec3f &navigationAngularVelocity) const
Convert angular velocity vectors (special case of Normals).
Definition: coordsystem.inl:129
3d triangle of 32bits floating points
Definition: triangle3f.h:15
KyUInt32 m_clientAxisForNavigationZ
The axis in the game engine coordinate system that should be mapped to the Z axis within the Autodesk...
Definition: coordsystem.h:102
This class maintains the mapping between the system of coordinate axes used by the client game engine...
Definition: coordsystem.h:119
Represents the positive direction of the client game engine Y axis.
Definition: coordsystem.h:34
void ClientToNavigation_Transform(const Transform &clientTransform, Transform &navigationTransform) const
Converts a Transform from the game engine coordinate system to the Autodesk Navigation coordinate sys...
Definition: coordsystem.inl:286
ClientAxis GetClientAxisForNavigationX() const
Retrieves the axis in the game engine coordinate system that is mapped to the X axis within the Autod...
Definition: coordsystem.inl:62
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:52
KyInt32 m_navigationZ_idx
Identifies the index within each Vec3f that contains game engine coordinates that is mapped to the Z ...
Definition: coordsystem.h:373
Matrix3x3f is defined as 3 Transformed Unit Vectors:
Definition: matrix3x3f.h:24
KyFloat32 ClientToNavigation_Dist(KyFloat32 clientDist) const
Converts a distance measurement from the game engine coordinate system to the Autodesk Navigation coo...
Definition: coordsystem.inl:69
A structure that sets up the mapping between the coordinate system used in the Autodesk Navigation En...
Definition: coordsystem.h:43
void Init_Yup(KyFloat32 oneMeterInClientUnits=1.0f)
Initialize with NavX=ClientX, NavY=-ClientZ, NavZ=Up=ClientY, custom oneMeterInClientUnits.
Definition: coordsystem.h:63
void NavigationToClient_Extents(const Vec3f &navigationExtents, Vec3f &clientExtents) const
Converts an extents vector from the Autodesk Navigation engine coordinate system to the game coordina...
Definition: coordsystem.inl:159
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
KyUInt32 m_clientAxisForNavigationY
The axis in the game engine coordinate system that should be mapped to the Y axis within the Autodesk...
Definition: coordsystem.h:100
void SetClientAxisForNavigationZ(ClientAxis clientAxisForNavigationZ)
Sets the axis in the game engine coordinate system that should be mapped to the Z axis within the Aut...
Definition: coordsystem.inl:60
void SetClientAxisForNavigationX(ClientAxis clientAxisForNavigationX)
Sets the axis in the game engine coordinate system that should be mapped to the X axis within the Aut...
Definition: coordsystem.inl:58
CoordSystemClientAxis
Enumerates the possible axis orientations that can be assigned to m_clientAxisForNavigationX, m_clientAxisForNavigationX and m_clientAxisForNavigationX axes used within Autodesk Navigation.
Definition: coordsystem.h:30
static const ClientAxis CLIENT_MINUS_X
Represents the negative direction of the X axis in the game engine.
Definition: coordsystem.h:126
static const ClientAxis CLIENT_Z
Represents the positive direction of the Z axis in the game engine.
Definition: coordsystem.h:129
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:27
3d axis aligned box of 32bits floating points
Definition: box3f.h:16
Represents the positive direction of the client game engine Z axis.
Definition: coordsystem.h:36
KyFloat32 m_navigationX_sign
Indicates whether coordinates on the Autodesk Navigation X axis need to be negated when converting be...
Definition: coordsystem.h:368
void ClientToNavigation_Matrix(const Matrix3x3f &clientMatrix, Matrix3x3f &navigationMatrix) const
Converts a matrix from the game engine coordinate system to the Autodesk Navigation coordinate system...
Definition: coordsystem.inl:248
KyFloat32 NavigationToClient_SquareDist(KyFloat32 navigationSquareDist) const
Converts a squared distance measurement from the Autodesk Navigation coordinate system to the game en...
Definition: coordsystem.inl:73
void ClientToNavigation_Triangle(const Triangle3f &clientTriangle, Triangle3f &navigationTriangle) const
Converts a triangle from the game engine coordinate system to the Autodesk Navigation coordinate syst...
Definition: coordsystem.inl:184
void SetClientAxisForNavigationY(ClientAxis clientAxisForNavigationY)
Sets the axis in the game engine coordinate system that should be mapped to the Y axis within the Aut...
Definition: coordsystem.inl:59
KyFloat32 m_oneMeterInClientUnits
The number of world units in the game engine that add up to one meter in length.
Definition: coordsystem.h:96
Represents the negative direction of the client game engine Z axis.
Definition: coordsystem.h:37
static const ClientAxis CLIENT_X
Represents the positive direction of the X axis in the game engine.
Definition: coordsystem.h:125
static const ClientAxis CLIENT_MINUS_Y
Represents the negative direction of the Y axis in the game engine.
Definition: coordsystem.h:128
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
static const ClientAxis CLIENT_MINUS_Z
Represents the negative direction of the Z axis in the game engine.
Definition: coordsystem.h:130
void NavigationToClient_Triangle(const Triangle3f &navigationTriangle, Triangle3f &clientTriangle) const
Converts a triangle from the Autodesk Navigation coordinate system to the game engine coordinate syst...
Definition: coordsystem.inl:201
void NavigationToClient_Transform(const Transform &navigationTransform, Transform &clientTransform) const
Converts a Transform from the Autodesk Navigation coordinate system to the game engine coordinate sys...
Definition: coordsystem.inl:291
CoordSystemConfig()
Initialize with NavX=ClientX, NavY=ClientY, NavZ=Up=ClientZ, ClientUnits = meters.
Definition: coordsystem.h:48
Represents the negative direction of the client game engine Y axis.
Definition: coordsystem.h:35
void NavigationToClient_AngularVelocity(const Vec3f &navigationAngularVelocity, Vec3f &clientAngularVelocity) const
Converts an angular velocity vector from the Autodesk Navigation coordinate system to the game engine...
Definition: coordsystem.inl:133
void NavigationToClient_Matrix(const Matrix3x3f &navigationMatrix, Matrix3x3f &clientMatrix) const
Converts a matrix from the Autodesk Navigation coordinate system to the game engine coordinate system...
Definition: coordsystem.inl:267
KyUInt32 m_clientAxisForNavigationX
The axis in the game engine coordinate system that should be mapped to the X axis within the Autodesk...
Definition: coordsystem.h:98
KyInt32 m_navigationX_idx
Identifies the index within each Vec3f that contains game engine coordinates that is mapped to the X ...
Definition: coordsystem.h:367
KyFloat32 m_inv_oneMeter
One divided by the m_oneMeter value.
Definition: coordsystem.h:378
std::int32_t KyInt32
int32_t
Definition: types.h:24
Represents the negative direction of the client game engine X axis.
Definition: coordsystem.h:33
void NavigationToClient_Box(const Box3f &navigationBox, Vec3f &clientMin, Vec3f &clientMax) const
Converts a bounding box from the Autodesk Navigation coordinate system to the game engine coordinate ...
Definition: coordsystem.inl:230
ClientAxis GetClientAxisForNavigationZ() const
Retrieves the axis in the game engine coordinate system that is mapped to the Z axis within the Autod...
Definition: coordsystem.inl:64
void ClientToNavigation_Pos(const Vec3f &clientPos, Vec3f &navigationPos) const
Convert positions or any other vectors which length have to be scaled when converted.
Definition: coordsystem.inl:78
Matrix3x3f rotation and Vec3f translation.
Definition: transform.h:16
KyFloat32 m_navigationY_sign
Indicates whether coordinates on the Autodesk Navigation Y axis need to be negated when converting be...
Definition: coordsystem.h:371
KyFloat32 ClientToNavigation_SquareDist(KyFloat32 clientSquareDist) const
Converts a squared distance measurement from the game engine coordinate system to the Autodesk Naviga...
Definition: coordsystem.inl:72
void ClientToNavigation_Extents(const Vec3f &clientExtents, Vec3f &navigationExtents) const
Convert extents or any other vectors which have to be scaled and values kept positive when converted...
Definition: coordsystem.inl:150
KyFloat32 NavigationToClient_Dist(KyFloat32 navigationDist) const
Converts a distance measurement from the Autodesk Navigation coordinate system to the game engine coo...
Definition: coordsystem.inl:70
void ClientToNavigation_Box(const Vec3f &clientMin, const Vec3f &clientMax, Box3f &navigationBox) const
Converts a bounding box from the game engine coordinate system to the Autodesk Navigation coordinate ...
Definition: coordsystem.inl:220
float KyFloat32
float
Definition: types.h:32
3d vector using 32bits floating points.
Definition: vec3f.h:16