Newton Dynamics  4.00
ndShapeConvex.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_SHAPE_CONVEX_H__
23 #define __ND_SHAPE_CONVEX_H__
24 
25 #include "ndCollisionStdafx.h"
26 #include "ndShape.h"
27 
28 #define D_CLIP_MAX_COUNT 512
29 #define D_CLIP_MAX_POINT_COUNT 64
30 #define D_MIN_CONVEX_SHAPE_SIZE ndFloat32 (1.0f/128.0f)
31 
32 D_MSV_NEWTON_ALIGN_32
33 class ndShapeConvex: public ndShape
34 {
35  public:
36  D_CLASS_REFLECTION(ndShapeConvex);
38  {
39  public:
40  ndConvexSimplexEdge* m_twin;
41  ndConvexSimplexEdge* m_next;
42  ndConvexSimplexEdge* m_prev;
43  ndInt32 m_vertex;
44  };
45 
46  protected:
47  D_COLLISION_API ndShapeConvex (ndShapeID id);
48  D_COLLISION_API ~ndShapeConvex ();
49 
50  virtual ndShapeConvex* GetAsShapeConvex() { return this; }
51 
52  D_COLLISION_API void SetVolumeAndCG();
53  D_COLLISION_API virtual void MassProperties();
54  D_COLLISION_API virtual void DebugShape(const ndMatrix& matrix, ndShapeDebugNotify& debugCallback) const;
55  D_COLLISION_API virtual ndFloat32 CalculateMassProperties(const ndMatrix& offset, ndVector& inertia, ndVector& crossInertia, ndVector& centerOfMass) const;
56  D_COLLISION_API virtual ndMatrix CalculateInertiaAndCenterOfMass(const ndMatrix& alignMatrix, const ndVector& localScale, const ndMatrix& matrix) const;
57 
58  D_COLLISION_API virtual ndShapeInfo GetShapeInfo() const;
59  D_COLLISION_API virtual void CalculateAabb(const ndMatrix& matrix, ndVector& p0, ndVector& p1) const;
60  D_COLLISION_API virtual ndVector SupportVertex(const ndVector& dir, ndInt32* const vertexIndex) const;
61  D_COLLISION_API virtual ndInt32 CalculatePlaneIntersection(const ndVector& normal, const ndVector& point, ndVector* const contactsOut) const;
62  D_COLLISION_API virtual ndVector CalculateVolumeIntegral(const ndMatrix& globalMatrix, const ndVector& globalPlane, const ndShapeInstance& parentScale) const;
63  D_COLLISION_API virtual ndFloat32 RayCast(ndRayCastNotify& callback, const ndVector& localP0, const ndVector& localP1, ndFloat32 maxT, const ndBody* const body, ndContactPoint& contactOut) const;
64 
65  D_COLLISION_API virtual void Save(const ndLoadSaveBase::ndSaveDescriptor& desc) const;
66  bool SanityCheck(ndPolyhedra& hull) const;
67  bool SanityCheck(ndInt32 count, const ndVector& normal, ndVector* const contactsOut) const;
68  ndInt32 RectifyConvexSlice(ndInt32 count, const ndVector& normal, ndVector* const contactsOut) const;
69  virtual ndInt32 GetConvexVertexCount() const { return m_vertexCount; }
70  virtual ndVector SupportVertexSpecial(const ndVector& dir, ndFloat32, ndInt32* const vertexIndex) const
71  {
72  return SupportVertex(dir, vertexIndex);
73  }
74 
75  virtual ndVector SupportVertexSpecialProjectPoint(const ndVector& point, const ndVector&) const
76  {
77  return point;
78  }
79 
80  virtual const ndConvexSimplexEdge** GetVertexToEdgeMapping() const
81  {
82  return nullptr;
83  }
84 
85  virtual ndFloat32 GetVolume() const;
86  virtual ndFloat32 GetBoxMinRadius() const;
87  virtual ndFloat32 GetBoxMaxRadius() const;
88 
89  ndVector CalculateVolumeIntegral(const ndPlane& plane) const;
90  ndInt32 BuildCylinderCapPoly (ndFloat32 radius, const ndMatrix& transform, ndVector* const vertexOut) const;
91 
92  ndVector* m_vertex;
93  ndConvexSimplexEdge* m_simplex;
94 
95  ndFloat32 m_boxMinRadius;
96  ndFloat32 m_boxMaxRadius;
97  ndFloat32 m_simplexVolume;
98  ndUnsigned16 m_edgeCount;
99  ndUnsigned16 m_vertexCount;
100  friend class ndMeshEffect;
101  friend class ndContactSolver;
102 } D_GCC_NEWTON_ALIGN_32 ;
103 
104 #endif
105 
106 
ndBody
Definition: ndBody.h:43
ndShape
Definition: ndShape.h:209
ndContactSolver
Definition: ndContactSolver.h:60
ndRayCastNotify
Definition: ndRayCastNotify.h:31
ndPlane
Definition: ndPlane.h:35
ndShapeConvex::ndConvexSimplexEdge
Definition: ndShapeConvex.h:38
ndShapeConvex
Definition: ndShapeConvex.h:34
ndContactPoint
Definition: ndContact.h:39
ndMeshEffect
Definition: ndMeshEffect.h:48
ndMatrix
Definition: ndMatrix.h:42
ndShapeDebugNotify
Definition: ndShapeInstance.h:38
ndShapeInfo
Definition: ndShape.h:182
ndPolyhedra
Definition: ndPolyhedra.h:60
ndShapeInstance
Definition: ndShapeInstance.h:62
ndLoadSaveBase::ndSaveDescriptor
Definition: ndSaveLoadSytem.h:93
ndVector
Definition: ndVectorArmNeon.h:41