Newton Dynamics  4.00
ndJointKinematicController.h
1 /* Copyright (c) <2003-2022> <Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely
10 */
11 
12 #ifndef __ND_JOINT_KINEMATIC_CONTROLLER_H__
13 #define __ND_JOINT_KINEMATIC_CONTROLLER_H__
14 
15 #include "ndNewtonStdafx.h"
16 #include "ndJointBilateralConstraint.h"
17 
19 {
20  public:
21  enum ndControlModes
22  {
23  m_linear,
24  m_full6dof,
25  m_linearPlusAngularFriction, // for pick mode from screen
26  };
27 
28  D_CLASS_REFLECTION(ndJointKinematicController);
30  D_NEWTON_API ndJointKinematicController(ndBodyKinematic* const referenceBody, ndBodyKinematic* const body, const ndVector& attachmentPointInGlobalSpace);
31  D_NEWTON_API ndJointKinematicController(ndBodyKinematic* const referenceBody, ndBodyKinematic* const body, const ndMatrix& attachmentMatrixInGlobalSpace);
32  D_NEWTON_API virtual ~ndJointKinematicController();
33 
34  virtual bool IsBilateral() const;
35  void SetControlMode(ndControlModes mode);
36  void SetMaxSpeed(ndFloat32 speedInMetersPerSeconds);
37  void SetMaxOmega(ndFloat32 speedInRadiansPerSeconds);
38  void SetMaxLinearFriction(ndFloat32 force);
39  void SetMaxAngularFriction(ndFloat32 torque);
40  void SetAngularViscousFrictionCoefficient(ndFloat32 coefficient);
41 
42  ndMatrix GetTargetMatrix() const;
43  void SetTargetPosit(const ndVector& posit);
44  void SetTargetRotation(const ndQuaternion& rotation);
45 
46  D_NEWTON_API void SetTargetMatrix(const ndMatrix& matrix);
47 
48  protected:
49  void Init(const ndMatrix& matrix);
50 
51  D_NEWTON_API void CheckSleep() const;
52  D_NEWTON_API void JacobianDerivative(ndConstraintDescritor& desc);
53  D_NEWTON_API void Save(const ndLoadSaveBase::ndSaveDescriptor& desc) const;
54 
55  private:
56  ndFloat32 m_maxSpeed;
57  ndFloat32 m_maxOmega;
58  ndFloat32 m_maxLinearFriction;
59  ndFloat32 m_maxAngularFriction;
60  ndFloat32 m_angularFrictionCoefficient;
61  ndControlModes m_controlMode;
62  bool m_autoSleepState;
63 };
64 
65 inline void ndJointKinematicController::SetControlMode(ndControlModes mode)
66 {
67  m_controlMode = mode;
68 }
69 
70 inline void ndJointKinematicController::SetMaxSpeed(ndFloat32 speedInMetersPerSeconds)
71 {
72  m_maxSpeed = ndAbs(speedInMetersPerSeconds);
73 }
74 
75 inline void ndJointKinematicController::SetMaxLinearFriction(ndFloat32 frictionForce)
76 {
77  m_maxLinearFriction = ndAbs(frictionForce);
78 }
79 
80 inline void ndJointKinematicController::SetMaxAngularFriction(ndFloat32 frictionTorque)
81 {
82  m_maxAngularFriction = ndAbs(frictionTorque);
83 }
84 
85 inline void ndJointKinematicController::SetMaxOmega(ndFloat32 speedInRadiansPerSeconds)
86 {
87  m_maxOmega = ndAbs(speedInRadiansPerSeconds);
88 }
89 
90 inline void ndJointKinematicController::SetAngularViscousFrictionCoefficient(ndFloat32 coefficient)
91 {
92  ndVector mass (GetBody0()->GetMassMatrix());
93  m_angularFrictionCoefficient = ndAbs(coefficient) * ndMax(mass.m_x, ndMax(mass.m_y, mass.m_z));
94 }
95 
96 inline void ndJointKinematicController::SetTargetPosit(const ndVector& posit)
97 {
98  ndMatrix matrix(m_localMatrix1);
99  matrix.m_posit = posit;
100  SetTargetMatrix(matrix);
101 }
102 
103 inline void ndJointKinematicController::SetTargetRotation(const ndQuaternion& rotation)
104 {
105  ndMatrix matrix(rotation, m_localMatrix1.m_posit);
106  SetTargetMatrix(matrix);
107 }
108 
109 inline ndMatrix ndJointKinematicController::GetTargetMatrix() const
110 {
111  ndAssert(0);
112  return m_localMatrix0;
113 }
114 
115 inline bool ndJointKinematicController::IsBilateral() const
116 {
117  return true;
118 }
119 
120 #endif
121 
ndJointKinematicController
Definition: ndJointKinematicController.h:19
ndConstraintDescritor
Definition: ndConstraint.h:179
ndJointBilateralConstraint
Definition: ndJointBilateralConstraint.h:53
ndBodyKinematic
Definition: ndBodyKinematic.h:40
ndMatrix
Definition: ndMatrix.h:42
ndQuaternion
Definition: ndQuaternion.h:32
ndLoadSaveBase::ndLoadDescriptor
Definition: ndSaveLoadSytem.h:59
ndLoadSaveBase::ndSaveDescriptor
Definition: ndSaveLoadSytem.h:93
ndVector
Definition: ndVectorArmNeon.h:41