NVIDIA(R) PhysX(R) SDK 3.4 API Reference: PxMat33.h Source File

NVIDIA PhysX API

PxMat33.h

Go to the documentation of this file.
00001 // This code contains NVIDIA Confidential Information and is disclosed to you
00002 // under a form of NVIDIA software license agreement provided separately to you.
00003 //
00004 // Notice
00005 // NVIDIA Corporation and its licensors retain all intellectual property and
00006 // proprietary rights in and to this software and related documentation and
00007 // any modifications thereto. Any use, reproduction, disclosure, or
00008 // distribution of this software and related documentation without an express
00009 // license agreement from NVIDIA Corporation is strictly prohibited.
00010 //
00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
00015 //
00016 // Information and code furnished is believed to be accurate and reliable.
00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
00018 // information or for any infringement of patents or other rights of third parties that may
00019 // result from its use. No license is granted by implication or otherwise under any patent
00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
00021 // This code supersedes and replaces all information previously supplied.
00022 // NVIDIA Corporation products are not authorized for use as critical
00023 // components in life support devices or systems without express written approval of
00024 // NVIDIA Corporation.
00025 //
00026 // Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved.
00027 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
00028 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
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     // a <op>= b operators
00268 
00270     PX_CUDA_CALLABLE PX_FORCE_INLINE const PxMat33 operator*(const PxMat33& other) const
00271     {
00272         // Rows from this <dot> columns from other
00273         // column0 = transform(other.column0) etc
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     // Transform etc
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     // Data, see above for format!
00352 
00353     PxVec3 column0, column1, column2; // the three base vectors
00354 };
00355 
00356 // implementation from PxQuat.h
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 } // namespace physx
00393 #endif
00394 
00396 #endif // #ifndef PXFOUNDATION_PXMAT33_H


Copyright © 2008-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com