Bullet Collision Detection & Physics Library: btGeneric6DofSpringConstraint.h Source File

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 #include "LinearMath/btVector3.h"
20 #include "btTypedConstraint.h"
21 #include "btGeneric6DofConstraint.h"
22
23 #ifdef BT_USE_DOUBLE_PRECISION
24 #define btGeneric6DofSpringConstraintData2 btGeneric6DofSpringConstraintDoubleData2
25 #define btGeneric6DofSpringConstraintDataName "btGeneric6DofSpringConstraintDoubleData2"
26 #else
27 #define btGeneric6DofSpringConstraintData2 btGeneric6DofSpringConstraintData
28 #define btGeneric6DofSpringConstraintDataName "btGeneric6DofSpringConstraintData"
29 #endif //BT_USE_DOUBLE_PRECISION
30
32
40
41 ATTRIBUTE_ALIGNED16(class)
42 btGeneric6DofSpringConstraint : public btGeneric6DofConstraint
43 {
44 protected:
45 bool m_springEnabled[6];
46 btScalar m_equilibriumPoint[6];
47 btScalar m_springStiffness[6];
48 btScalar m_springDamping[6]; // between 0 and 1 (1 == no damping)
49 void init();
50 void internalUpdateSprings(btConstraintInfo2 * info);
51
52 public:
53 BT_DECLARE_ALIGNED_ALLOCATOR();
54
55 btGeneric6DofSpringConstraint(btRigidBody & rbA, btRigidBody & rbB, const btTransform& frameInA, const btTransform& frameInB, bool useLinearReferenceFrameA);
56 btGeneric6DofSpringConstraint(btRigidBody & rbB, const btTransform& frameInB, bool useLinearReferenceFrameB);
57 void enableSpring(int index, bool onOff);
58 void setStiffness(int index, btScalar stiffness);
59 void setDamping(int index, btScalar damping);
60 void setEquilibriumPoint(); // set the current constraint position/orientation as an equilibrium point for all DOF
61 void setEquilibriumPoint(int index); // set the current constraint position/orientation as an equilibrium point for given DOF
62 void setEquilibriumPoint(int index, btScalar val);
63
64 bool isSpringEnabled(int index) const
65 {
66 return m_springEnabled[index];
67 }
68
69 btScalar getStiffness(int index) const
70 {
71 return m_springStiffness[index];
72 }
73
74 btScalar getDamping(int index) const
75 {
76 return m_springDamping[index];
77 }
78
79 btScalar getEquilibriumPoint(int index) const
80 {
81 return m_equilibriumPoint[index];
82 }
83
84 virtual void setAxis(const btVector3& axis1, const btVector3& axis2);
85
86 virtual void getInfo2(btConstraintInfo2 * info);
87
88 virtual int calculateSerializeBufferSize() const;
90 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
91 };
92
93 struct btGeneric6DofSpringConstraintData
94 {
95 btGeneric6DofConstraintData m_6dofData;
96
97 int m_springEnabled[6];
98 float m_equilibriumPoint[6];
99 float m_springStiffness[6];
100 float m_springDamping[6];
101 };
102
103 struct btGeneric6DofSpringConstraintDoubleData2
104 {
105 btGeneric6DofConstraintDoubleData2 m_6dofData;
106
107 int m_springEnabled[6];
108 double m_equilibriumPoint[6];
109 double m_springStiffness[6];
110 double m_springDamping[6];
111 };
112
113 SIMD_FORCE_INLINE int btGeneric6DofSpringConstraint::calculateSerializeBufferSize() const
114 {
115 return sizeof(btGeneric6DofSpringConstraintData2);
116 }
117
119 SIMD_FORCE_INLINE const char* btGeneric6DofSpringConstraint::serialize(void* dataBuffer, btSerializer* serializer) const
120 {
121 btGeneric6DofSpringConstraintData2* dof = (btGeneric6DofSpringConstraintData2*)dataBuffer;
122 btGeneric6DofConstraint::serialize(&dof->m_6dofData, serializer);
123
124 int i;
125 for (i = 0; i < 6; i++)
126 {
127 dof->m_equilibriumPoint[i] = m_equilibriumPoint[i];
128 dof->m_springDamping[i] = m_springDamping[i];
129 dof->m_springEnabled[i] = m_springEnabled[i] ? 1 : 0;
130 dof->m_springStiffness[i] = m_springStiffness[i];
131 }
132 return btGeneric6DofSpringConstraintDataName;
133 }
134
135 #endif // BT_GENERIC_6DOF_SPRING_CONSTRAINT_H
btGeneric6DofSpringConstraintData::m_springStiffness
float m_springStiffness[6]
Definition: btGeneric6DofSpringConstraint.h:99
btRigidBody
The btRigidBody is the main class for rigid body objects.
Definition: btRigidBody.h:60
btGeneric6DofSpringConstraint::BT_DECLARE_ALIGNED_ALLOCATOR
BT_DECLARE_ALIGNED_ALLOCATOR()
btGeneric6DofSpringConstraint::getEquilibriumPoint
btScalar getEquilibriumPoint(int index) const
Definition: btGeneric6DofSpringConstraint.h:79
btGeneric6DofSpringConstraintData::m_6dofData
btGeneric6DofConstraintData m_6dofData
Definition: btGeneric6DofSpringConstraint.h:95
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
btGeneric6DofSpringConstraintDoubleData2::m_springStiffness
double m_springStiffness[6]
Definition: btGeneric6DofSpringConstraint.h:109
btGeneric6DofSpringConstraintDataName
#define btGeneric6DofSpringConstraintDataName
Definition: btGeneric6DofSpringConstraint.h:28
btGeneric6DofSpringConstraint::m_equilibriumPoint
btScalar m_equilibriumPoint[6]
Definition: btGeneric6DofSpringConstraint.h:46
btGeneric6DofSpringConstraint::getDamping
btScalar getDamping(int index) const
Definition: btGeneric6DofSpringConstraint.h:74
btGeneric6DofConstraintData
Definition: btGeneric6DofConstraint.h:555
btGeneric6DofSpringConstraint::m_springDamping
btScalar m_springDamping[6]
Definition: btGeneric6DofSpringConstraint.h:48
btGeneric6DofSpringConstraintDoubleData2::m_springEnabled
int m_springEnabled[6]
Definition: btGeneric6DofSpringConstraint.h:107
btGeneric6DofConstraint
btGeneric6DofConstraint between two rigidbodies each with a pivotpoint that descibes the axis locatio...
Definition: btGeneric6DofConstraint.h:268
btGeneric6DofSpringConstraint::getStiffness
btScalar getStiffness(int index) const
Definition: btGeneric6DofSpringConstraint.h:69
btVector3.h
btGeneric6DofSpringConstraint::serialize
virtual const char * serialize(void *dataBuffer, btSerializer *serializer) const
fills the dataBuffer and returns the struct name (and 0 on failure)
Definition: btGeneric6DofSpringConstraint.h:119
btGeneric6DofSpringConstraintData
Definition: btGeneric6DofSpringConstraint.h:94
btGeneric6DofSpringConstraintData::m_springEnabled
int m_springEnabled[6]
Definition: btGeneric6DofSpringConstraint.h:97
btTypedConstraint.h
btGeneric6DofSpringConstraint
Generic 6 DOF constraint that allows to set spring motors to any translational and rotational DOF.
Definition: btGeneric6DofSpringConstraint.h:43
btGeneric6DofSpringConstraint::m_springStiffness
btScalar m_springStiffness[6]
Definition: btGeneric6DofSpringConstraint.h:47
btGeneric6DofSpringConstraintData2
#define btGeneric6DofSpringConstraintData2
Definition: btGeneric6DofSpringConstraint.h:27
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:30
btGeneric6DofSpringConstraintData::m_equilibriumPoint
float m_equilibriumPoint[6]
Definition: btGeneric6DofSpringConstraint.h:98
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
btGeneric6DofSpringConstraint::isSpringEnabled
bool isSpringEnabled(int index) const
Definition: btGeneric6DofSpringConstraint.h:64
ATTRIBUTE_ALIGNED16
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:99
btGeneric6DofSpringConstraint::calculateSerializeBufferSize
virtual int calculateSerializeBufferSize() const
Definition: btGeneric6DofSpringConstraint.h:113
SIMD_FORCE_INLINE
#define SIMD_FORCE_INLINE
Definition: btScalar.h:98
btSerializer
Definition: btSerializer.h:66
btGeneric6DofConstraintDoubleData2
Definition: btGeneric6DofConstraint.h:571
btGeneric6DofConstraint.h
btTypedConstraint::btConstraintInfo2
Definition: btTypedConstraint.h:121
btGeneric6DofSpringConstraintDoubleData2::m_equilibriumPoint
double m_equilibriumPoint[6]
Definition: btGeneric6DofSpringConstraint.h:108
btGeneric6DofSpringConstraintData::m_springDamping
float m_springDamping[6]
Definition: btGeneric6DofSpringConstraint.h:100
btGeneric6DofSpringConstraintDoubleData2
Definition: btGeneric6DofSpringConstraint.h:104
btGeneric6DofSpringConstraint::m_springEnabled
bool m_springEnabled[6]
Definition: btGeneric6DofSpringConstraint.h:45
btGeneric6DofSpringConstraintDoubleData2::m_6dofData
btGeneric6DofConstraintDoubleData2 m_6dofData
Definition: btGeneric6DofSpringConstraint.h:105
btGeneric6DofConstraint::serialize
virtual const char * serialize(void *dataBuffer, btSerializer *serializer) const
fills the dataBuffer and returns the struct name (and 0 on failure)
Definition: btGeneric6DofConstraint.h:592
btGeneric6DofSpringConstraintDoubleData2::m_springDamping
double m_springDamping[6]
Definition: btGeneric6DofSpringConstraint.h:110