gwnavruntime/math/matrix3x3f.h Source File

matrix3x3f.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 // primary contact: LAPA - secondary contact: NOBODY
9 #ifndef Navigation_Matrix3x3f_H
10 #define Navigation_Matrix3x3f_H
11 
12 
14 
15 
16 namespace Kaim
17 {
18 
19 
22 {
23  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
24 
25 public:
26  static Matrix3x3f Identity();
27 
28  enum Elements {
29  xx = 0, xy, xz,
30  yx, yy, yz,
31  zx, zy, zz,
32  };
33 
34  // ---------------------------------- Constructors ----------------------------------
35 
36  Matrix3x3f();
37  Matrix3x3f(
38  KyFloat32 v_xx, KyFloat32 v_xy, KyFloat32 v_xz,
39  KyFloat32 v_yx, KyFloat32 v_yy, KyFloat32 v_yz,
40  KyFloat32 v_zx, KyFloat32 v_zy, KyFloat32 v_zz);
41  Matrix3x3f(const Vec3f& v_x, const Vec3f& v_y, const Vec3f& v_z);
42  Matrix3x3f(const Vec3f& axis, KyFloat32 angleRad);
43 
44 
45  void SetIdentity();
46  void Set(
47  KyFloat32 v_xx, KyFloat32 v_xy, KyFloat32 v_xz,
48  KyFloat32 v_yx, KyFloat32 v_yy, KyFloat32 v_yz,
49  KyFloat32 v_zx, KyFloat32 v_zy, KyFloat32 v_zz);
50  void Set(const Vec3f& v_x, const Vec3f& v_y, const Vec3f& v_z);
52  void SetRotation(const Vec3f& axis, KyFloat32 angleRad);
53 
54  const Vec3f& GetRow(KyUInt32 index) const;
55  Vec3f& GetRow(KyUInt32 index);
56 
57  void Transform(const Vec3f& v, Vec3f& transformed) const;
58 
60  Vec3f operator*(const Vec3f& v) const;
61 
62  Matrix3x3f operator*(const Matrix3x3f& rhs) const;
63 
64  bool operator==(const Matrix3x3f& other) const;
65  bool operator!=(const Matrix3x3f& other) const;
66 
67  // ---------------------------------- Public Data Members ----------------------------------
68 public:
69  KyFloat32 m[9];
70 };
71 
72 
73 KY_INLINE void SwapEndianness(Endianness::Target e, Matrix3x3f& self)
74 {
75  for (int i = 0; i < 9; ++i)
76  SwapEndianness(e, self.m[i]);
77 }
78 
79 KY_INLINE Matrix3x3f::Matrix3x3f()
80 {
81  SetIdentity();
82 }
83 
84 KY_INLINE Matrix3x3f::Matrix3x3f(
85  KyFloat32 v_xx, KyFloat32 v_xy, KyFloat32 v_xz,
86  KyFloat32 v_yx, KyFloat32 v_yy, KyFloat32 v_yz,
87  KyFloat32 v_zx, KyFloat32 v_zy, KyFloat32 v_zz)
88 {
89  Set(v_xx, v_xy, v_xz,
90  v_yx, v_yy, v_yz,
91  v_zx, v_zy, v_zz);
92 }
93 
94 KY_INLINE Matrix3x3f::Matrix3x3f(const Vec3f& v_x, const Vec3f& v_y, const Vec3f& v_z)
95 {
96  Set(v_x, v_y, v_z);
97 }
98 
99 KY_INLINE Matrix3x3f::Matrix3x3f(const Vec3f& axis, KyFloat32 angleRad)
100 {
101  SetRotation(axis, angleRad);
102 }
103 
104 KY_INLINE Matrix3x3f Matrix3x3f::Identity()
105 {
106  return Matrix3x3f(
107  1.0f, 0.0f, 0.0f,
108  0.0f, 1.0f, 0.0f,
109  0.0f, 0.0f, 1.0f);
110 }
111 
112 KY_INLINE void Matrix3x3f::Set(
113  KyFloat32 v_xx, KyFloat32 v_xy, KyFloat32 v_xz,
114  KyFloat32 v_yx, KyFloat32 v_yy, KyFloat32 v_yz,
115  KyFloat32 v_zx, KyFloat32 v_zy, KyFloat32 v_zz)
116 {
117  m[xx] = v_xx; m[xy] = v_xy; m[xz] = v_xz;
118  m[yx] = v_yx; m[yy] = v_yy; m[yz] = v_yz;
119  m[zx] = v_zx; m[zy] = v_zy; m[zz] = v_zz;
120 }
121 
122 KY_INLINE void Matrix3x3f::Set(const Vec3f& v_x, const Vec3f& v_y, const Vec3f& v_z)
123 {
124  Set(v_x.x, v_x.y, v_x.z,
125  v_y.x, v_y.y, v_y.z,
126  v_z.x, v_z.y, v_z.z);
127 }
128 
129 KY_INLINE void Matrix3x3f::SetIdentity()
130 {
131  Set(1.0f, 0.0f, 0.0f,
132  0.0f, 1.0f, 0.0f,
133  0.0f, 0.0f, 1.0f);
134 }
135 
136 KY_INLINE const Vec3f& Matrix3x3f::GetRow(KyUInt32 index) const
137 {
138  KY_ASSERT(index < 3);
139  return *(Vec3f*)(&m[xx] + index * 3);
140 }
141 
142 KY_INLINE Vec3f& Matrix3x3f::GetRow(KyUInt32 index)
143 {
144  KY_ASSERT(index < 3);
145  return *(Vec3f*)(&m[xx] + index * 3);
146 }
147 
149 KY_INLINE Vec3f Matrix3x3f::operator*(const Vec3f& v) const
150 {
151  return Vec3f(
152  m[xx] * v.x + m[yx] * v.y + m[zx] * v.z,
153  m[xy] * v.x + m[yy] * v.y + m[zy] * v.z,
154  m[xz] * v.x + m[yz] * v.y + m[zz] * v.z);
155 }
156 
157 KY_INLINE void Matrix3x3f::Transform(const Vec3f& v, Vec3f& transformed) const
158 {
159  transformed = *this * v;
160 }
161 
162 KY_INLINE bool Matrix3x3f::operator==(const Matrix3x3f& other) const
163 {
164  for (int i = 0; i < 9; ++i)
165  if (m[i] != other.m[i])
166  return false;
167  return true;
168 }
169 
170 KY_INLINE bool Matrix3x3f::operator != (const Matrix3x3f& other) const
171 {
172  return !operator==(other);
173 }
174 
175 } // namespace Kaim
176 
177 #endif // Navigation_Matrix3x3f_H
3x3 matrix.
Definition: matrix3x3f.h:21
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:35
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
void SetRotation(const Vec3f &axis, KyFloat32 angleRad)
Set as angleRad rotation matrix around axis.
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
This class represents a three-dimensional 6 freedom degrees unit transform.
Definition: transform.h:20
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
Vec3f operator*(const Vec3f &v) const
Returns the product of this matrix and v.
Definition: matrix3x3f.h:159