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

Bullet Collision Detection & Physics Library

btGearConstraint.h
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2012 Advanced Micro Devices, Inc. http://bulletphysics.org
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16#ifndef BT_GEAR_CONSTRAINT_H
17#define BT_GEAR_CONSTRAINT_H
18
19#include "BulletDynamics/ConstraintSolver/btTypedConstraint.h"
20
21#ifdef BT_USE_DOUBLE_PRECISION
22#define btGearConstraintData btGearConstraintDoubleData
23#define btGearConstraintDataName "btGearConstraintDoubleData"
24#else
25#define btGearConstraintData btGearConstraintFloatData
26#define btGearConstraintDataName "btGearConstraintFloatData"
27#endif //BT_USE_DOUBLE_PRECISION
28
31 class btGearConstraint : public btTypedConstraint
32{
33protected:
34 btVector3 m_axisInA;
35 btVector3 m_axisInB;
36 bool m_useFrameA;
37 btScalar m_ratio;
38
39public:
40 btGearConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& axisInA, const btVector3& axisInB, btScalar ratio = 1.f);
41 virtual ~btGearConstraint();
42
44 virtual void getInfo1(btConstraintInfo1* info);
45
47 virtual void getInfo2(btConstraintInfo2* info);
48
49 void setAxisA(btVector3& axisA)
50 {
51 m_axisInA = axisA;
52 }
53 void setAxisB(btVector3& axisB)
54 {
55 m_axisInB = axisB;
56 }
57 void setRatio(btScalar ratio)
58 {
59 m_ratio = ratio;
60 }
61 const btVector3& getAxisA() const
62 {
63 return m_axisInA;
64 }
65 const btVector3& getAxisB() const
66 {
67 return m_axisInB;
68 }
69 btScalar getRatio() const
70 {
71 return m_ratio;
72 }
73
74 virtual void setParam(int num, btScalar value, int axis = -1)
75 {
76 (void)num;
77 (void)value;
78 (void)axis;
79 btAssert(0);
80 }
81
83 virtual btScalar getParam(int num, int axis = -1) const
84 {
85 (void)num;
86 (void)axis;
87 btAssert(0);
88 return 0.f;
89 }
90
91 virtual int calculateSerializeBufferSize() const;
92
94 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
95};
96
98 struct btGearConstraintFloatData
99{
100 btTypedConstraintFloatData m_typeConstraintData;
101
102 btVector3FloatData m_axisInA;
103 btVector3FloatData m_axisInB;
104
105 float m_ratio;
106 char m_padding[4];
107};
108
109 struct btGearConstraintDoubleData
110{
111 btTypedConstraintDoubleData m_typeConstraintData;
112
113 btVector3DoubleData m_axisInA;
114 btVector3DoubleData m_axisInB;
115
116 double m_ratio;
117};
118
119 SIMD_FORCE_INLINE int btGearConstraint::calculateSerializeBufferSize() const
120{
121 return sizeof(btGearConstraintData);
122}
123
125 SIMD_FORCE_INLINE const char* btGearConstraint::serialize(void* dataBuffer, btSerializer* serializer) const
126{
127 btGearConstraintData* gear = (btGearConstraintData*)dataBuffer;
128 btTypedConstraint::serialize(&gear->m_typeConstraintData, serializer);
129
130 m_axisInA.serialize(gear->m_axisInA);
131 m_axisInB.serialize(gear->m_axisInB);
132
133 gear->m_ratio = m_ratio;
134
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;
141#endif
142
143 return btGearConstraintDataName;
144}
145
146#endif //BT_GEAR_CONSTRAINT_H
btGearConstraintData
#define btGearConstraintData
Definition btGearConstraint.h:25
btGearConstraintDataName
#define btGearConstraintDataName
Definition btGearConstraint.h:26
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
SIMD_FORCE_INLINE
#define SIMD_FORCE_INLINE
Definition btScalar.h:98
btAssert
#define btAssert(x)
Definition btScalar.h:153
btTypedConstraint.h
btGearConstraint::serialize
virtual const char * serialize(void *dataBuffer, btSerializer *serializer) const
fills the dataBuffer and returns the struct name (and 0 on failure)
Definition btGearConstraint.h:125
btGearConstraint::~btGearConstraint
virtual ~btGearConstraint()
Definition btGearConstraint.cpp:28
btGearConstraint::m_useFrameA
bool m_useFrameA
Definition btGearConstraint.h:36
btGearConstraint::getAxisB
const btVector3 & getAxisB() const
Definition btGearConstraint.h:65
btGearConstraint::m_ratio
btScalar m_ratio
Definition btGearConstraint.h:37
btGearConstraint::getParam
virtual btScalar getParam(int num, int axis=-1) const
return the local value of parameter
Definition btGearConstraint.h:83
btGearConstraint::setParam
virtual void setParam(int num, btScalar value, int axis=-1)
override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0...
Definition btGearConstraint.h:74
btGearConstraint::m_axisInB
btVector3 m_axisInB
Definition btGearConstraint.h:35
btGearConstraint::setRatio
void setRatio(btScalar ratio)
Definition btGearConstraint.h:57
btGearConstraint::setAxisA
void setAxisA(btVector3 &axisA)
Definition btGearConstraint.h:49
btGearConstraint::setAxisB
void setAxisB(btVector3 &axisB)
Definition btGearConstraint.h:53
btGearConstraint::m_axisInA
btVector3 m_axisInA
Definition btGearConstraint.h:34
btGearConstraint::calculateSerializeBufferSize
virtual int calculateSerializeBufferSize() const
Definition btGearConstraint.h:119
btGearConstraint::getInfo2
virtual void getInfo2(btConstraintInfo2 *info)
internal method used by the constraint solver, don't use them directly
Definition btGearConstraint.cpp:38
btGearConstraint::getInfo1
virtual void getInfo1(btConstraintInfo1 *info)
internal method used by the constraint solver, don't use them directly
Definition btGearConstraint.cpp:32
btGearConstraint::btGearConstraint
btGearConstraint(btRigidBody &rbA, btRigidBody &rbB, const btVector3 &axisInA, const btVector3 &axisInB, btScalar ratio=1.f)
Implemented by Erwin Coumans. The idea for the constraint comes from Dimitris Papavasiliou.
Definition btGearConstraint.cpp:20
btGearConstraint::getAxisA
const btVector3 & getAxisA() const
Definition btGearConstraint.h:61
btGearConstraint::getRatio
btScalar getRatio() const
Definition btGearConstraint.h:69
btRigidBody
The btRigidBody is the main class for rigid body objects.
Definition btRigidBody.h:60
btSerializer
Definition btSerializer.h:66
btTypedConstraint::serialize
virtual const char * serialize(void *dataBuffer, btSerializer *serializer) const
fills the dataBuffer and returns the struct name (and 0 on failure)
Definition btTypedConstraint.cpp:104
btTypedConstraint::btTypedConstraint
btTypedConstraint(btTypedConstraintType type, btRigidBody &rbA)
Definition btTypedConstraint.cpp:22
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition btVector3.h:82
btGearConstraintDoubleData
Definition btGearConstraint.h:110
btGearConstraintDoubleData::m_ratio
double m_ratio
Definition btGearConstraint.h:116
btGearConstraintDoubleData::m_axisInA
btVector3DoubleData m_axisInA
Definition btGearConstraint.h:113
btGearConstraintDoubleData::m_typeConstraintData
btTypedConstraintDoubleData m_typeConstraintData
Definition btGearConstraint.h:111
btGearConstraintDoubleData::m_axisInB
btVector3DoubleData m_axisInB
Definition btGearConstraint.h:114
btGearConstraintFloatData
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
Definition btGearConstraint.h:99
btGearConstraintFloatData::m_typeConstraintData
btTypedConstraintFloatData m_typeConstraintData
Definition btGearConstraint.h:100
btGearConstraintFloatData::m_axisInB
btVector3FloatData m_axisInB
Definition btGearConstraint.h:103
btGearConstraintFloatData::m_ratio
float m_ratio
Definition btGearConstraint.h:105
btGearConstraintFloatData::m_padding
char m_padding[4]
Definition btGearConstraint.h:106
btGearConstraintFloatData::m_axisInA
btVector3FloatData m_axisInA
Definition btGearConstraint.h:102
btTypedConstraintDoubleData
Definition btTypedConstraint.h:411
btTypedConstraintFloatData
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
Definition btTypedConstraint.h:359
btTypedConstraint::btConstraintInfo1
Definition btTypedConstraint.h:114
btTypedConstraint::btConstraintInfo2
Definition btTypedConstraint.h:121
btVector3DoubleData
Definition btVector3.h:1287
btVector3FloatData
Definition btVector3.h:1282