PxMat44.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_PXMAT44_H
00031 #define PXFOUNDATION_PXMAT44_H
00032 
00036 #include "foundation/PxQuat.h"
00037 #include "foundation/PxVec4.h"
00038 #include "foundation/PxMat33.h"
00039 #include "foundation/PxTransform.h"
00040 
00041 #if !PX_DOXYGEN
00042 namespace physx
00043 {
00044 #endif
00045 
00054 class PxMat44
00055 {
00056   public:
00058     PX_CUDA_CALLABLE PX_INLINE PxMat44()
00059     {
00060     }
00061 
00063     PX_CUDA_CALLABLE PX_INLINE PxMat44(PxIDENTITY r)
00064     : column0(1.0f, 0.0f, 0.0f, 0.0f)
00065     , column1(0.0f, 1.0f, 0.0f, 0.0f)
00066     , column2(0.0f, 0.0f, 1.0f, 0.0f)
00067     , column3(0.0f, 0.0f, 0.0f, 1.0f)
00068     {
00069         PX_UNUSED(r);
00070     }
00071 
00073     PX_CUDA_CALLABLE PX_INLINE PxMat44(PxZERO r) : column0(PxZero), column1(PxZero), column2(PxZero), column3(PxZero)
00074     {
00075         PX_UNUSED(r);
00076     }
00077 
00079     PX_CUDA_CALLABLE PxMat44(const PxVec4& col0, const PxVec4& col1, const PxVec4& col2, const PxVec4& col3)
00080     : column0(col0), column1(col1), column2(col2), column3(col3)
00081     {
00082     }
00083 
00085     explicit PX_CUDA_CALLABLE PX_INLINE PxMat44(float r)
00086     : column0(r, 0.0f, 0.0f, 0.0f)
00087     , column1(0.0f, r, 0.0f, 0.0f)
00088     , column2(0.0f, 0.0f, r, 0.0f)
00089     , column3(0.0f, 0.0f, 0.0f, r)
00090     {
00091     }
00092 
00094     PX_CUDA_CALLABLE PxMat44(const PxVec3& col0, const PxVec3& col1, const PxVec3& col2, const PxVec3& col3)
00095     : column0(col0, 0), column1(col1, 0), column2(col2, 0), column3(col3, 1.0f)
00096     {
00097     }
00098 
00100     explicit PX_CUDA_CALLABLE PX_INLINE PxMat44(float values[])
00101     : column0(values[0], values[1], values[2], values[3])
00102     , column1(values[4], values[5], values[6], values[7])
00103     , column2(values[8], values[9], values[10], values[11])
00104     , column3(values[12], values[13], values[14], values[15])
00105     {
00106     }
00107 
00109     explicit PX_CUDA_CALLABLE PX_INLINE PxMat44(const PxQuat& q)
00110     {
00111         const float x = q.x;
00112         const float y = q.y;
00113         const float z = q.z;
00114         const float w = q.w;
00115 
00116         const float x2 = x + x;
00117         const float y2 = y + y;
00118         const float z2 = z + z;
00119 
00120         const float xx = x2 * x;
00121         const float yy = y2 * y;
00122         const float zz = z2 * z;
00123 
00124         const float xy = x2 * y;
00125         const float xz = x2 * z;
00126         const float xw = x2 * w;
00127 
00128         const float yz = y2 * z;
00129         const float yw = y2 * w;
00130         const float zw = z2 * w;
00131 
00132         column0 = PxVec4(1.0f - yy - zz, xy + zw, xz - yw, 0.0f);
00133         column1 = PxVec4(xy - zw, 1.0f - xx - zz, yz + xw, 0.0f);
00134         column2 = PxVec4(xz + yw, yz - xw, 1.0f - xx - yy, 0.0f);
00135         column3 = PxVec4(0.0f, 0.0f, 0.0f, 1.0f);
00136     }
00137 
00139     explicit PX_CUDA_CALLABLE PX_INLINE PxMat44(const PxVec4& diagonal)
00140     : column0(diagonal.x, 0.0f, 0.0f, 0.0f)
00141     , column1(0.0f, diagonal.y, 0.0f, 0.0f)
00142     , column2(0.0f, 0.0f, diagonal.z, 0.0f)
00143     , column3(0.0f, 0.0f, 0.0f, diagonal.w)
00144     {
00145     }
00146 
00148     PX_CUDA_CALLABLE PxMat44(const PxMat33& axes, const PxVec3& position)
00149     : column0(axes.column0, 0.0f), column1(axes.column1, 0.0f), column2(axes.column2, 0.0f), column3(position, 1.0f)
00150     {
00151     }
00152 
00153     PX_CUDA_CALLABLE PxMat44(const PxTransform& t)
00154     {
00155         *this = PxMat44(PxMat33(t.q), t.p);
00156     }
00157 
00161     PX_CUDA_CALLABLE PX_INLINE bool operator==(const PxMat44& m) const
00162     {
00163         return column0 == m.column0 && column1 == m.column1 && column2 == m.column2 && column3 == m.column3;
00164     }
00165 
00167     PX_CUDA_CALLABLE PX_INLINE PxMat44(const PxMat44& other)
00168     : column0(other.column0), column1(other.column1), column2(other.column2), column3(other.column3)
00169     {
00170     }
00171 
00173     PX_CUDA_CALLABLE PX_INLINE PxMat44& operator=(const PxMat44& other)
00174     {
00175         column0 = other.column0;
00176         column1 = other.column1;
00177         column2 = other.column2;
00178         column3 = other.column3;
00179         return *this;
00180     }
00181 
00183     PX_CUDA_CALLABLE PX_INLINE const PxMat44 getTranspose() const
00184     {
00185         return PxMat44(
00186             PxVec4(column0.x, column1.x, column2.x, column3.x), PxVec4(column0.y, column1.y, column2.y, column3.y),
00187             PxVec4(column0.z, column1.z, column2.z, column3.z), PxVec4(column0.w, column1.w, column2.w, column3.w));
00188     }
00189 
00191     PX_CUDA_CALLABLE PX_INLINE const PxMat44 operator-() const
00192     {
00193         return PxMat44(-column0, -column1, -column2, -column3);
00194     }
00195 
00197     PX_CUDA_CALLABLE PX_INLINE const PxMat44 operator+(const PxMat44& other) const
00198     {
00199         return PxMat44(column0 + other.column0, column1 + other.column1, column2 + other.column2,
00200                        column3 + other.column3);
00201     }
00202 
00204     PX_CUDA_CALLABLE PX_INLINE const PxMat44 operator-(const PxMat44& other) const
00205     {
00206         return PxMat44(column0 - other.column0, column1 - other.column1, column2 - other.column2,
00207                        column3 - other.column3);
00208     }
00209 
00211     PX_CUDA_CALLABLE PX_INLINE const PxMat44 operator*(float scalar) const
00212     {
00213         return PxMat44(column0 * scalar, column1 * scalar, column2 * scalar, column3 * scalar);
00214     }
00215 
00216     friend PxMat44 operator*(float, const PxMat44&);
00217 
00219     PX_CUDA_CALLABLE PX_INLINE const PxMat44 operator*(const PxMat44& other) const
00220     {
00221         // Rows from this <dot> columns from other
00222         // column0 = transform(other.column0) etc
00223         return PxMat44(transform(other.column0), transform(other.column1), transform(other.column2),
00224                        transform(other.column3));
00225     }
00226 
00227     // a <op>= b operators
00228 
00230     PX_CUDA_CALLABLE PX_INLINE PxMat44& operator+=(const PxMat44& other)
00231     {
00232         column0 += other.column0;
00233         column1 += other.column1;
00234         column2 += other.column2;
00235         column3 += other.column3;
00236         return *this;
00237     }
00238 
00240     PX_CUDA_CALLABLE PX_INLINE PxMat44& operator-=(const PxMat44& other)
00241     {
00242         column0 -= other.column0;
00243         column1 -= other.column1;
00244         column2 -= other.column2;
00245         column3 -= other.column3;
00246         return *this;
00247     }
00248 
00250     PX_CUDA_CALLABLE PX_INLINE PxMat44& operator*=(float scalar)
00251     {
00252         column0 *= scalar;
00253         column1 *= scalar;
00254         column2 *= scalar;
00255         column3 *= scalar;
00256         return *this;
00257     }
00258 
00260     PX_CUDA_CALLABLE PX_INLINE PxMat44& operator*=(const PxMat44& other)
00261     {
00262         *this = *this * other;
00263         return *this;
00264     }
00265 
00267     PX_DEPRECATED PX_CUDA_CALLABLE PX_FORCE_INLINE float operator()(unsigned int row, unsigned int col) const
00268     {
00269         return (*this)[col][row];
00270     }
00271 
00273     PX_DEPRECATED PX_CUDA_CALLABLE PX_FORCE_INLINE float& operator()(unsigned int row, unsigned int col)
00274     {
00275         return (*this)[col][row];
00276     }
00277 
00279     PX_CUDA_CALLABLE PX_INLINE const PxVec4 transform(const PxVec4& other) const
00280     {
00281         return column0 * other.x + column1 * other.y + column2 * other.z + column3 * other.w;
00282     }
00283 
00285     PX_CUDA_CALLABLE PX_INLINE const PxVec3 transform(const PxVec3& other) const
00286     {
00287         return transform(PxVec4(other, 1.0f)).getXYZ();
00288     }
00289 
00291     PX_CUDA_CALLABLE PX_INLINE const PxVec4 rotate(const PxVec4& other) const
00292     {
00293         return column0 * other.x + column1 * other.y + column2 * other.z; // + column3*0;
00294     }
00295 
00297     PX_CUDA_CALLABLE PX_INLINE const PxVec3 rotate(const PxVec3& other) const
00298     {
00299         return rotate(PxVec4(other, 1.0f)).getXYZ();
00300     }
00301 
00302     PX_CUDA_CALLABLE PX_INLINE const PxVec3 getBasis(int num) const
00303     {
00304         PX_ASSERT(num >= 0 && num < 3);
00305         return (&column0)[num].getXYZ();
00306     }
00307 
00308     PX_CUDA_CALLABLE PX_INLINE const PxVec3 getPosition() const
00309     {
00310         return column3.getXYZ();
00311     }
00312 
00313     PX_CUDA_CALLABLE PX_INLINE void setPosition(const PxVec3& position)
00314     {
00315         column3.x = position.x;
00316         column3.y = position.y;
00317         column3.z = position.z;
00318     }
00319 
00320     PX_CUDA_CALLABLE PX_FORCE_INLINE const float* front() const
00321     {
00322         return &column0.x;
00323     }
00324 
00325     PX_DEPRECATED PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec4& operator[](unsigned int num)
00326     {
00327         return (&column0)[num];
00328     }
00329     PX_DEPRECATED PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec4& operator[](unsigned int num) const
00330     {
00331         return (&column0)[num];
00332     }
00333 
00334     PX_CUDA_CALLABLE PX_INLINE void scale(const PxVec4& p)
00335     {
00336         column0 *= p.x;
00337         column1 *= p.y;
00338         column2 *= p.z;
00339         column3 *= p.w;
00340     }
00341 
00342     PX_CUDA_CALLABLE PX_INLINE const PxMat44 inverseRT(void) const
00343     {
00344         PxVec3 r0(column0.x, column1.x, column2.x), r1(column0.y, column1.y, column2.y),
00345             r2(column0.z, column1.z, column2.z);
00346 
00347         return PxMat44(r0, r1, r2, -(r0 * column3.x + r1 * column3.y + r2 * column3.z));
00348     }
00349 
00350     PX_CUDA_CALLABLE PX_INLINE bool isFinite() const
00351     {
00352         return column0.isFinite() && column1.isFinite() && column2.isFinite() && column3.isFinite();
00353     }
00354 
00355     // Data, see above for format!
00356 
00357     PxVec4 column0, column1, column2, column3; // the four base vectors
00358 };
00359 
00360 // implementation from PxTransform.h
00361 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform::PxTransform(const PxMat44& m)
00362 {
00363     PxVec3 column0 = PxVec3(m.column0.x, m.column0.y, m.column0.z);
00364     PxVec3 column1 = PxVec3(m.column1.x, m.column1.y, m.column1.z);
00365     PxVec3 column2 = PxVec3(m.column2.x, m.column2.y, m.column2.z);
00366 
00367     q = PxQuat(PxMat33(column0, column1, column2));
00368     p = PxVec3(m.column3.x, m.column3.y, m.column3.z);
00369 }
00370 
00371 #if !PX_DOXYGEN
00372 } // namespace physx
00373 #endif
00374 
00376 #endif // #ifndef PXFOUNDATION_PXMAT44_H


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