22 #ifndef __ND_SHAPE_INSTANCE_H__
23 #define __ND_SHAPE_INSTANCE_H__
25 #define D_MAX_SHAPE_AABB_PADDING ndFloat32 (1.0f / 16.0f)
55 virtual void DrawPolygon(ndInt32 vertexCount,
const ndVector*
const faceArray,
const ndEdgeType*
const edgeType) = 0;
58 } D_GCC_NEWTON_ALIGN_32;
77 ,m_point0(ndVector::m_wOne)
78 ,m_point1(ndVector::m_wOne)
79 ,m_normal(ndVector::m_zero)
86 D_COLLISION_API
bool ClosestPoint();
114 D_COLLISION_API
ndMatrix CalculateInertia()
const;
124 D_COLLISION_API ndFloat32 CalculateBuoyancyCenterOfPresure(
ndVector& com,
const ndMatrix& matrix,
const ndVector& fluidPlane)
const;
126 D_COLLISION_API
static ndVector GetBoxPadding();
128 D_COLLISION_API
void SavePLY(
const char*
const fileName)
const;
131 const ndShape* GetShape()
const;
132 void SetShape(
ndShape*
const shape);
135 ndVector SupportVertexSpecial(
const ndVector& dir, ndInt32*
const vertexIndex)
const;
138 const ndMatrix& GetLocalMatrix()
const;
139 void SetLocalMatrix(
const ndMatrix& matrix);
141 const ndMatrix& GetGlobalMatrix()
const;
142 void SetGlobalMatrix(
const ndMatrix& scale);
144 bool GetCollisionMode()
const;
145 void SetCollisionMode(
bool mode);
146 ndInt32 GetConvexVertexCount()
const;
152 const ndVector& GetInvScale()
const;
153 const ndMatrix& GetAlignmentMatrix()
const;
155 D_COLLISION_API
void SetScale(
const ndVector& scale);
156 D_COLLISION_API
void SetGlobalScale(
const ndVector& scale);
157 D_COLLISION_API
void SetGlobalScale(
const ndMatrix& scaleMatrix);
158 D_COLLISION_API ndInt32 CalculatePlaneIntersection(
const ndVector& normal,
const ndVector& point,
ndVector*
const contactsOut)
const;
160 ndFloat32 GetVolume()
const;
161 ndFloat32 GetBoxMinRadius()
const;
162 ndFloat32 GetBoxMaxRadius()
const;
164 ndScaleType GetScaleType()
const;
165 ndFloat32 GetUmbraClipSize()
const;
166 ndUnsigned64 GetUserDataID()
const;
177 const ndBody* m_ownerBody;
178 const void* m_subCollisionHandle;
180 ndFloat32 m_skinMargin;
181 ndScaleType m_scaleType;
182 bool m_collisionMode;
186 } D_GCC_NEWTON_ALIGN_32 ;
188 inline ndShape* ndShapeInstance::GetShape()
193 inline const ndShape* ndShapeInstance::GetShape()
const
198 inline const ndMatrix& ndShapeInstance::GetAlignmentMatrix()
const
200 return m_alignmentMatrix;
203 inline const ndMatrix& ndShapeInstance::GetLocalMatrix()
const
205 return m_localMatrix;
208 inline void ndShapeInstance::SetLocalMatrix(
const ndMatrix& matrix)
210 m_localMatrix = matrix;
213 inline const ndMatrix& ndShapeInstance::GetGlobalMatrix()
const
215 return m_globalMatrix;
218 inline void ndShapeInstance::SetGlobalMatrix(
const ndMatrix& matrix)
220 m_globalMatrix = matrix;
223 inline ndMatrix ndShapeInstance::GetScaledTransform(
const ndMatrix& matrix)
const
225 ndMatrix scale(ndGetIdentityMatrix());
226 scale[0][0] = m_scale.m_x;
227 scale[1][1] = m_scale.m_y;
228 scale[2][2] = m_scale.m_z;
229 return m_alignmentMatrix * scale * m_localMatrix * matrix;
232 inline ndInt32 ndShapeInstance::GetConvexVertexCount()
const
234 return m_shape->GetConvexVertexCount();
239 const ndVector dir(inDir & ndVector::m_triplexMask);
240 ndAssert(dir.m_w == ndFloat32(0.0f));
241 ndAssert(ndAbs(dir.DotProduct(dir).GetScalar() - ndFloat32(1.0f)) < ndFloat32(1.0e-2f));
246 return m_shape->SupportVertex(dir,
nullptr);
250 return m_scale * m_shape->SupportVertex(dir,
nullptr);
255 const ndVector dir1((m_scale * dir).Normalize());
256 return m_scale * m_shape->SupportVertex(dir1,
nullptr);
262 const ndVector dir1(m_alignmentMatrix.UnrotateVector((m_scale * dir).Normalize()));
263 return m_scale * m_alignmentMatrix.TransformVector(m_shape->SupportVertex(dir1,
nullptr));
268 inline ndVector ndShapeInstance::SupportVertexSpecial(
const ndVector& inDir, ndInt32*
const vertexIndex)
const
270 const ndVector dir(inDir & ndVector::m_triplexMask);
271 ndAssert(dir.m_w == ndFloat32(0.0f));
272 ndAssert(ndAbs(dir.DotProduct(dir).GetScalar() - ndFloat32(1.0f)) < ndFloat32(1.0e-2f));
277 return m_shape->SupportVertexSpecial(dir, m_skinMargin, vertexIndex);
281 return m_scale * m_shape->SupportVertexSpecial(dir, m_skinMargin, vertexIndex);
287 return SupportVertex(dir);
291 inline ndVector ndShapeInstance::SupportVertexSpecialProjectPoint(
const ndVector& point,
const ndVector& inDir)
const
293 const ndVector dir(inDir & ndVector::m_triplexMask);
294 ndAssert(dir.m_w == ndFloat32(0.0f));
295 ndAssert(ndAbs(dir.DotProduct(dir).GetScalar() - ndFloat32(1.0f)) < ndFloat32(1.0e-2f));
300 return m_shape->SupportVertexSpecialProjectPoint(point, dir);
304 return m_scale * m_shape->SupportVertexSpecialProjectPoint(point * m_invScale, dir);
316 dVector dir1((m_scale * dir).Normalize());
317 return m_scale * m_shape->SupportVertexSpecialProjectPoint(point * m_invScale, dir1);
323 dVector dir1(m_alignmentMatrix.UnrotateVector((m_scale * dir).Normalize()));
324 return m_scale * m_alignmentMatrix.TransformVector(m_shape->SupportVertexSpecialProjectPoint(m_alignmentMatrix.UntransformVector(point * m_invScale), dir1));
330 inline bool ndShapeInstance::GetCollisionMode()
const
332 return m_collisionMode;
335 inline void ndShapeInstance::SetCollisionMode(
bool mode)
337 m_collisionMode = mode;
340 inline const ndVector& ndShapeInstance::GetScale()
const
345 inline const ndVector& ndShapeInstance::GetInvScale()
const
350 inline ndFloat32 ndShapeInstance::GetBoxMinRadius()
const
352 return m_shape->GetBoxMinRadius() * m_maxScale.m_x;
355 inline ndFloat32 ndShapeInstance::GetBoxMaxRadius()
const
357 return m_shape->GetBoxMaxRadius() * m_maxScale.m_x;
360 inline ndFloat32 ndShapeInstance::GetVolume()
const
362 return m_shape->GetVolume() * m_scale.m_x * m_scale.m_y * m_scale.m_z;
367 return m_shapeMaterial;
370 inline void ndShapeInstance::SetMaterial(
const ndShapeMaterial& material)
372 m_shapeMaterial = material;
375 inline ndShapeInstance::ndScaleType ndShapeInstance::GetScaleType()
const
380 inline ndFloat32 ndShapeInstance::GetUmbraClipSize()
const
382 return m_shape->GetUmbraClipSize() * m_maxScale.m_x;
385 inline ndUnsigned64 ndShapeInstance::GetUserDataID()
const
387 return ndUnsigned64 (m_shapeMaterial.m_userId);
390 inline void ndShapeInstance::SetShape(
ndShape*
const shape)
396 m_shape = shape ? shape->AddRef() : shape;