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-2012 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 00031 #ifndef PX_FOUNDATION_PX_MAT44_H 00032 #define PX_FOUNDATION_PX_MAT44_H 00033 00037 #include "foundation/PxQuat.h" 00038 #include "foundation/PxVec4.h" 00039 #include "foundation/PxMat33.h" 00040 #include "foundation/PxTransform.h" 00041 00042 #ifndef PX_DOXYGEN 00043 namespace physx 00044 { 00045 #endif 00046 00055 class PxMat44 00056 { 00057 public: 00059 PX_CUDA_CALLABLE PX_INLINE PxMat44() 00060 {} 00061 00063 PX_CUDA_CALLABLE PxMat44(const PxVec4& col0, const PxVec4& col1, const PxVec4& col2, const PxVec4 &col3) 00064 : column0(col0), column1(col1), column2(col2), column3(col3) 00065 {} 00066 00068 PX_CUDA_CALLABLE PxMat44(const PxVec3& column0, const PxVec3& column1, const PxVec3& column2, const PxVec3& column3) 00069 : column0(column0,0), column1(column1,0), column2(column2,0), column3(column3,1) 00070 {} 00071 00073 explicit PX_CUDA_CALLABLE PX_INLINE PxMat44(PxReal values[]): 00074 column0(values[0],values[1],values[2], values[3]), 00075 column1(values[4],values[5],values[6], values[7]), 00076 column2(values[8],values[9],values[10], values[11]), 00077 column3(values[12], values[13], values[14], values[15]) 00078 { 00079 } 00080 00082 explicit PX_CUDA_CALLABLE PX_INLINE PxMat44(const PxQuat& q) 00083 { 00084 const PxReal x = q.x; 00085 const PxReal y = q.y; 00086 const PxReal z = q.z; 00087 const PxReal w = q.w; 00088 00089 const PxReal x2 = x + x; 00090 const PxReal y2 = y + y; 00091 const PxReal z2 = z + z; 00092 00093 const PxReal xx = x2*x; 00094 const PxReal yy = y2*y; 00095 const PxReal zz = z2*z; 00096 00097 const PxReal xy = x2*y; 00098 const PxReal xz = x2*z; 00099 const PxReal xw = x2*w; 00100 00101 const PxReal yz = y2*z; 00102 const PxReal yw = y2*w; 00103 const PxReal zw = z2*w; 00104 00105 column0 = PxVec4(1.0f - yy - zz, xy + zw, xz - yw, 0.0f); 00106 column1 = PxVec4(xy - zw, 1.0f - xx - zz, yz + xw, 0.0f); 00107 column2 = PxVec4(xz + yw, yz - xw, 1.0f - xx - yy, 0.0f); 00108 column3 = PxVec4(0.0f, 0.0f, 0.0f, 1.0f); 00109 } 00110 00112 explicit PX_CUDA_CALLABLE PX_INLINE PxMat44(const PxVec4& diagonal): 00113 column0(diagonal.x,0.0f,0.0f,0.0f), 00114 column1(0.0f,diagonal.y,0.0f,0.0f), 00115 column2(0.0f,0.0f,diagonal.z,0.0f), 00116 column3(0.0f,0.0f,0.0f,diagonal.w) 00117 { 00118 } 00119 00120 PX_CUDA_CALLABLE PxMat44(const PxMat33& orientation, const PxVec3& position): 00121 column0(orientation.column0,0.0f), 00122 column1(orientation.column1,0.0f), 00123 column2(orientation.column2,0.0f), 00124 column3(position,1) 00125 { 00126 } 00127 00128 PX_CUDA_CALLABLE PxMat44(const PxTransform& t) 00129 { 00130 *this = PxMat44(PxMat33(t.q), t.p); 00131 } 00132 00134 PX_CUDA_CALLABLE PX_INLINE PxMat44(const PxMat44& other) 00135 : column0(other.column0), column1(other.column1), column2(other.column2), column3(other.column3) 00136 {} 00137 00139 PX_CUDA_CALLABLE PX_INLINE const PxMat44& operator=(const PxMat44& other) 00140 { 00141 column0 = other.column0; 00142 column1 = other.column1; 00143 column2 = other.column2; 00144 column3 = other.column3; 00145 return *this; 00146 } 00147 00148 PX_CUDA_CALLABLE PX_INLINE static PxMat44 createIdentity() 00149 { 00150 return PxMat44( 00151 PxVec4(1.0f,0.0f,0.0f,0.0f), 00152 PxVec4(0.0f,1.0f,0.0f,0.0f), 00153 PxVec4(0.0f,0.0f,1.0f,0.0f), 00154 PxVec4(0.0f,0.0f,0.0f,1.0f)); 00155 } 00156 00157 00158 PX_CUDA_CALLABLE PX_INLINE static PxMat44 createZero() 00159 { 00160 return PxMat44(PxVec4(0.0f), PxVec4(0.0f), PxVec4(0.0f), PxVec4(0.0f)); 00161 } 00162 00164 PX_CUDA_CALLABLE PX_INLINE PxMat44 getTranspose() const 00165 { 00166 return PxMat44(PxVec4(column0.x, column1.x, column2.x, column3.x), 00167 PxVec4(column0.y, column1.y, column2.y, column3.y), 00168 PxVec4(column0.z, column1.z, column2.z, column3.z), 00169 PxVec4(column0.w, column1.w, column2.w, column3.w)); 00170 } 00171 00173 PX_CUDA_CALLABLE PX_INLINE PxMat44 operator-() const 00174 { 00175 return PxMat44(-column0, -column1, -column2, -column3); 00176 } 00177 00179 PX_CUDA_CALLABLE PX_INLINE PxMat44 operator+(const PxMat44& other) const 00180 { 00181 return PxMat44( column0+other.column0, 00182 column1+other.column1, 00183 column2+other.column2, 00184 column3+other.column3); 00185 } 00186 00188 PX_CUDA_CALLABLE PX_INLINE PxMat44 operator-(const PxMat44& other) const 00189 { 00190 return PxMat44( column0-other.column0, 00191 column1-other.column1, 00192 column2-other.column2, 00193 column3-other.column3); 00194 } 00195 00197 PX_CUDA_CALLABLE PX_INLINE PxMat44 operator*(PxReal scalar) const 00198 { 00199 return PxMat44(column0*scalar, column1*scalar, column2*scalar, column3*scalar); 00200 } 00201 00202 friend PxMat44 operator*(PxReal, const PxMat44&); 00203 00205 PX_CUDA_CALLABLE PX_INLINE PxMat44 operator*(const PxMat44& other) const 00206 { 00207 //Rows from this <dot> columns from other 00208 //column0 = transform(other.column0) etc 00209 return PxMat44(transform(other.column0), transform(other.column1), transform(other.column2), transform(other.column3)); 00210 } 00211 00212 // a <op>= b operators 00213 00215 PX_CUDA_CALLABLE PX_INLINE PxMat44& operator+=(const PxMat44& other) 00216 { 00217 column0 += other.column0; 00218 column1 += other.column1; 00219 column2 += other.column2; 00220 column3 += other.column3; 00221 return *this; 00222 } 00223 00225 PX_CUDA_CALLABLE PX_INLINE PxMat44& operator-=(const PxMat44& other) 00226 { 00227 column0 -= other.column0; 00228 column1 -= other.column1; 00229 column2 -= other.column2; 00230 column3 -= other.column3; 00231 return *this; 00232 } 00233 00235 PX_CUDA_CALLABLE PX_INLINE PxMat44& operator*=(PxReal scalar) 00236 { 00237 column0 *= scalar; 00238 column1 *= scalar; 00239 column2 *= scalar; 00240 column3 *= scalar; 00241 return *this; 00242 } 00243 00245 PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal operator()(unsigned int row, unsigned int col) const 00246 { 00247 return (*this)[col][row]; 00248 } 00249 00251 PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal& operator()(unsigned int row, unsigned int col) 00252 { 00253 return (*this)[col][row]; 00254 } 00255 00257 PX_CUDA_CALLABLE PX_INLINE PxVec4 transform(const PxVec4& other) const 00258 { 00259 return column0*other.x + column1*other.y + column2*other.z + column3*other.w; 00260 } 00261 00263 PX_CUDA_CALLABLE PX_INLINE PxVec3 transform(const PxVec3& other) const 00264 { 00265 return transform(PxVec4(other,1)).getXYZ(); 00266 } 00267 00269 PX_CUDA_CALLABLE PX_INLINE PxVec4 rotate(const PxVec4& other) const 00270 { 00271 return column0*other.x + column1*other.y + column2*other.z;// + column3*0; 00272 } 00273 00275 PX_CUDA_CALLABLE PX_INLINE PxVec3 rotate(const PxVec3& other) const 00276 { 00277 return rotate(PxVec4(other,1)).getXYZ(); 00278 } 00279 00280 00281 PX_CUDA_CALLABLE PX_INLINE PxVec3 getBasis(int num) const 00282 { 00283 PX_ASSERT(num>=0 && num<3); 00284 return (&column0)[num].getXYZ(); 00285 } 00286 00287 PX_CUDA_CALLABLE PX_INLINE PxVec3 getPosition() const 00288 { 00289 return column3.getXYZ(); 00290 } 00291 00292 PX_CUDA_CALLABLE PX_INLINE void setPosition(const PxVec3& position) 00293 { 00294 column3.x = position.x; 00295 column3.y = position.y; 00296 column3.z = position.z; 00297 } 00298 00299 PX_CUDA_CALLABLE PX_FORCE_INLINE const PxReal* front() const 00300 { 00301 return &column0.x; 00302 } 00303 00304 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec4& operator[](int num) {return (&column0)[num];} 00305 PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec4& operator[](int num) const {return (&column0)[num];} 00306 00307 PX_CUDA_CALLABLE PX_INLINE void scale(const PxVec4& p) 00308 { 00309 column0 *= p.x; 00310 column1 *= p.y; 00311 column2 *= p.z; 00312 column3 *= p.w; 00313 } 00314 00315 PX_CUDA_CALLABLE PX_INLINE PxMat44 inverseRT(void) const 00316 { 00317 PxVec3 r0(column0.x, column1.x, column2.x), 00318 r1(column0.y, column1.y, column2.y), 00319 r2(column0.z, column1.z, column2.z); 00320 00321 return PxMat44(r0, r1, r2, -(r0 * column3.x + r1 * column3.y + r2 * column3.z)); 00322 } 00323 00324 PX_CUDA_CALLABLE PX_INLINE bool isFinite() const 00325 { 00326 return column0.isFinite() && column1.isFinite() && column2.isFinite() && column3.isFinite(); 00327 } 00328 00329 00330 //Data, see above for format! 00331 00332 PxVec4 column0, column1, column2, column3; //the four base vectors 00333 }; 00334 00335 // implementation from PxTransform.h 00336 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform::PxTransform(const PxMat44& m) 00337 { 00338 PxVec3 column0 = PxVec3(m.column0.x, m.column0.y, m.column0.z); 00339 PxVec3 column1 = PxVec3(m.column1.x, m.column1.y, m.column1.z); 00340 PxVec3 column2 = PxVec3(m.column2.x, m.column2.y, m.column2.z); 00341 00342 q = PxQuat(PxMat33(column0, column1, column2)); 00343 p = PxVec3(m.column3.x, m.column3.y, m.column3.z); 00344 } 00345 00346 #ifndef PX_DOXYGEN 00347 } // namespace physx 00348 #endif 00349 00351 #endif // PX_FOUNDATION_PX_MAT44_H
Copyright © 2008-2012 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com