Bullet Collision Detection & Physics Library
btGeneric6DofSpringConstraint.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library, http://bulletphysics.org
3 Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
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 #ifndef BT_GENERIC_6DOF_SPRING_CONSTRAINT_H
17 #define BT_GENERIC_6DOF_SPRING_CONSTRAINT_H
18 
19 
20 #include "LinearMath/btVector3.h"
21 #include "btTypedConstraint.h"
23 
24 
26 
34 
36 {
37 protected:
38  bool m_springEnabled[6];
39  btScalar m_equilibriumPoint[6];
40  btScalar m_springStiffness[6];
41  btScalar m_springDamping[6]; // between 0 and 1 (1 == no damping)
42  void init();
43  void internalUpdateSprings(btConstraintInfo2* info);
44 public:
45 
47 
48  btGeneric6DofSpringConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA);
49  btGeneric6DofSpringConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameB);
50  void enableSpring(int index, bool onOff);
51  void setStiffness(int index, btScalar stiffness);
52  void setDamping(int index, btScalar damping);
53  void setEquilibriumPoint(); // set the current constraint position/orientation as an equilibrium point for all DOF
54  void setEquilibriumPoint(int index); // set the current constraint position/orientation as an equilibrium point for given DOF
55  void setEquilibriumPoint(int index, btScalar val);
56 
57  virtual void setAxis( const btVector3& axis1, const btVector3& axis2);
58 
59  virtual void getInfo2 (btConstraintInfo2* info);
60 
61  virtual int calculateSerializeBufferSize() const;
63  virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
64 
65 };
66 
67 
70 {
72 
76  float m_springDamping[6];
77 };
78 
80 {
81  return sizeof(btGeneric6DofSpringConstraintData);
82 }
83 
85 SIMD_FORCE_INLINE const char* btGeneric6DofSpringConstraint::serialize(void* dataBuffer, btSerializer* serializer) const
86 {
89 
90  int i;
91  for (i=0;i<6;i++)
92  {
93  dof->m_equilibriumPoint[i] = (float)m_equilibriumPoint[i];
94  dof->m_springDamping[i] = (float)m_springDamping[i];
95  dof->m_springEnabled[i] = m_springEnabled[i]? 1 : 0;
96  dof->m_springStiffness[i] = (float)m_springStiffness[i];
97  }
98  return "btGeneric6DofSpringConstraintData";
99 }
100 
101 #endif // BT_GENERIC_6DOF_SPRING_CONSTRAINT_H
102