Home | History | Annotate | Download | only in ConstraintSolver
      1 /*
      2 Bullet Continuous Collision Detection and Physics Library
      3 Copyright (c) 2012 Advanced Micro Devices, Inc.  http://bulletphysics.org
      4 
      5 This software is provided 'as-is', without any express or implied warranty.
      6 In no event will the authors be held liable for any damages arising from the use of this software.
      7 Permission is granted to anyone to use this software for any purpose,
      8 including commercial applications, and to alter it and redistribute it freely,
      9 subject to the following restrictions:
     10 
     11 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.
     12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
     13 3. This notice may not be removed or altered from any source distribution.
     14 */
     15 
     16 
     17 
     18 #ifndef BT_GEAR_CONSTRAINT_H
     19 #define BT_GEAR_CONSTRAINT_H
     20 
     21 #include "BulletDynamics/ConstraintSolver/btTypedConstraint.h"
     22 
     23 
     24 #ifdef BT_USE_DOUBLE_PRECISION
     25 #define btGearConstraintData	btGearConstraintDoubleData
     26 #define btGearConstraintDataName	"btGearConstraintDoubleData"
     27 #else
     28 #define btGearConstraintData	btGearConstraintFloatData
     29 #define btGearConstraintDataName	"btGearConstraintFloatData"
     30 #endif //BT_USE_DOUBLE_PRECISION
     31 
     32 
     33 
     34 ///The btGeatConstraint will couple the angular velocity for two bodies around given local axis and ratio.
     35 ///See Bullet/Demos/ConstraintDemo for an example use.
     36 class btGearConstraint : public btTypedConstraint
     37 {
     38 protected:
     39 	btVector3	m_axisInA;
     40 	btVector3	m_axisInB;
     41 	bool		m_useFrameA;
     42 	btScalar	m_ratio;
     43 
     44 public:
     45 	btGearConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& axisInA,const btVector3& axisInB, btScalar ratio=1.f);
     46 	virtual ~btGearConstraint ();
     47 
     48 	///internal method used by the constraint solver, don't use them directly
     49 	virtual void getInfo1 (btConstraintInfo1* info);
     50 
     51 	///internal method used by the constraint solver, don't use them directly
     52 	virtual void getInfo2 (btConstraintInfo2* info);
     53 
     54 	void setAxisA(btVector3& axisA)
     55 	{
     56 		m_axisInA = axisA;
     57 	}
     58 	void setAxisB(btVector3& axisB)
     59 	{
     60 		m_axisInB = axisB;
     61 	}
     62 	void setRatio(btScalar ratio)
     63 	{
     64 		m_ratio = ratio;
     65 	}
     66 	const btVector3& getAxisA() const
     67 	{
     68 		return m_axisInA;
     69 	}
     70 	const btVector3& getAxisB() const
     71 	{
     72 		return m_axisInB;
     73 	}
     74 	btScalar getRatio() const
     75 	{
     76 		return m_ratio;
     77 	}
     78 
     79 
     80 	virtual	void	setParam(int num, btScalar value, int axis = -1)
     81 	{
     82 		(void) num;
     83 		(void) value;
     84 		(void) axis;
     85 		btAssert(0);
     86 	}
     87 
     88 	///return the local value of parameter
     89 	virtual	btScalar getParam(int num, int axis = -1) const
     90 	{
     91 		(void) num;
     92 		(void) axis;
     93 		btAssert(0);
     94 		return 0.f;
     95 	}
     96 
     97 	virtual	int	calculateSerializeBufferSize() const;
     98 
     99 	///fills the dataBuffer and returns the struct name (and 0 on failure)
    100 	virtual	const char*	serialize(void* dataBuffer, btSerializer* serializer) const;
    101 };
    102 
    103 
    104 
    105 
    106 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
    107 struct btGearConstraintFloatData
    108 {
    109 	btTypedConstraintFloatData	m_typeConstraintData;
    110 
    111 	btVector3FloatData			m_axisInA;
    112 	btVector3FloatData			m_axisInB;
    113 
    114 	float							m_ratio;
    115 	char							m_padding[4];
    116 };
    117 
    118 struct btGearConstraintDoubleData
    119 {
    120 	btTypedConstraintDoubleData	m_typeConstraintData;
    121 
    122 	btVector3DoubleData			m_axisInA;
    123 	btVector3DoubleData			m_axisInB;
    124 
    125 	double						m_ratio;
    126 };
    127 
    128 SIMD_FORCE_INLINE	int	btGearConstraint::calculateSerializeBufferSize() const
    129 {
    130 	return sizeof(btGearConstraintData);
    131 }
    132 
    133 	///fills the dataBuffer and returns the struct name (and 0 on failure)
    134 SIMD_FORCE_INLINE	const char*	btGearConstraint::serialize(void* dataBuffer, btSerializer* serializer) const
    135 {
    136 	btGearConstraintData* gear = (btGearConstraintData*)dataBuffer;
    137 	btTypedConstraint::serialize(&gear->m_typeConstraintData,serializer);
    138 
    139 	m_axisInA.serialize( gear->m_axisInA );
    140 	m_axisInB.serialize( gear->m_axisInB );
    141 
    142 	gear->m_ratio = m_ratio;
    143 
    144 	return btGearConstraintDataName;
    145 }
    146 
    147 
    148 
    149 
    150 
    151 
    152 #endif //BT_GEAR_CONSTRAINT_H
    153