PxTransform.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_TRANSFORM_H 00032 #define PX_FOUNDATION_PX_TRANSFORM_H 00033 00037 #include "foundation/PxQuat.h" 00038 #include "foundation/PxPlane.h" 00039 00040 #ifndef PX_DOXYGEN 00041 namespace physx 00042 { 00043 #endif 00044 00049 class PxTransform 00050 { 00051 public: 00052 PxQuat q; 00053 PxVec3 p; 00054 00055 //#define PXTRANSFORM_DEFAULT_CONSTRUCT_NAN 00056 00057 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform() 00058 #ifdef PXTRANSFORM_DEFAULT_CONSTRUCT_IDENTITY 00059 : q(0, 0, 0, 1), p(0, 0, 0) 00060 #elif defined(PXTRANSFORM_DEFAULT_CONSTRUCT_NAN) 00061 #define invalid PxSqrt(-1.0f) 00062 : q(invalid, invalid, invalid, invalid), p(invalid, invalid, invalid) 00063 #undef invalid 00064 #endif 00065 { 00066 } 00067 00068 PX_CUDA_CALLABLE PX_FORCE_INLINE explicit PxTransform(const PxVec3& position): q(0, 0, 0, 1), p(position) 00069 { 00070 } 00071 00072 PX_CUDA_CALLABLE PX_FORCE_INLINE explicit PxTransform(const PxQuat& orientation): q(orientation), p(0, 0, 0) 00073 { 00074 PX_ASSERT(orientation.isSane()); 00075 } 00076 00077 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform(const PxVec3& p0, const PxQuat& q0): q(q0), p(p0) 00078 { 00079 PX_ASSERT(q0.isSane()); 00080 } 00081 00082 PX_CUDA_CALLABLE PX_FORCE_INLINE explicit PxTransform(const PxMat44& m); // defined in PxMat44.h 00083 00084 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform operator*(const PxTransform& x) const 00085 { 00086 PX_ASSERT(x.isSane()); 00087 return transform(x); 00088 } 00089 00090 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform getInverse() const 00091 { 00092 PX_ASSERT(isFinite()); 00093 return PxTransform(q.rotateInv(-p),q.getConjugate()); 00094 } 00095 00096 00097 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 transform(const PxVec3& input) const 00098 { 00099 PX_ASSERT(isFinite()); 00100 return q.rotate(input) + p; 00101 } 00102 00103 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 transformInv(const PxVec3& input) const 00104 { 00105 PX_ASSERT(isFinite()); 00106 return q.rotateInv(input-p); 00107 } 00108 00109 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 rotate(const PxVec3& input) const 00110 { 00111 PX_ASSERT(isFinite()); 00112 return q.rotate(input); 00113 } 00114 00115 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 rotateInv(const PxVec3& input) const 00116 { 00117 PX_ASSERT(isFinite()); 00118 return q.rotateInv(input); 00119 } 00120 00122 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform transform(const PxTransform& src) const 00123 { 00124 PX_ASSERT(src.isSane()); 00125 PX_ASSERT(isSane()); 00126 // src = [srct, srcr] -> [r*srct + t, r*srcr] 00127 return PxTransform(q.rotate(src.p) + p, q*src.q); 00128 } 00129 00134 PX_CUDA_CALLABLE bool isValid() const 00135 { 00136 return p.isFinite() && q.isFinite() && q.isUnit(); 00137 } 00138 00143 PX_CUDA_CALLABLE bool isSane() const 00144 { 00145 return isFinite() && q.isSane(); 00146 } 00147 00148 00152 PX_CUDA_CALLABLE PX_FORCE_INLINE bool isFinite() const { return p.isFinite() && q.isFinite(); } 00153 00155 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform transformInv(const PxTransform& src) const 00156 { 00157 PX_ASSERT(src.isSane()); 00158 PX_ASSERT(isFinite()); 00159 // src = [srct, srcr] -> [r^-1*(srct-t), r^-1*srcr] 00160 PxQuat qinv = q.getConjugate(); 00161 return PxTransform(qinv.rotate(src.p - p), qinv*src.q); 00162 } 00163 00164 PX_CUDA_CALLABLE static PX_FORCE_INLINE PxTransform createIdentity() 00165 { 00166 return PxTransform(PxVec3(0)); 00167 } 00168 00173 PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane transform(const PxPlane& plane) const 00174 { 00175 PxVec3 transformedNormal = rotate(plane.n); 00176 return PxPlane(transformedNormal, plane.d - p.dot(transformedNormal)); 00177 } 00178 00183 PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane inverseTransform(const PxPlane& plane) const 00184 { 00185 PxVec3 transformedNormal = rotateInv(plane.n); 00186 return PxPlane(transformedNormal, plane.d + p.dot(plane.n)); 00187 } 00188 00189 00190 }; 00191 00192 #ifndef PX_DOXYGEN 00193 } // namespace physx 00194 #endif 00195 00197 #endif // PX_FOUNDATION_PX_TRANSFORM_H
Copyright © 2008-2012 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com