PxTransform.h

Go to the documentation of this file.
00001 //
00002 // Redistribution and use in source and binary forms, with or without
00003 // modification, are permitted provided that the following conditions
00004 // are met:
00005 //  * Redistributions of source code must retain the above copyright
00006 //    notice, this list of conditions and the following disclaimer.
00007 //  * Redistributions in binary form must reproduce the above copyright
00008 //    notice, this list of conditions and the following disclaimer in the
00009 //    documentation and/or other materials provided with the distribution.
00010 //  * Neither the name of NVIDIA CORPORATION nor the names of its
00011 //    contributors may be used to endorse or promote products derived
00012 //    from this software without specific prior written permission.
00013 //
00014 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
00015 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00016 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00017 // PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00018 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00019 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00020 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00021 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00022 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00023 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00024 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 //
00026 // Copyright (c) 2008-2018 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-2018 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com