2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2012 Advanced Micro Devices, Inc. http://bulletphysics.org
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:
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.
16 #ifndef BT_GEAR_CONSTRAINT_H
17 #define BT_GEAR_CONSTRAINT_H
19 #include "BulletDynamics/ConstraintSolver/btTypedConstraint.h"
21 #ifdef BT_USE_DOUBLE_PRECISION
22 #define btGearConstraintData btGearConstraintDoubleData
23 #define btGearConstraintDataName "btGearConstraintDoubleData"
25 #define btGearConstraintData btGearConstraintFloatData
26 #define btGearConstraintDataName "btGearConstraintFloatData"
27 #endif //BT_USE_DOUBLE_PRECISION
29 ///The btGeatConstraint will couple the angular velocity for two bodies around given local axis and ratio.
30 ///See Bullet/Demos/ConstraintDemo for an example use.
31 class btGearConstraint : public btTypedConstraint
40 btGearConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& axisInA, const btVector3& axisInB, btScalar ratio = 1.f);
41 virtual ~btGearConstraint();
43 ///internal method used by the constraint solver, don't use them directly
44 virtual void getInfo1(btConstraintInfo1* info);
46 ///internal method used by the constraint solver, don't use them directly
47 virtual void getInfo2(btConstraintInfo2* info);
49 void setAxisA(btVector3& axisA)
53 void setAxisB(btVector3& axisB)
57 void setRatio(btScalar ratio)
61 const btVector3& getAxisA() const
65 const btVector3& getAxisB() const
69 btScalar getRatio() const
74 virtual void setParam(int num, btScalar value, int axis = -1)
82 ///return the local value of parameter
83 virtual btScalar getParam(int num, int axis = -1) const
91 virtual int calculateSerializeBufferSize() const;
93 ///fills the dataBuffer and returns the struct name (and 0 on failure)
94 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
97 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
98 struct btGearConstraintFloatData
100 btTypedConstraintFloatData m_typeConstraintData;
102 btVector3FloatData m_axisInA;
103 btVector3FloatData m_axisInB;
109 struct btGearConstraintDoubleData
111 btTypedConstraintDoubleData m_typeConstraintData;
113 btVector3DoubleData m_axisInA;
114 btVector3DoubleData m_axisInB;
119 SIMD_FORCE_INLINE int btGearConstraint::calculateSerializeBufferSize() const
121 return sizeof(btGearConstraintData);
124 ///fills the dataBuffer and returns the struct name (and 0 on failure)
125 SIMD_FORCE_INLINE const char* btGearConstraint::serialize(void* dataBuffer, btSerializer* serializer) const
127 btGearConstraintData* gear = (btGearConstraintData*)dataBuffer;
128 btTypedConstraint::serialize(&gear->m_typeConstraintData, serializer);
130 m_axisInA.serialize(gear->m_axisInA);
131 m_axisInB.serialize(gear->m_axisInB);
133 gear->m_ratio = m_ratio;
135 // Fill padding with zeros to appease msan.
136 #ifndef BT_USE_DOUBLE_PRECISION
137 gear->m_padding[0] = 0;
138 gear->m_padding[1] = 0;
139 gear->m_padding[2] = 0;
140 gear->m_padding[3] = 0;
143 return btGearConstraintDataName;
146 #endif //BT_GEAR_CONSTRAINT_H