Newton Dynamics  4.00
ndBody.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_BODY_H_
23 #define __ND_BODY_H_
24 
25 #include "ndCollisionStdafx.h"
26 #include "ndShapeInstance.h"
27 
28 class ndContact;
29 class ndBodyNotify;
30 class ndBodyDynamic;
31 class ndBodySentinel;
32 class ndBodySphFluid;
33 class ndBodyKinematic;
34 class ndRayCastNotify;
35 class ndBodyParticleSet;
40 
41 D_MSV_NEWTON_ALIGN_32
42 class ndBody : public ndContainersFreeListAlloc<ndBody>
43 {
44  public:
45  D_CLASS_REFLECTION(ndBody);
46  D_COLLISION_API ndBody();
47  D_COLLISION_API ndBody(const ndLoadSaveBase::ndLoadDescriptor& desc);
48  D_COLLISION_API virtual ~ndBody();
49 
50  virtual ndBody* GetAsBody() { return this;}
51  virtual ndBodyDynamic* GetAsBodyDynamic() { return nullptr; }
52  virtual ndBodySentinel* GetAsBodySentinel() { return nullptr; }
53  virtual ndBodySphFluid* GetAsBodySphFluid() { return nullptr; }
54  virtual ndBodyKinematic* GetAsBodyKinematic() { return nullptr; }
55  virtual ndBodyParticleSet* GetAsBodyParticleSet() { return nullptr; }
56  virtual ndBodyPlayerCapsule* GetAsBodyPlayerCapsule() { return nullptr; }
57  virtual ndBodyTriggerVolume* GetAsBodyTriggerVolume() { return nullptr; }
58  virtual ndBodyKinematicBase* GetAsBodyKinematicSpecial() { return nullptr; }
59 
60  ndUnsigned32 GetId() const;
61  void GetAABB(ndVector& p0, ndVector& p1) const;
62 
63  virtual ndFloat32 GetInvMass() const;
64  virtual bool RayCast(ndRayCastNotify& callback, const ndFastRay& ray, const ndFloat32 maxT) const = 0;
65 
66  const ndVector& GetCentreOfMass() const;
67  D_COLLISION_API virtual void SetCentreOfMass(const ndVector& com);
68 
69  ndBodyNotify* GetNotifyCallback() const;
70 
71  ndVector GetOmega() const;
72  ndMatrix GetMatrix() const;
73  ndVector GetVelocity() const;
74  ndVector GetPosition() const;
75  ndQuaternion GetRotation() const;
76  ndVector GetGlobalGetCentreOfMass() const;
77 
78  D_COLLISION_API virtual void SetNotifyCallback(ndBodyNotify* const notify);
79  D_COLLISION_API virtual void SetOmega(const ndVector& veloc);
80  D_COLLISION_API virtual void SetVelocity(const ndVector& veloc);
81  D_COLLISION_API virtual void SetMatrix(const ndMatrix& matrix);
82 
83  D_COLLISION_API virtual void Save(const ndLoadSaveBase::ndSaveDescriptor& desc) const;
84  D_COLLISION_API ndVector GetVelocityAtPoint(const ndVector& point) const;
85 
86  D_COLLISION_API void SetOmegaNoSleep(const ndVector& veloc);
87  D_COLLISION_API void SetVelocityNoSleep(const ndVector& veloc);
88  D_COLLISION_API void SetMatrixNoSleep(const ndMatrix& matrix);
89  D_COLLISION_API void SetMatrixAndCentreOfMass(const ndQuaternion& rotation, const ndVector& globalcom);
90 
91  protected:
92  D_COLLISION_API static const nd::TiXmlNode* FindNode(const nd::TiXmlNode* const rootNode, const char* const name);
93 
94  virtual void AttachContact(ndContact* const) {}
95  virtual void DetachContact(ndContact* const) {}
96  virtual ndContact* FindContact(const ndBody* const) const { return nullptr; }
97 
98  ndMatrix m_matrix;
99  ndVector m_veloc;
100  ndVector m_omega;
101  ndVector m_localCentreOfMass;
102  ndVector m_globalCentreOfMass;
103  ndVector m_minAabb;
104  ndVector m_maxAabb;
105  ndQuaternion m_rotation;
106  ndBodyNotify* m_notifyCallback;
107 
108  ndUnsigned32 m_uniqueId;
109  union
110  {
111  ndUnsigned32 m_flags;
112  struct
113  {
114  ndUnsigned32 m_isDynamics : 1;
115  ndUnsigned32 m_skeletonMark : 1;
116  ndUnsigned32 m_skeletonMark0 : 1;
117  ndUnsigned32 m_skeletonMark1 : 1;
118  ndUnsigned32 m_contactTestOnly : 1;
119  ndUnsigned32 m_transformIsDirty : 1;
120  ndUnsigned32 m_equilibriumOverride : 1;
121  };
122  };
123 
124  ndUnsigned8 m_isStatic;
125  ndUnsigned8 m_autoSleep;
126  ndUnsigned8 m_equilibrium;
127  ndUnsigned8 m_equilibrium0;
128  ndUnsigned8 m_isJointFence0;
129  ndUnsigned8 m_isJointFence1;
130  ndUnsigned8 m_isConstrained;
131  ndUnsigned8 m_sceneForceUpdate;
132  ndUnsigned8 m_sceneEquilibrium;
133  ndUnsigned8 m_markedForRemoved;
134 
135  D_COLLISION_API static ndUnsigned32 m_uniqueIdCount;
136 
137  friend class ndWorld;
138  friend class ndScene;
139  friend class ndConstraint;
141 } D_GCC_NEWTON_ALIGN_32;
142 
143 inline ndUnsigned32 ndBody::GetId() const
144 {
145  return m_uniqueId;
146 }
147 
148 inline ndBodyNotify* ndBody::GetNotifyCallback() const
149 {
150  return m_notifyCallback;
151 }
152 
153 inline ndMatrix ndBody::GetMatrix() const
154 {
155  return m_matrix;
156 }
157 
158 inline ndVector ndBody::GetPosition() const
159 {
160  return m_matrix.m_posit;
161 }
162 
163 inline ndQuaternion ndBody::GetRotation() const
164 {
165  return m_rotation;
166 }
167 
168 inline ndVector ndBody::GetGlobalGetCentreOfMass() const
169 {
170  return m_globalCentreOfMass;
171 }
172 
173 inline ndVector ndBody::GetVelocity() const
174 {
175  return m_veloc;
176 }
177 
178 inline ndVector ndBody::GetOmega() const
179 {
180  return m_omega;
181 }
182 
183 inline void ndBody::GetAABB(ndVector& p0, ndVector& p1) const
184 {
185  p0 = m_minAabb;
186  p1 = m_maxAabb;
187 }
188 
189 inline const ndVector& ndBody::GetCentreOfMass() const
190 {
191  return m_localCentreOfMass;
192 }
193 
194 inline ndVector ndBody::GetVelocityAtPoint(const ndVector& point) const
195 {
196  return m_veloc + m_omega.CrossProduct(point - m_globalCentreOfMass);
197 }
198 
199 inline ndFloat32 ndBody::GetInvMass() const
200 {
201  return ndFloat32(0.0f);
202 }
203 
204 
205 #endif
206 
ndBodyNotify
Definition: ndBodyNotify.h:31
nd::TiXmlNode
The parent class for everything in the Document Object Model.
Definition: tinyxml.h:437
ndScene
Definition: ndScene.h:59
ndBody
Definition: ndBody.h:43
ndContact
Definition: ndContact.h:97
ndRayCastNotify
Definition: ndRayCastNotify.h:31
ndBodyPlayerCapsuleImpulseSolver
Definition: ndBodyPlayerCapsule.cpp:55
ndBodyDynamic
Definition: ndBodyDynamic.h:43
ndJointBilateralConstraint
Definition: ndJointBilateralConstraint.h:53
ndBodyKinematic
Definition: ndBodyKinematic.h:40
ndBodySentinel
Definition: ndBodyKinematic.h:238
ndMatrix
Definition: ndMatrix.h:42
ndBodyPlayerCapsule
Definition: ndBodyPlayerCapsule.h:33
ndBodyKinematicBase
Definition: ndBodyKinematicBase.h:30
ndBodySphFluid
Definition: ndBodySphFluid.h:30
ndQuaternion
Definition: ndQuaternion.h:32
ndFastRay
Definition: ndFastRay.h:48
ndConstraint
Definition: ndConstraint.h:229
ndContainersFreeListAlloc
Definition: ndContainersAlloc.h:60
ndBodyTriggerVolume
Definition: ndBodyTriggerVolume.h:30
ndLoadSaveBase::ndLoadDescriptor
Definition: ndSaveLoadSytem.h:59
ndLoadSaveBase::ndSaveDescriptor
Definition: ndSaveLoadSytem.h:93
ndBodyParticleSet
Definition: ndBodyParticleSet.h:29
ndVector
Definition: ndVectorArmNeon.h:41
ndWorld
Definition: ndWorld.h:47