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-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_PXTRANSFORM_H
00031 #define PXFOUNDATION_PXTRANSFORM_H
00032 
00036 #include "foundation/PxQuat.h"
00037 #include "foundation/PxPlane.h"
00038 
00039 #if !PX_DOXYGEN
00040 namespace physx
00041 {
00042 #endif
00043 
00048 class PxTransform
00049 {
00050   public:
00051     PxQuat q;
00052     PxVec3 p;
00053 
00054     PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform()
00055     {
00056     }
00057 
00058     PX_CUDA_CALLABLE PX_FORCE_INLINE explicit PxTransform(const PxVec3& position) : q(PxIdentity), p(position)
00059     {
00060     }
00061 
00062     PX_CUDA_CALLABLE PX_FORCE_INLINE explicit PxTransform(PxIDENTITY r) : q(PxIdentity), p(PxZero)
00063     {
00064         PX_UNUSED(r);
00065     }
00066 
00067     PX_CUDA_CALLABLE PX_FORCE_INLINE explicit PxTransform(const PxQuat& orientation) : q(orientation), p(0)
00068     {
00069         PX_ASSERT(orientation.isSane());
00070     }
00071 
00072     PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform(float x, float y, float z, PxQuat aQ = PxQuat(PxIdentity))
00073     : q(aQ), p(x, y, z)
00074     {
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 
00087     PX_CUDA_CALLABLE PX_INLINE bool operator==(const PxTransform& t) const
00088     {
00089         return p == t.p && q == t.q;
00090     }
00091 
00092     PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform operator*(const PxTransform& x) const
00093     {
00094         PX_ASSERT(x.isSane());
00095         return transform(x);
00096     }
00097 
00099     PX_CUDA_CALLABLE PX_INLINE PxTransform& operator*=(PxTransform& other)
00100     {
00101         *this = *this * other;
00102         return *this;
00103     }
00104 
00105     PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform getInverse() const
00106     {
00107         PX_ASSERT(isFinite());
00108         return PxTransform(q.rotateInv(-p), q.getConjugate());
00109     }
00110 
00111     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 transform(const PxVec3& input) const
00112     {
00113         PX_ASSERT(isFinite());
00114         return q.rotate(input) + p;
00115     }
00116 
00117     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 transformInv(const PxVec3& input) const
00118     {
00119         PX_ASSERT(isFinite());
00120         return q.rotateInv(input - p);
00121     }
00122 
00123     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 rotate(const PxVec3& input) const
00124     {
00125         PX_ASSERT(isFinite());
00126         return q.rotate(input);
00127     }
00128 
00129     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 rotateInv(const PxVec3& input) const
00130     {
00131         PX_ASSERT(isFinite());
00132         return q.rotateInv(input);
00133     }
00134 
00136     PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform transform(const PxTransform& src) const
00137     {
00138         PX_ASSERT(src.isSane());
00139         PX_ASSERT(isSane());
00140         // src = [srct, srcr] -> [r*srct + t, r*srcr]
00141         return PxTransform(q.rotate(src.p) + p, q * src.q);
00142     }
00143 
00148     PX_CUDA_CALLABLE bool isValid() const
00149     {
00150         return p.isFinite() && q.isFinite() && q.isUnit();
00151     }
00152 
00158     PX_CUDA_CALLABLE bool isSane() const
00159     {
00160         return isFinite() && q.isSane();
00161     }
00162 
00166     PX_CUDA_CALLABLE PX_FORCE_INLINE bool isFinite() const
00167     {
00168         return p.isFinite() && q.isFinite();
00169     }
00170 
00172     PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform transformInv(const PxTransform& src) const
00173     {
00174         PX_ASSERT(src.isSane());
00175         PX_ASSERT(isFinite());
00176         // src = [srct, srcr] -> [r^-1*(srct-t), r^-1*srcr]
00177         PxQuat qinv = q.getConjugate();
00178         return PxTransform(qinv.rotate(src.p - p), qinv * src.q);
00179     }
00180 
00185     PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane transform(const PxPlane& plane) const
00186     {
00187         PxVec3 transformedNormal = rotate(plane.n);
00188         return PxPlane(transformedNormal, plane.d - p.dot(transformedNormal));
00189     }
00190 
00195     PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane inverseTransform(const PxPlane& plane) const
00196     {
00197         PxVec3 transformedNormal = rotateInv(plane.n);
00198         return PxPlane(transformedNormal, plane.d + p.dot(plane.n));
00199     }
00200 
00204     PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform getNormalized() const
00205     {
00206         return PxTransform(p, q.getNormalized());
00207     }
00208 };
00209 
00210 #if !PX_DOXYGEN
00211 } // namespace physx
00212 #endif
00213 
00215 #endif // #ifndef PXFOUNDATION_PXTRANSFORM_H


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