2017-08-01 12:30:58 +00:00
|
|
|
/*
|
|
|
|
Bullet Continuous Collision Detection and Physics Library
|
|
|
|
Copyright (c) 2012 Advanced Micro Devices, Inc. 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_GEAR_CONSTRAINT_H
|
|
|
|
#define BT_GEAR_CONSTRAINT_H
|
|
|
|
|
|
|
|
#include "BulletDynamics/ConstraintSolver/btTypedConstraint.h"
|
|
|
|
|
|
|
|
#ifdef BT_USE_DOUBLE_PRECISION
|
2019-01-03 13:26:51 +00:00
|
|
|
#define btGearConstraintData btGearConstraintDoubleData
|
|
|
|
#define btGearConstraintDataName "btGearConstraintDoubleData"
|
2017-08-01 12:30:58 +00:00
|
|
|
#else
|
2019-01-03 13:26:51 +00:00
|
|
|
#define btGearConstraintData btGearConstraintFloatData
|
|
|
|
#define btGearConstraintDataName "btGearConstraintFloatData"
|
|
|
|
#endif //BT_USE_DOUBLE_PRECISION
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
///The btGeatConstraint will couple the angular velocity for two bodies around given local axis and ratio.
|
|
|
|
///See Bullet/Demos/ConstraintDemo for an example use.
|
|
|
|
class btGearConstraint : public btTypedConstraint
|
|
|
|
{
|
|
|
|
protected:
|
2019-01-03 13:26:51 +00:00
|
|
|
btVector3 m_axisInA;
|
|
|
|
btVector3 m_axisInB;
|
|
|
|
bool m_useFrameA;
|
|
|
|
btScalar m_ratio;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
public:
|
2019-01-03 13:26:51 +00:00
|
|
|
btGearConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& axisInA, const btVector3& axisInB, btScalar ratio = 1.f);
|
|
|
|
virtual ~btGearConstraint();
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
///internal method used by the constraint solver, don't use them directly
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual void getInfo1(btConstraintInfo1* info);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
///internal method used by the constraint solver, don't use them directly
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual void getInfo2(btConstraintInfo2* info);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void setAxisA(btVector3& axisA)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
m_axisInA = axisA;
|
|
|
|
}
|
|
|
|
void setAxisB(btVector3& axisB)
|
|
|
|
{
|
|
|
|
m_axisInB = axisB;
|
|
|
|
}
|
|
|
|
void setRatio(btScalar ratio)
|
|
|
|
{
|
|
|
|
m_ratio = ratio;
|
|
|
|
}
|
|
|
|
const btVector3& getAxisA() const
|
|
|
|
{
|
|
|
|
return m_axisInA;
|
|
|
|
}
|
|
|
|
const btVector3& getAxisB() const
|
|
|
|
{
|
|
|
|
return m_axisInB;
|
|
|
|
}
|
|
|
|
btScalar getRatio() const
|
|
|
|
{
|
|
|
|
return m_ratio;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual void setParam(int num, btScalar value, int axis = -1)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
(void)num;
|
|
|
|
(void)value;
|
|
|
|
(void)axis;
|
2017-08-01 12:30:58 +00:00
|
|
|
btAssert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
///return the local value of parameter
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual btScalar getParam(int num, int axis = -1) const
|
|
|
|
{
|
|
|
|
(void)num;
|
|
|
|
(void)axis;
|
2017-08-01 12:30:58 +00:00
|
|
|
btAssert(0);
|
|
|
|
return 0.f;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual int calculateSerializeBufferSize() const;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
///fills the dataBuffer and returns the struct name (and 0 on failure)
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
|
2017-08-01 12:30:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
|
|
|
|
struct btGearConstraintFloatData
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
btTypedConstraintFloatData m_typeConstraintData;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
btVector3FloatData m_axisInA;
|
|
|
|
btVector3FloatData m_axisInB;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
float m_ratio;
|
|
|
|
char m_padding[4];
|
2017-08-01 12:30:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct btGearConstraintDoubleData
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
btTypedConstraintDoubleData m_typeConstraintData;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
btVector3DoubleData m_axisInA;
|
|
|
|
btVector3DoubleData m_axisInB;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
double m_ratio;
|
2017-08-01 12:30:58 +00:00
|
|
|
};
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
SIMD_FORCE_INLINE int btGearConstraint::calculateSerializeBufferSize() const
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
return sizeof(btGearConstraintData);
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
///fills the dataBuffer and returns the struct name (and 0 on failure)
|
|
|
|
SIMD_FORCE_INLINE const char* btGearConstraint::serialize(void* dataBuffer, btSerializer* serializer) const
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
btGearConstraintData* gear = (btGearConstraintData*)dataBuffer;
|
2019-01-03 13:26:51 +00:00
|
|
|
btTypedConstraint::serialize(&gear->m_typeConstraintData, serializer);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
m_axisInA.serialize(gear->m_axisInA);
|
|
|
|
m_axisInB.serialize(gear->m_axisInB);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
gear->m_ratio = m_ratio;
|
|
|
|
|
|
|
|
// Fill padding with zeros to appease msan.
|
|
|
|
#ifndef BT_USE_DOUBLE_PRECISION
|
|
|
|
gear->m_padding[0] = 0;
|
|
|
|
gear->m_padding[1] = 0;
|
|
|
|
gear->m_padding[2] = 0;
|
|
|
|
gear->m_padding[3] = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return btGearConstraintDataName;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
#endif //BT_GEAR_CONSTRAINT_H
|