px3Casts.h
Engine/source/T3D/physics/physx3/px3Casts.h
Public Functions
Detailed Description
Public Functions
px3Cast(const Box3F & box)
px3Cast(const F & from)
px3Cast(const MatrixF & xfm)
px3Cast(const physx::PxBounds3 & bounds)
px3Cast(const physx::PxExtendedVec3 & xvec)
px3Cast(const physx::PxQuat & quat)
px3Cast(const physx::PxTransform & xfm)
px3Cast(const physx::PxVec3 & vec)
px3Cast(const Point3F & point)
px3Cast(const QuatF & quat)
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _PX3CASTS_H_ 25#define _PX3CASTS_H_ 26 27#ifndef _MPOINT3_H_ 28#include "math/mPoint3.h" 29#endif 30#ifndef _MMATRIX_H_ 31#include "math/mMatrix.h" 32#endif 33#ifndef _MBOX_H_ 34#include "math/mBox.h" 35#endif 36#ifndef _MQUAT_H_ 37#include "math/mQuat.h" 38#endif 39#ifndef _MTRANSFORM_H_ 40#include "math/mTransform.h" 41#endif 42 43 44template <class T, class F> inline T px3Cast( const F &from ); 45 46//------------------------------------------------------------------------- 47 48template<> 49inline Point3F px3Cast( const physx::PxVec3 &vec ) 50{ 51 return Point3F( vec.x, vec.y, vec.z ); 52} 53 54template<> 55inline physx::PxVec3 px3Cast( const Point3F &point ) 56{ 57 return physx::PxVec3( point.x, point.y, point.z ); 58} 59//------------------------------------------------------------------------- 60template<> 61inline QuatF px3Cast( const physx::PxQuat &quat ) 62{ 63 /// The Torque quat has the opposite winding order. 64 return QuatF( -quat.x, -quat.y, -quat.z, quat.w ); 65} 66 67template<> 68inline physx::PxQuat px3Cast( const QuatF &quat ) 69{ 70 /// The Torque quat has the opposite winding order. 71 physx::PxQuat result( -quat.x, -quat.y, -quat.z, quat.w ); 72 return result; 73} 74//------------------------------------------------------------------------- 75 76template<> 77inline physx::PxExtendedVec3 px3Cast( const Point3F &point ) 78{ 79 return physx::PxExtendedVec3( point.x, point.y, point.z ); 80} 81 82template<> 83inline Point3F px3Cast( const physx::PxExtendedVec3 &xvec ) 84{ 85 return Point3F( xvec.x, xvec.y, xvec.z ); 86} 87 88//------------------------------------------------------------------------- 89 90template<> 91inline physx::PxBounds3 px3Cast( const Box3F &box ) 92{ 93 physx::PxBounds3 bounds(px3Cast<physx::PxVec3>(box.minExtents), 94 px3Cast<physx::PxVec3>(box.maxExtents)); 95 return bounds; 96} 97 98template<> 99inline Box3F px3Cast( const physx::PxBounds3 &bounds ) 100{ 101 return Box3F( bounds.minimum.x, 102 bounds.minimum.y, 103 bounds.minimum.z, 104 bounds.maximum.x, 105 bounds.maximum.y, 106 bounds.maximum.z ); 107} 108 109//------------------------------------------------------------------------- 110 111template<> 112inline physx::PxTransform px3Cast( const MatrixF &xfm ) 113{ 114 physx::PxTransform out; 115 QuatF q; 116 q.set(xfm); 117 out.q = px3Cast<physx::PxQuat>(q); 118 out.p = px3Cast<physx::PxVec3>(xfm.getPosition()); 119 return out; 120} 121 122template<> 123inline TransformF px3Cast(const physx::PxTransform &xfm) 124{ 125 TransformF out(px3Cast<Point3F>(xfm.p),AngAxisF(px3Cast<QuatF>(xfm.q))); 126 return out; 127} 128 129template<> 130inline MatrixF px3Cast( const physx::PxTransform &xfm ) 131{ 132 MatrixF out; 133 TransformF t = px3Cast<TransformF>(xfm); 134 out = t.getMatrix(); 135 return out; 136} 137 138#endif //_PX3CASTS_H_ 139