2017-08-01 12:30:58 +00:00
|
|
|
/*
|
|
|
|
Bullet Continuous Collision Detection and Physics Library, http://bulletphysics.org
|
|
|
|
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
|
|
|
|
|
|
|
|
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_GENERIC_6DOF_SPRING_CONSTRAINT_H
|
|
|
|
#define BT_GENERIC_6DOF_SPRING_CONSTRAINT_H
|
|
|
|
|
|
|
|
#include "LinearMath/btVector3.h"
|
|
|
|
#include "btTypedConstraint.h"
|
|
|
|
#include "btGeneric6DofConstraint.h"
|
|
|
|
|
|
|
|
#ifdef BT_USE_DOUBLE_PRECISION
|
2019-01-03 13:26:51 +00:00
|
|
|
#define btGeneric6DofSpringConstraintData2 btGeneric6DofSpringConstraintDoubleData2
|
|
|
|
#define btGeneric6DofSpringConstraintDataName "btGeneric6DofSpringConstraintDoubleData2"
|
2017-08-01 12:30:58 +00:00
|
|
|
#else
|
2019-01-03 13:26:51 +00:00
|
|
|
#define btGeneric6DofSpringConstraintData2 btGeneric6DofSpringConstraintData
|
|
|
|
#define btGeneric6DofSpringConstraintDataName "btGeneric6DofSpringConstraintData"
|
|
|
|
#endif //BT_USE_DOUBLE_PRECISION
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
/// Generic 6 DOF constraint that allows to set spring motors to any translational and rotational DOF
|
|
|
|
|
|
|
|
/// DOF index used in enableSpring() and setStiffness() means:
|
|
|
|
/// 0 : translation X
|
|
|
|
/// 1 : translation Y
|
|
|
|
/// 2 : translation Z
|
|
|
|
/// 3 : rotation X (3rd Euler rotational around new position of X axis, range [-PI+epsilon, PI-epsilon] )
|
|
|
|
/// 4 : rotation Y (2nd Euler rotational around new position of Y axis, range [-PI/2+epsilon, PI/2-epsilon] )
|
|
|
|
/// 5 : rotation Z (1st Euler rotational around Z axis, range [-PI+epsilon, PI-epsilon] )
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
ATTRIBUTE_ALIGNED16(class)
|
|
|
|
btGeneric6DofSpringConstraint : public btGeneric6DofConstraint
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
protected:
|
2019-01-03 13:26:51 +00:00
|
|
|
bool m_springEnabled[6];
|
|
|
|
btScalar m_equilibriumPoint[6];
|
|
|
|
btScalar m_springStiffness[6];
|
|
|
|
btScalar m_springDamping[6]; // between 0 and 1 (1 == no damping)
|
2017-08-01 12:30:58 +00:00
|
|
|
void init();
|
2019-01-03 13:26:51 +00:00
|
|
|
void internalUpdateSprings(btConstraintInfo2 * info);
|
|
|
|
|
|
|
|
public:
|
2017-08-01 12:30:58 +00:00
|
|
|
BT_DECLARE_ALIGNED_ALLOCATOR();
|
2019-01-03 13:26:51 +00:00
|
|
|
|
|
|
|
btGeneric6DofSpringConstraint(btRigidBody & rbA, btRigidBody & rbB, const btTransform& frameInA, const btTransform& frameInB, bool useLinearReferenceFrameA);
|
|
|
|
btGeneric6DofSpringConstraint(btRigidBody & rbB, const btTransform& frameInB, bool useLinearReferenceFrameB);
|
2017-08-01 12:30:58 +00:00
|
|
|
void enableSpring(int index, bool onOff);
|
|
|
|
void setStiffness(int index, btScalar stiffness);
|
|
|
|
void setDamping(int index, btScalar damping);
|
2019-01-03 13:26:51 +00:00
|
|
|
void setEquilibriumPoint(); // set the current constraint position/orientation as an equilibrium point for all DOF
|
2017-08-01 12:30:58 +00:00
|
|
|
void setEquilibriumPoint(int index); // set the current constraint position/orientation as an equilibrium point for given DOF
|
|
|
|
void setEquilibriumPoint(int index, btScalar val);
|
|
|
|
|
|
|
|
bool isSpringEnabled(int index) const
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
return m_springEnabled[index];
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
btScalar getStiffness(int index) const
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
return m_springStiffness[index];
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
btScalar getDamping(int index) const
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
return m_springDamping[index];
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
btScalar getEquilibriumPoint(int index) const
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
return m_equilibriumPoint[index];
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual void setAxis(const btVector3& axis1, const btVector3& axis2);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
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
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
struct btGeneric6DofSpringConstraintData
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
btGeneric6DofConstraintData m_6dofData;
|
|
|
|
|
|
|
|
int m_springEnabled[6];
|
|
|
|
float m_equilibriumPoint[6];
|
|
|
|
float m_springStiffness[6];
|
|
|
|
float m_springDamping[6];
|
2017-08-01 12:30:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct btGeneric6DofSpringConstraintDoubleData2
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
btGeneric6DofConstraintDoubleData2 m_6dofData;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
int m_springEnabled[6];
|
|
|
|
double m_equilibriumPoint[6];
|
|
|
|
double m_springStiffness[6];
|
|
|
|
double m_springDamping[6];
|
|
|
|
};
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
SIMD_FORCE_INLINE int btGeneric6DofSpringConstraint::calculateSerializeBufferSize() const
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
return sizeof(btGeneric6DofSpringConstraintData2);
|
|
|
|
}
|
|
|
|
|
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* btGeneric6DofSpringConstraint::serialize(void* dataBuffer, btSerializer* serializer) const
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
btGeneric6DofSpringConstraintData2* dof = (btGeneric6DofSpringConstraintData2*)dataBuffer;
|
2019-01-03 13:26:51 +00:00
|
|
|
btGeneric6DofConstraint::serialize(&dof->m_6dofData, serializer);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
int i;
|
2019-01-03 13:26:51 +00:00
|
|
|
for (i = 0; i < 6; i++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
dof->m_equilibriumPoint[i] = m_equilibriumPoint[i];
|
|
|
|
dof->m_springDamping[i] = m_springDamping[i];
|
2019-01-03 13:26:51 +00:00
|
|
|
dof->m_springEnabled[i] = m_springEnabled[i] ? 1 : 0;
|
2017-08-01 12:30:58 +00:00
|
|
|
dof->m_springStiffness[i] = m_springStiffness[i];
|
|
|
|
}
|
|
|
|
return btGeneric6DofSpringConstraintDataName;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
#endif // BT_GENERIC_6DOF_SPRING_CONSTRAINT_H
|