[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / bullet3 / src / BulletDynamics / Featherstone / btMultiBodySphericalJointMotor.h
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2018 Erwin Coumans  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 ///This file was written by Erwin Coumans
17
18 #ifndef BT_MULTIBODY_SPHERICAL_JOINT_MOTOR_H
19 #define BT_MULTIBODY_SPHERICAL_JOINT_MOTOR_H
20
21 #include "btMultiBodyConstraint.h"
22 struct btSolverInfo;
23
24 class btMultiBodySphericalJointMotor : public btMultiBodyConstraint
25 {
26 protected:
27         btVector3 m_desiredVelocity;
28         btQuaternion m_desiredPosition;
29         bool m_use_multi_dof_params;
30         btVector3 m_kd;
31         btVector3 m_kp;
32         btScalar m_erp;
33         btScalar m_rhsClamp;  //maximum error
34         btVector3 m_maxAppliedImpulseMultiDof;
35         btVector3 m_damping;
36
37 public:
38         btMultiBodySphericalJointMotor(btMultiBody* body, int link, btScalar maxMotorImpulse);
39         
40         virtual ~btMultiBodySphericalJointMotor();
41         virtual void finalizeMultiDof();
42
43         virtual int getIslandIdA() const;
44         virtual int getIslandIdB() const;
45
46         virtual void createConstraintRows(btMultiBodyConstraintArray& constraintRows,
47                                                                           btMultiBodyJacobianData& data,
48                                                                           const btContactSolverInfo& infoGlobal);
49
50         virtual void setVelocityTarget(const btVector3& velTarget, btScalar kd = 1.0)
51         {
52                 m_desiredVelocity = velTarget;
53                 m_kd = btVector3(kd, kd, kd);
54                 m_use_multi_dof_params = false;
55         }
56
57         virtual void setVelocityTargetMultiDof(const btVector3& velTarget, const btVector3& kd = btVector3(1.0, 1.0, 1.0))
58         {
59                 m_desiredVelocity = velTarget;
60                 m_kd = kd;
61                 m_use_multi_dof_params = true;
62         }
63
64         virtual void setPositionTarget(const btQuaternion& posTarget, btScalar kp =1.f)
65         {
66                 m_desiredPosition = posTarget;
67                 m_kp = btVector3(kp, kp, kp);
68                 m_use_multi_dof_params = false;
69         }
70
71         virtual void setPositionTargetMultiDof(const btQuaternion& posTarget, const btVector3& kp = btVector3(1.f, 1.f, 1.f))
72         {
73                 m_desiredPosition = posTarget;
74                 m_kp = kp;
75                 m_use_multi_dof_params = true;
76         }
77
78         virtual void setErp(btScalar erp)
79         {
80                 m_erp = erp;
81         }
82         virtual btScalar getErp() const
83         {
84                 return m_erp;
85         }
86         virtual void setRhsClamp(btScalar rhsClamp)
87         {
88                 m_rhsClamp = rhsClamp;
89         }
90
91         btScalar getMaxAppliedImpulseMultiDof(int i) const
92         {
93                 return m_maxAppliedImpulseMultiDof[i];
94         }
95
96         void setMaxAppliedImpulseMultiDof(const btVector3& maxImp)
97         {
98                 m_maxAppliedImpulseMultiDof = maxImp;
99                 m_use_multi_dof_params = true;
100         }
101
102         btScalar getDamping(int i) const
103         {
104                 return m_damping[i];
105         }
106
107         void setDamping(const btVector3& damping)
108         {
109                 m_damping = damping;
110         }
111
112         virtual void debugDraw(class btIDebugDraw* drawer)
113         {
114                 //todo(erwincoumans)
115         }
116 };
117
118 #endif  //BT_MULTIBODY_SPHERICAL_JOINT_MOTOR_H