btCasts.h

Engine/source/T3D/physics/bullet/btCasts.h

More...

Public Functions

btCast(const btQuaternion & quat)
btCast(const btTransform & xfm)
btCast(const btVector3 & vec)
T
btCast(const F & from)
btTransform
btVector3
btCast(const Point3F & point)
btQuaternion
btCast(const QuatF & quat)

Detailed Description

Public Functions

btCast(const btQuaternion & quat)

btCast(const btTransform & xfm)

btCast(const btVector3 & vec)

btCast(const F & from)

btCast(const MatrixF & xfm)

btCast(const Point3F & point)

btCast(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 _BULLET_CASTS_H_
 25#define _BULLET_CASTS_H_
 26
 27#ifndef _BULLET_H_
 28#include "T3D/physics/bullet/bt.h"
 29#endif
 30#ifndef _MMATRIX_H_
 31#include "math/mMatrix.h"
 32#endif
 33#ifndef _MPOINT3_H_
 34#include "math/mPoint3.h"
 35#endif
 36#ifndef _MQUAT_H_
 37#include "math/mQuat.h"
 38#endif
 39
 40template <class T, class F> inline T btCast( const F &from );
 41
 42//-------------------------------------------------------------------------
 43
 44template<>
 45inline Point3F btCast( const btVector3 &vec )
 46{
 47   return Point3F( vec.x(), vec.y(), vec.z() );
 48}
 49
 50template<>
 51inline btVector3 btCast( const Point3F &point )
 52{
 53   return btVector3( point.x, point.y, point.z );
 54}
 55
 56template<>
 57inline QuatF btCast( const btQuaternion &quat )
 58{
 59   /// The Torque quat has the opposite winding order.
 60   return QuatF( -quat.x(), -quat.y(), -quat.z(), quat.w() );
 61}
 62
 63template<>
 64inline btQuaternion btCast( const QuatF &quat )
 65{
 66   /// The Torque quat has the opposite winding order.
 67   return btQuaternion( -quat.x, -quat.y, -quat.z, quat.w );
 68}
 69
 70template<>
 71inline btTransform btCast( const MatrixF &xfm )
 72{
 73   btTransform out;
 74   out.getBasis().setValue(   xfm[0], xfm[1], xfm[2],
 75                              xfm[4], xfm[5], xfm[6],
 76                              xfm[8], xfm[9], xfm[10] );
 77   out.getOrigin().setValue(  xfm[3], xfm[7], xfm[11] );
 78   return out;
 79}
 80
 81template<>
 82inline MatrixF btCast( const btTransform &xfm )
 83{
 84   MatrixF out;
 85
 86   // Set the rotation.
 87   out.setRow( 0, btCast<Point3F>( xfm.getBasis()[0] ) );
 88   out.setRow( 1, btCast<Point3F>( xfm.getBasis()[1] ) );
 89   out.setRow( 2, btCast<Point3F>( xfm.getBasis()[2] ) );
 90   
 91   // The position.
 92   out[3] = xfm.getOrigin().x();
 93   out[7] = xfm.getOrigin().y();
 94   out[11] = xfm.getOrigin().z();
 95
 96   // Clear out the rest.
 97   out[12] = out[13] = out[14] = 0.0f;
 98   out[15] = 1.0f;
 99
100   return out;
101}
102
103#endif // _BULLET_CASTS_H_
104