2017-08-01 14:30:58 +02:00
/*
Bullet Continuous Collision Detection and Physics Library
Copyright ( c ) 2003 - 2009 Erwin Coumans http : //bulletphysics.org
This software is provided ' as - is ' , without any express or implied warranty .
In no event will the authors be held liable for any damages arising from the use of this software .
Permission is granted to anyone to use this software for any purpose ,
including commercial applications , and to alter it and redistribute it freely ,
subject to the following restrictions :
1. The origin of this software must not be misrepresented ; you must not claim that you wrote the original software . If you use this software in a product , an acknowledgment in the product documentation would be appreciated but is not required .
2. Altered source versions must be plainly marked as such , and must not be misrepresented as being the original software .
3. This notice may not be removed or altered from any source distribution .
*/
# ifndef BT_CYLINDER_MINKOWSKI_H
# define BT_CYLINDER_MINKOWSKI_H
# include "btBoxShape.h"
2019-01-03 14:26:51 +01:00
# include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
2017-08-01 14:30:58 +02:00
# include "LinearMath/btVector3.h"
/// The btCylinderShape class implements a cylinder shape primitive, centered around the origin. Its central axis aligned with the Y axis. btCylinderShapeX is aligned with the X axis and btCylinderShapeZ around the Z axis.
2019-01-03 14:26:51 +01:00
ATTRIBUTE_ALIGNED16 ( class )
btCylinderShape : public btConvexInternalShape
2017-08-01 14:30:58 +02:00
{
protected :
2019-01-03 14:26:51 +01:00
int m_upAxis ;
2017-08-01 14:30:58 +02:00
public :
2019-01-03 14:26:51 +01:00
BT_DECLARE_ALIGNED_ALLOCATOR ( ) ;
2017-08-01 14:30:58 +02:00
btVector3 getHalfExtentsWithMargin ( ) const
{
btVector3 halfExtents = getHalfExtentsWithoutMargin ( ) ;
2019-01-03 14:26:51 +01:00
btVector3 margin ( getMargin ( ) , getMargin ( ) , getMargin ( ) ) ;
2017-08-01 14:30:58 +02:00
halfExtents + = margin ;
return halfExtents ;
}
2019-01-03 14:26:51 +01:00
2017-08-01 14:30:58 +02:00
const btVector3 & getHalfExtentsWithoutMargin ( ) const
{
2019-01-03 14:26:51 +01:00
return m_implicitShapeDimensions ; //changed in Bullet 2.63: assume the scaling and margin are included
2017-08-01 14:30:58 +02:00
}
2019-01-03 14:26:51 +01:00
btCylinderShape ( const btVector3 & halfExtents ) ;
void getAabb ( const btTransform & t , btVector3 & aabbMin , btVector3 & aabbMax ) const ;
2017-08-01 14:30:58 +02:00
2019-01-03 14:26:51 +01:00
virtual void calculateLocalInertia ( btScalar mass , btVector3 & inertia ) const ;
2017-08-01 14:30:58 +02:00
2019-01-03 14:26:51 +01:00
virtual btVector3 localGetSupportingVertexWithoutMargin ( const btVector3 & vec ) const ;
2017-08-01 14:30:58 +02:00
2019-01-03 14:26:51 +01:00
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin ( const btVector3 * vectors , btVector3 * supportVerticesOut , int numVectors ) const ;
2017-08-01 14:30:58 +02:00
virtual void setMargin ( btScalar collisionMargin )
{
//correct the m_implicitShapeDimensions for the margin
2019-01-03 14:26:51 +01:00
btVector3 oldMargin ( getMargin ( ) , getMargin ( ) , getMargin ( ) ) ;
btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions + oldMargin ;
2017-08-01 14:30:58 +02:00
btConvexInternalShape : : setMargin ( collisionMargin ) ;
2019-01-03 14:26:51 +01:00
btVector3 newMargin ( getMargin ( ) , getMargin ( ) , getMargin ( ) ) ;
2017-08-01 14:30:58 +02:00
m_implicitShapeDimensions = implicitShapeDimensionsWithMargin - newMargin ;
}
2019-01-03 14:26:51 +01:00
virtual btVector3 localGetSupportingVertex ( const btVector3 & vec ) const
2017-08-01 14:30:58 +02:00
{
btVector3 supVertex ;
supVertex = localGetSupportingVertexWithoutMargin ( vec ) ;
2019-01-03 14:26:51 +01:00
if ( getMargin ( ) ! = btScalar ( 0. ) )
2017-08-01 14:30:58 +02:00
{
btVector3 vecnorm = vec ;
2019-01-03 14:26:51 +01:00
if ( vecnorm . length2 ( ) < ( SIMD_EPSILON * SIMD_EPSILON ) )
2017-08-01 14:30:58 +02:00
{
2019-01-03 14:26:51 +01:00
vecnorm . setValue ( btScalar ( - 1. ) , btScalar ( - 1. ) , btScalar ( - 1. ) ) ;
}
2017-08-01 14:30:58 +02:00
vecnorm . normalize ( ) ;
2019-01-03 14:26:51 +01:00
supVertex + = getMargin ( ) * vecnorm ;
2017-08-01 14:30:58 +02:00
}
return supVertex ;
}
//use box inertia
// virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
2019-01-03 14:26:51 +01:00
int getUpAxis ( ) const
2017-08-01 14:30:58 +02:00
{
return m_upAxis ;
}
2019-01-03 14:26:51 +01:00
virtual btVector3 getAnisotropicRollingFrictionDirection ( ) const
2017-08-01 14:30:58 +02:00
{
2019-01-03 14:26:51 +01:00
btVector3 aniDir ( 0 , 0 , 0 ) ;
aniDir [ getUpAxis ( ) ] = 1 ;
2017-08-01 14:30:58 +02:00
return aniDir ;
}
virtual btScalar getRadius ( ) const
{
return getHalfExtentsWithMargin ( ) . getX ( ) ;
}
2019-01-03 14:26:51 +01:00
virtual void setLocalScaling ( const btVector3 & scaling )
2017-08-01 14:30:58 +02:00
{
2019-01-03 14:26:51 +01:00
btVector3 oldMargin ( getMargin ( ) , getMargin ( ) , getMargin ( ) ) ;
btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions + oldMargin ;
2017-08-01 14:30:58 +02:00
btVector3 unScaledImplicitShapeDimensionsWithMargin = implicitShapeDimensionsWithMargin / m_localScaling ;
btConvexInternalShape : : setLocalScaling ( scaling ) ;
m_implicitShapeDimensions = ( unScaledImplicitShapeDimensionsWithMargin * m_localScaling ) - oldMargin ;
}
//debugging
2019-01-03 14:26:51 +01:00
virtual const char * getName ( ) const
2017-08-01 14:30:58 +02:00
{
return " CylinderY " ;
}
2019-01-03 14:26:51 +01:00
virtual int calculateSerializeBufferSize ( ) const ;
2017-08-01 14:30:58 +02:00
///fills the dataBuffer and returns the struct name (and 0 on failure)
2019-01-03 14:26:51 +01:00
virtual const char * serialize ( void * dataBuffer , btSerializer * serializer ) const ;
2017-08-01 14:30:58 +02:00
} ;
class btCylinderShapeX : public btCylinderShape
{
public :
BT_DECLARE_ALIGNED_ALLOCATOR ( ) ;
2019-01-03 14:26:51 +01:00
btCylinderShapeX ( const btVector3 & halfExtents ) ;
virtual btVector3 localGetSupportingVertexWithoutMargin ( const btVector3 & vec ) const ;
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin ( const btVector3 * vectors , btVector3 * supportVerticesOut , int numVectors ) const ;
//debugging
virtual const char * getName ( ) const
2017-08-01 14:30:58 +02:00
{
return " CylinderX " ;
}
virtual btScalar getRadius ( ) const
{
return getHalfExtentsWithMargin ( ) . getY ( ) ;
}
} ;
class btCylinderShapeZ : public btCylinderShape
{
public :
BT_DECLARE_ALIGNED_ALLOCATOR ( ) ;
2019-01-03 14:26:51 +01:00
btCylinderShapeZ ( const btVector3 & halfExtents ) ;
virtual btVector3 localGetSupportingVertexWithoutMargin ( const btVector3 & vec ) const ;
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin ( const btVector3 * vectors , btVector3 * supportVerticesOut , int numVectors ) const ;
2017-08-01 14:30:58 +02:00
2019-01-03 14:26:51 +01:00
//debugging
virtual const char * getName ( ) const
2017-08-01 14:30:58 +02:00
{
return " CylinderZ " ;
}
virtual btScalar getRadius ( ) const
{
return getHalfExtentsWithMargin ( ) . getX ( ) ;
}
} ;
///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
2019-01-03 14:26:51 +01:00
struct btCylinderShapeData
2017-08-01 14:30:58 +02:00
{
2019-01-03 14:26:51 +01:00
btConvexInternalShapeData m_convexInternalShapeData ;
2017-08-01 14:30:58 +02:00
2019-01-03 14:26:51 +01:00
int m_upAxis ;
2017-08-01 14:30:58 +02:00
2019-01-03 14:26:51 +01:00
char m_padding [ 4 ] ;
2017-08-01 14:30:58 +02:00
} ;
2019-01-03 14:26:51 +01:00
SIMD_FORCE_INLINE int btCylinderShape : : calculateSerializeBufferSize ( ) const
2017-08-01 14:30:58 +02:00
{
return sizeof ( btCylinderShapeData ) ;
}
2019-01-03 14:26:51 +01:00
///fills the dataBuffer and returns the struct name (and 0 on failure)
SIMD_FORCE_INLINE const char * btCylinderShape : : serialize ( void * dataBuffer , btSerializer * serializer ) const
2017-08-01 14:30:58 +02:00
{
2019-01-03 14:26:51 +01:00
btCylinderShapeData * shapeData = ( btCylinderShapeData * ) dataBuffer ;
2017-08-01 14:30:58 +02:00
2019-01-03 14:26:51 +01:00
btConvexInternalShape : : serialize ( & shapeData - > m_convexInternalShapeData , serializer ) ;
2017-08-01 14:30:58 +02:00
shapeData - > m_upAxis = m_upAxis ;
// Fill padding with zeros to appease msan.
shapeData - > m_padding [ 0 ] = 0 ;
shapeData - > m_padding [ 1 ] = 0 ;
shapeData - > m_padding [ 2 ] = 0 ;
shapeData - > m_padding [ 3 ] = 0 ;
return " btCylinderShapeData " ;
}
2019-01-03 14:26:51 +01:00
# endif //BT_CYLINDER_MINKOWSKI_H