[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / bullet3 / src / BulletDynamics / ConstraintSolver / btGearConstraint.h
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2012 Advanced Micro Devices, Inc.  http://bulletphysics.org
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_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
29 ///The btGeatConstraint will couple the angular velocity for two bodies around given local axis and ratio.
30 ///See Bullet/Demos/ConstraintDemo for an example use.
31 class btGearConstraint : public btTypedConstraint
32 {
33 protected:
34         btVector3 m_axisInA;
35         btVector3 m_axisInB;
36         bool m_useFrameA;
37         btScalar m_ratio;
38
39 public:
40         btGearConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& axisInA, const btVector3& axisInB, btScalar ratio = 1.f);
41         virtual ~btGearConstraint();
42
43         ///internal method used by the constraint solver, don't use them directly
44         virtual void getInfo1(btConstraintInfo1* info);
45
46         ///internal method used by the constraint solver, don't use them directly
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
82         ///return the local value of parameter
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
93         ///fills the dataBuffer and returns the struct name (and 0 on failure)
94         virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
95 };
96
97 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
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
124 ///fills the dataBuffer and returns the struct name (and 0 on failure)
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