Newton Dynamics  4.00
ndContact.h
1 /* Copyright (c) <2003-2022> <Julio Jerez, 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, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 #ifndef __ND_CONTACT_H__
23 #define __ND_CONTACT_H__
24 
25 #include "ndCollisionStdafx.h"
26 #include "ndConstraint.h"
27 #include "ndContactNotify.h"
28 #include "ndContactSolver.h"
29 
30 class ndBodyKinematic;
31 class ndShapeInstance;
32 
33 #define D_MAX_CONTATCS 128
34 #define D_CONSTRAINT_MAX_ROWS (3 * 16)
35 #define D_RESTING_CONTACT_PENETRATION (D_PENETRATION_TOL + ndFloat32 (1.0f / 1024.0f))
36 
37 D_MSV_NEWTON_ALIGN_32
39 {
40  public:
41  ndVector m_point;
42  ndVector m_normal;
43  const ndBodyKinematic* m_body0;
44  const ndBodyKinematic* m_body1;
45  const ndShapeInstance* m_shapeInstance0;
46  const ndShapeInstance* m_shapeInstance1;
47  ndInt64 m_shapeId0;
48  ndInt64 m_shapeId1;
49  ndFloat32 m_penetration;
50 } D_GCC_NEWTON_ALIGN_32;
51 
52 D_MSV_NEWTON_ALIGN_32
54 {
55  public:
57  :m_dir0(ndVector::m_zero)
58  ,m_dir1(ndVector::m_zero)
59  ,m_material()
60  {
61  m_dir0_Force.Clear();
62  m_dir1_Force.Clear();
63  m_normal_Force.Clear();
64  }
65 
66  void OverrideFriction0Accel(ndFloat32 accel)
67  {
68  m_dir0_Force.m_force = accel;
69  m_material.m_flags = m_material.m_flags | m_override0Accel;
70  }
71 
72  void OverrideFriction1Accel(ndFloat32 accel)
73  {
74  m_dir1_Force.m_force = accel;
75  m_material.m_flags = m_material.m_flags | m_override1Accel;
76  }
77 
78  ndVector m_dir0;
79  ndVector m_dir1;
80  ndForceImpactPair m_normal_Force;
81  ndForceImpactPair m_dir0_Force;
82  ndForceImpactPair m_dir1_Force;
83  ndMaterial m_material;
84 } D_GCC_NEWTON_ALIGN_32;
85 
86 class ndContactPointList : public ndList<ndContactMaterial, ndContainersFreeListAlloc<ndContactMaterial>>
87 {
88  public:
91  {
92  }
93 };
94 
95 D_MSV_NEWTON_ALIGN_32
96 class ndContact: public ndConstraint
97 {
98  public:
99  D_COLLISION_API ndContact();
100  D_COLLISION_API virtual ~ndContact();
101 
102  D_COLLISION_API virtual ndBodyKinematic* GetBody0() const;
103  D_COLLISION_API virtual ndBodyKinematic* GetBody1() const;
104 
105  D_COLLISION_API void AttachToBodies();
106  D_COLLISION_API void DetachFromBodies();
107 
108  ndContact* GetAsContact();
109  virtual ndUnsigned32 GetRowsCount() const;
110 
111  const ndMaterial* GetMaterial() const;
112  virtual void JacobianDerivative(ndConstraintDescritor& desc);
113  virtual void JointAccelerations(ndJointAccelerationDecriptor* const desc);
114 
115  ndContactPointList& GetContactPoints();
116  const ndContactPointList& GetContactPoints() const;
117 
118  bool IsSkeletonSelftCollision() const;
119  bool IsSkeletonIntraCollision() const;
120 
121  private:
122  void SetBodies(ndBodyKinematic* const body0, ndBodyKinematic* const body1);
123  void CalculatePointDerivative(ndInt32 index, ndConstraintDescritor& desc, const ndVector& dir, const ndPointParam& param) const;
124  void JacobianContactDerivative(ndConstraintDescritor& desc, const ndContactMaterial& contact, ndInt32 normalIndex, ndInt32& frictionIndex);
125 
126  ndVector m_positAcc;
127  ndQuaternion m_rotationAcc;
128  ndVector m_separatingVector;
129  ndContactPointList m_contacPointsList;
130  ndBodyKinematic* m_body0;
131  ndBodyKinematic* m_body1;
132  ndMaterial* m_material;
133  ndFloat32 m_timeOfImpact;
134  ndFloat32 m_separationDistance;
135  ndUnsigned32 m_maxDOF;
136  ndUnsigned32 m_sceneLru;
137  ndUnsigned32 m_isDead : 1;
138  ndUnsigned32 m_isAttached : 1;
139  ndUnsigned32 m_isIntersetionTestOnly : 1;
140  ndUnsigned32 m_skeletonIntraCollision : 1;
141  ndUnsigned32 m_skeletonSelftCollision : 1;
142  static ndVector m_initialSeparatingVector;
143 
144  friend class ndScene;
145  friend class ndContactArray;
146  friend class ndBodyKinematic;
147  friend class ndContactSolver;
148  friend class ndShapeInstance;
149  friend class ndConvexCastNotify;
150  friend class ndShapeConvexPolygon;
152 } D_GCC_NEWTON_ALIGN_32 ;
153 
154 inline ndContact* ndContact::GetAsContact()
155 {
156  return this;
157 }
158 
159 inline const ndMaterial* ndContact::GetMaterial() const
160 {
161  return m_material;
162 }
163 
164 inline ndUnsigned32 ndContact::GetRowsCount() const
165 {
166  return m_maxDOF;
167 }
168 
169 inline ndBodyKinematic* ndContact::GetBody0() const
170 {
171  return m_body0;
172 }
173 
174 inline ndBodyKinematic* ndContact::GetBody1() const
175 {
176  return m_body1;
177 }
178 
179 inline ndContactPointList& ndContact::GetContactPoints()
180 {
181  return m_contacPointsList;
182 }
183 
184 inline const ndContactPointList& ndContact::GetContactPoints() const
185 {
186  return m_contacPointsList;
187 }
188 
189 //inline bool ndContact::IsActive() const
190 //{
191 // return m_active ? true : false;
192 //}
193 
194 inline bool ndContact::IsSkeletonSelftCollision() const
195 {
196  return m_skeletonSelftCollision ? true : false;;
197 }
198 
199 inline bool ndContact::IsSkeletonIntraCollision() const
200 {
201  return m_skeletonIntraCollision ? true : false;
202 }
203 
204 
205 #endif
206 
ndScene
Definition: ndScene.h:59
ndContact
Definition: ndContact.h:97
ndContactPointList
Definition: ndContact.h:87
ndShapeConvexPolygon
Definition: ndShapeConvexPolygon.h:32
ndContactSolver
Definition: ndContactSolver.h:60
ndConstraintDescritor
Definition: ndConstraint.h:179
ndBodyPlayerCapsuleContactSolver
Definition: ndBodyPlayerCapsule.cpp:43
ndContactPoint
Definition: ndContact.h:39
ndForceImpactPair
Definition: ndConstraint.h:114
ndBodyKinematic
Definition: ndBodyKinematic.h:40
ndContactArray
Definition: ndContactArray.h:29
ndList
Definition: ndList.h:33
ndContactMaterial
Definition: ndContact.h:54
ndQuaternion
Definition: ndQuaternion.h:32
ndConstraint
Definition: ndConstraint.h:229
ndJointAccelerationDecriptor
Definition: ndConstraint.h:158
ndConvexCastNotify
Definition: ndConvexCastNotify.h:34
ndShapeInstance
Definition: ndShapeInstance.h:62
ndMaterial
Definition: ndContactNotify.h:33
ndVector
Definition: ndVectorArmNeon.h:41
ndPointParam
Definition: ndConstraint.h:89