00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef PXFOUNDATION_PXMAT33_H
00031 #define PXFOUNDATION_PXMAT33_H
00032
00036 #include "foundation/PxVec3.h"
00037 #include "foundation/PxQuat.h"
00038
00039 #if !PX_DOXYGEN
00040 namespace physx
00041 {
00042 #endif
00043
00090 class PxMat33
00091 {
00092 public:
00094 PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat33()
00095 {
00096 }
00097
00099 PX_CUDA_CALLABLE PX_INLINE PxMat33(PxIDENTITY r)
00100 : column0(1.0f, 0.0f, 0.0f), column1(0.0f, 1.0f, 0.0f), column2(0.0f, 0.0f, 1.0f)
00101 {
00102 PX_UNUSED(r);
00103 }
00104
00106 PX_CUDA_CALLABLE PX_INLINE PxMat33(PxZERO r) : column0(0.0f), column1(0.0f), column2(0.0f)
00107 {
00108 PX_UNUSED(r);
00109 }
00110
00112 PX_CUDA_CALLABLE PxMat33(const PxVec3& col0, const PxVec3& col1, const PxVec3& col2)
00113 : column0(col0), column1(col1), column2(col2)
00114 {
00115 }
00116
00118 explicit PX_CUDA_CALLABLE PX_INLINE PxMat33(float r)
00119 : column0(r, 0.0f, 0.0f), column1(0.0f, r, 0.0f), column2(0.0f, 0.0f, r)
00120 {
00121 }
00122
00124 explicit PX_CUDA_CALLABLE PX_INLINE PxMat33(float values[])
00125 : column0(values[0], values[1], values[2])
00126 , column1(values[3], values[4], values[5])
00127 , column2(values[6], values[7], values[8])
00128 {
00129 }
00130
00132 explicit PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat33(const PxQuat& q)
00133 {
00134 const float x = q.x;
00135 const float y = q.y;
00136 const float z = q.z;
00137 const float w = q.w;
00138
00139 const float x2 = x + x;
00140 const float y2 = y + y;
00141 const float z2 = z + z;
00142
00143 const float xx = x2 * x;
00144 const float yy = y2 * y;
00145 const float zz = z2 * z;
00146
00147 const float xy = x2 * y;
00148 const float xz = x2 * z;
00149 const float xw = x2 * w;
00150
00151 const float yz = y2 * z;
00152 const float yw = y2 * w;
00153 const float zw = z2 * w;
00154
00155 column0 = PxVec3(1.0f - yy - zz, xy + zw, xz - yw);
00156 column1 = PxVec3(xy - zw, 1.0f - xx - zz, yz + xw);
00157 column2 = PxVec3(xz + yw, yz - xw, 1.0f - xx - yy);
00158 }
00159
00161 PX_CUDA_CALLABLE PX_INLINE PxMat33(const PxMat33& other)
00162 : column0(other.column0), column1(other.column1), column2(other.column2)
00163 {
00164 }
00165
00167 PX_CUDA_CALLABLE PX_FORCE_INLINE PxMat33& operator=(const PxMat33& other)
00168 {
00169 column0 = other.column0;
00170 column1 = other.column1;
00171 column2 = other.column2;
00172 return *this;
00173 }
00174
00176 PX_CUDA_CALLABLE PX_INLINE static const PxMat33 createDiagonal(const PxVec3& d)
00177 {
00178 return PxMat33(PxVec3(d.x, 0.0f, 0.0f), PxVec3(0.0f, d.y, 0.0f), PxVec3(0.0f, 0.0f, d.z));
00179 }
00180
00184 PX_CUDA_CALLABLE PX_INLINE bool operator==(const PxMat33& m) const
00185 {
00186 return column0 == m.column0 && column1 == m.column1 && column2 == m.column2;
00187 }
00188
00190 PX_CUDA_CALLABLE PX_FORCE_INLINE const PxMat33 getTranspose() const
00191 {
00192 const PxVec3 v0(column0.x, column1.x, column2.x);
00193 const PxVec3 v1(column0.y, column1.y, column2.y);
00194 const PxVec3 v2(column0.z, column1.z, column2.z);
00195
00196 return PxMat33(v0, v1, v2);
00197 }
00198
00200 PX_CUDA_CALLABLE PX_INLINE const PxMat33 getInverse() const
00201 {
00202 const float det = getDeterminant();
00203 PxMat33 inverse;
00204
00205 if(det != 0)
00206 {
00207 const float invDet = 1.0f / det;
00208
00209 inverse.column0.x = invDet * (column1.y * column2.z - column2.y * column1.z);
00210 inverse.column0.y = invDet * -(column0.y * column2.z - column2.y * column0.z);
00211 inverse.column0.z = invDet * (column0.y * column1.z - column0.z * column1.y);
00212
00213 inverse.column1.x = invDet * -(column1.x * column2.z - column1.z * column2.x);
00214 inverse.column1.y = invDet * (column0.x * column2.z - column0.z * column2.x);
00215 inverse.column1.z = invDet * -(column0.x * column1.z - column0.z * column1.x);
00216
00217 inverse.column2.x = invDet * (column1.x * column2.y - column1.y * column2.x);
00218 inverse.column2.y = invDet * -(column0.x * column2.y - column0.y * column2.x);
00219 inverse.column2.z = invDet * (column0.x * column1.y - column1.x * column0.y);
00220
00221 return inverse;
00222 }
00223 else
00224 {
00225 return PxMat33(PxIdentity);
00226 }
00227 }
00228
00230 PX_CUDA_CALLABLE PX_INLINE float getDeterminant() const
00231 {
00232 return column0.dot(column1.cross(column2));
00233 }
00234
00236 PX_CUDA_CALLABLE PX_INLINE const PxMat33 operator-() const
00237 {
00238 return PxMat33(-column0, -column1, -column2);
00239 }
00240
00242 PX_CUDA_CALLABLE PX_INLINE const PxMat33 operator+(const PxMat33& other) const
00243 {
00244 return PxMat33(column0 + other.column0, column1 + other.column1, column2 + other.column2);
00245 }
00246
00248 PX_CUDA_CALLABLE PX_INLINE const PxMat33 operator-(const PxMat33& other) const
00249 {
00250 return PxMat33(column0 - other.column0, column1 - other.column1, column2 - other.column2);
00251 }
00252
00254 PX_CUDA_CALLABLE PX_INLINE const PxMat33 operator*(float scalar) const
00255 {
00256 return PxMat33(column0 * scalar, column1 * scalar, column2 * scalar);
00257 }
00258
00259 friend PxMat33 operator*(float, const PxMat33&);
00260
00262 PX_CUDA_CALLABLE PX_INLINE const PxVec3 operator*(const PxVec3& vec) const
00263 {
00264 return transform(vec);
00265 }
00266
00267
00268
00270 PX_CUDA_CALLABLE PX_FORCE_INLINE const PxMat33 operator*(const PxMat33& other) const
00271 {
00272
00273
00274 return PxMat33(transform(other.column0), transform(other.column1), transform(other.column2));
00275 }
00276
00278 PX_CUDA_CALLABLE PX_INLINE PxMat33& operator+=(const PxMat33& other)
00279 {
00280 column0 += other.column0;
00281 column1 += other.column1;
00282 column2 += other.column2;
00283 return *this;
00284 }
00285
00287 PX_CUDA_CALLABLE PX_INLINE PxMat33& operator-=(const PxMat33& other)
00288 {
00289 column0 -= other.column0;
00290 column1 -= other.column1;
00291 column2 -= other.column2;
00292 return *this;
00293 }
00294
00296 PX_CUDA_CALLABLE PX_INLINE PxMat33& operator*=(float scalar)
00297 {
00298 column0 *= scalar;
00299 column1 *= scalar;
00300 column2 *= scalar;
00301 return *this;
00302 }
00303
00305 PX_CUDA_CALLABLE PX_INLINE PxMat33& operator*=(const PxMat33& other)
00306 {
00307 *this = *this * other;
00308 return *this;
00309 }
00310
00312 PX_DEPRECATED PX_CUDA_CALLABLE PX_FORCE_INLINE float operator()(unsigned int row, unsigned int col) const
00313 {
00314 return (*this)[col][row];
00315 }
00316
00318 PX_DEPRECATED PX_CUDA_CALLABLE PX_FORCE_INLINE float& operator()(unsigned int row, unsigned int col)
00319 {
00320 return (*this)[col][row];
00321 }
00322
00323
00324
00326 PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec3 transform(const PxVec3& other) const
00327 {
00328 return column0 * other.x + column1 * other.y + column2 * other.z;
00329 }
00330
00332 PX_CUDA_CALLABLE PX_INLINE const PxVec3 transformTranspose(const PxVec3& other) const
00333 {
00334 return PxVec3(column0.dot(other), column1.dot(other), column2.dot(other));
00335 }
00336
00337 PX_CUDA_CALLABLE PX_FORCE_INLINE const float* front() const
00338 {
00339 return &column0.x;
00340 }
00341
00342 PX_DEPRECATED PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3& operator[](unsigned int num)
00343 {
00344 return (&column0)[num];
00345 }
00346 PX_DEPRECATED PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec3& operator[](unsigned int num) const
00347 {
00348 return (&column0)[num];
00349 }
00350
00351
00352
00353 PxVec3 column0, column1, column2;
00354 };
00355
00356
00357 PX_CUDA_CALLABLE PX_INLINE PxQuat::PxQuat(const PxMat33& m)
00358 {
00359 if(m.column2.z < 0)
00360 {
00361 if(m.column0.x > m.column1.y)
00362 {
00363 float t = 1 + m.column0.x - m.column1.y - m.column2.z;
00364 *this = PxQuat(t, m.column0.y + m.column1.x, m.column2.x + m.column0.z, m.column1.z - m.column2.y) *
00365 (0.5f / PxSqrt(t));
00366 }
00367 else
00368 {
00369 float t = 1 - m.column0.x + m.column1.y - m.column2.z;
00370 *this = PxQuat(m.column0.y + m.column1.x, t, m.column1.z + m.column2.y, m.column2.x - m.column0.z) *
00371 (0.5f / PxSqrt(t));
00372 }
00373 }
00374 else
00375 {
00376 if(m.column0.x < -m.column1.y)
00377 {
00378 float t = 1 - m.column0.x - m.column1.y + m.column2.z;
00379 *this = PxQuat(m.column2.x + m.column0.z, m.column1.z + m.column2.y, t, m.column0.y - m.column1.x) *
00380 (0.5f / PxSqrt(t));
00381 }
00382 else
00383 {
00384 float t = 1 + m.column0.x + m.column1.y + m.column2.z;
00385 *this = PxQuat(m.column1.z - m.column2.y, m.column2.x - m.column0.z, m.column0.y - m.column1.x, t) *
00386 (0.5f / PxSqrt(t));
00387 }
00388 }
00389 }
00390
00391 #if !PX_DOXYGEN
00392 }
00393 #endif
00394
00396 #endif // #ifndef PXFOUNDATION_PXMAT33_H