My Project: dynamics.mod/NewtonDynamics/source/physics/dgCollisionDeformableMesh.h Source File

My Project

dgCollisionDeformableMesh.h
Go to the documentation of this file.
1 /* Copyright (c) <2003-2011> <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
23 #ifndef __DGCOLLISION_DEFORMABLE_MESH_H__
24 #define __DGCOLLISION_DEFORMABLE_MESH_H__
25
26
27 #include "dgCollision.h"
28 #include "dgCollisionConvex.h"
29
30 class dgDeformableBody;
31 class dgDeformableContact;
32 class dgCollisionConvexPolygon;
33
34 #define DG_SOFTBODY_BASE_SIZE 8
35
36 class dgCollisionDeformableMesh: public dgCollisionConvex
37 {
38 public:
39 class dgParticle
40 {
41 public:
42 dgParticle(dgInt32 particlesCount);
43 dgParticle(const dgParticle& source);
44 dgParticle (dgWorld* const world, dgDeserialize deserialization, void* const userData);
45 ~dgParticle();
46
47 dgVector* m_posit;
48 dgVector* m_veloc;
49 dgFloat32* m_unitMass;
50 dgInt32 m_count;
51 };
52
53 class dgVisualVertexData
54 {
55 public:
56 dgFloat32 m_normals[3];
57 dgFloat32 m_uv0[2];
58 dgInt32 m_vertexIndex;
59 };
60
61 class dgMeshSegment
62 {
63 public:
64 dgMeshSegment ()
65 {
66 }
67 ~dgMeshSegment ()
68 {
69 if (m_indexList) {
70 dgFree(m_indexList);
71 }
72 }
73
74 dgInt32 m_material;
75 dgInt32 m_indexCount;
76 dgInt32* m_indexList;
77 };
78
79 dgCollisionDeformableMesh (const dgCollisionDeformableMesh& source);
80 dgCollisionDeformableMesh (dgWorld* const world, dgMeshEffect* const mesh, dgCollisionID collsionID);
81 dgCollisionDeformableMesh (dgWorld* const world, dgDeserialize deserialization, void* const userData);
82 virtual ~dgCollisionDeformableMesh(void);
83
84 dgBody* GetBody() const;
85 dgInt32 GetParticleCount() const;
86 dgVector GetParticlePosition(dgInt32 index) const;
87
88 void SetOnDebugDisplay (dgCollision::OnDebugCollisionMeshCallback debugDisplay);
89
90 void UpdateVisualNormals();
91 dgInt32 GetVisualPointsCount() const;
92 void SetSkinThickness (dgFloat32 skinThickness);
93 void GetVisualVertexData(dgInt32 vertexStrideInByte, dgFloat32* const vertex, dgInt32 normalStrideInByte, dgFloat32* const normals, dgInt32 uvStrideInByte0, dgFloat32* const uv0);
94
95
96
97 virtual void SetMass (dgFloat32 mass) = 0;
98 virtual void SetMatrix(const dgMatrix& matrix) = 0;
99 virtual void ApplyExternalForces (dgFloat32 timestep) = 0;
100 virtual void ResolvePositionsConstraints (dgFloat32 timestep) = 0;
101
102 virtual void CreateClusters (dgInt32 count, dgFloat32 overlaringWidth) = 0;
103
104 virtual void EndConfiguration () = 0;
105 virtual void ConstraintParticle (dgInt32 particleIndex, const dgVector& posit, const dgBody* const body) = 0;
106
107 void* GetFirtVisualSegment() const;
108 void* GetNextVisualSegment(void* const segment) const;
109 dgInt32 GetSegmentMaterial (void* const segment) const;
110 dgInt32 GetSegmentIndexCount (void* const segment) const;
111 const dgInt32* GetSegmentIndexList (void* const segment) const;
112
113 protected:
114 class dgDeformableNode;
115
116 virtual void SetCollisionBBox (const dgVector& p0, const dgVector& p1);
117 virtual void DebugCollision (const dgMatrix& matrixPtr, dgCollision::OnDebugCollisionMeshCallback callback, void* const userData) const;
118 virtual void CalcAABB (const dgMatrix& matrix, dgVector& p0, dgVector& p1) const;
119
120 bool SanityCheck () const;
121 void ImproveTotalFitness();
122 void ImproveNodeFitness (dgDeformableNode* const node);
123 dgDeformableNode* BuildTopDown (dgInt32 count, dgDeformableNode* const children, dgDeformableNode* const parent);
124 dgFloat32 CalculateSurfaceArea (const dgDeformableNode* const node0, const dgDeformableNode* const node1, dgVector& minBox, dgVector& maxBox) const;
125 dgInt32 CalculateContacts (dgCollidingPairCollector::dgPair* const pair, dgCollisionParamProxy& proxy);
126
127 dgFloat32 CalculateMassProperties (const dgMatrix& offset, dgVector& inertia, dgVector& crossInertia, dgVector& centerOfMass) const;
128
129 dgVector m_basePosit;
130 dgParticle m_particles;
131 dgList<dgMeshSegment> m_visualSegments;
132 dgFloat32 m_skinThickness;
133 dgInt32 m_nodesCount;
134 dgInt32 m_trianglesCount;
135 dgInt32 m_visualVertexCount;
136
137 dgWorld* m_world;
138 dgDeformableBody* m_myBody;
139 dgInt32* m_indexList;
140 dgVector* m_faceNormals;
141 dgDeformableNode* m_rootNode;
142 dgDeformableNode* m_nodesMemory;
143 dgVisualVertexData* m_visualVertexData;
144 mutable dgCollision::OnDebugCollisionMeshCallback m_onDebugDisplay;
145 bool m_isdoubleSided;
146
147 friend class dgWorld;
148 friend class dgDeformableBody;
149 };
150
151
152 #endif
153
dgCollisionDeformableMesh::m_visualVertexData
dgVisualVertexData * m_visualVertexData
Definition: dgCollisionDeformableMesh.h:143
dgCollisionDeformableMesh::UpdateVisualNormals
void UpdateVisualNormals()
Definition: dgCollisionDeformableMesh.cpp:770
dgCollisionDeformableMesh::m_particles
dgParticle m_particles
Definition: dgCollisionDeformableMesh.h:130
dgCollisionDeformableMesh::dgParticle::dgParticle
dgParticle(dgInt32 particlesCount)
Definition: dgCollisionDeformableMesh.cpp:51
dgCollisionDeformableMesh::GetSegmentMaterial
dgInt32 GetSegmentMaterial(void *const segment) const
Definition: dgCollisionDeformableMesh.cpp:882
dgCollidingPairCollector::dgPair
Definition: dgContact.h:52
dgCollisionDeformableMesh::dgMeshSegment::m_indexList
dgInt32 * m_indexList
Definition: dgCollisionDeformableMesh.h:76
dgCollision::OnDebugCollisionMeshCallback
void(dgApi * OnDebugCollisionMeshCallback)(void *userData, int vertexCount, const dgFloat32 *FaceArray, int faceId)
Definition: dgCollision.h:220
dgCollisionDeformableMesh::SetOnDebugDisplay
void SetOnDebugDisplay(dgCollision::OnDebugCollisionMeshCallback debugDisplay)
Definition: dgCollisionDeformableMesh.cpp:964
dgBody
Definition: dgBody.h:44
dgCollisionDeformableMesh::dgVisualVertexData
Definition: dgCollisionDeformableMesh.h:53
userData
void *const userData
Definition: dgBroadPhase.h:35
dgCollisionDeformableMesh::GetSegmentIndexList
const dgInt32 * GetSegmentIndexList(void *const segment) const
Definition: dgCollisionDeformableMesh.cpp:894
dgFloat32
float dgFloat32
Definition: dgTypes.h:233
dgInt32
int dgInt32
Definition: dgTypes.h:218
dgVector
Definition: dgVector.h:639
dgCollisionDeformableMesh::GetVisualPointsCount
dgInt32 GetVisualPointsCount() const
Definition: dgCollisionDeformableMesh.cpp:764
dgCollisionDeformableMesh::m_nodesCount
dgInt32 m_nodesCount
Definition: dgCollisionDeformableMesh.h:133
dgCollisionDeformableMesh::CreateClusters
virtual void CreateClusters(dgInt32 count, dgFloat32 overlaringWidth)=0
dgCollisionDeformableMesh::m_myBody
dgDeformableBody * m_myBody
Definition: dgCollisionDeformableMesh.h:138
dgCollisionDeformableMesh::dgParticle::~dgParticle
~dgParticle()
Definition: dgCollisionDeformableMesh.cpp:78
dgCollisionDeformableMesh::m_onDebugDisplay
dgCollision::OnDebugCollisionMeshCallback m_onDebugDisplay
Definition: dgCollisionDeformableMesh.h:144
dgCollisionDeformableMesh::EndConfiguration
virtual void EndConfiguration()=0
dgCollisionDeformableMesh::dgMeshSegment::dgMeshSegment
dgMeshSegment()
Definition: dgCollisionDeformableMesh.h:64
dgDeformableBody
Definition: dgDeformableBody.h:30
dgCollisionDeformableMesh::SetSkinThickness
void SetSkinThickness(dgFloat32 skinThickness)
Definition: dgCollisionDeformableMesh.cpp:754
dgCollisionDeformableMesh::dgVisualVertexData::m_vertexIndex
dgInt32 m_vertexIndex
Definition: dgCollisionDeformableMesh.h:58
dgCollisionConvexPolygon
Definition: dgCollisionConvexPolygon.h:31
dgFree
void dgApi dgFree(void *const ptr)
Definition: dgMemory.cpp:457
dgCollisionDeformableMesh::dgParticle::m_posit
dgVector * m_posit
Definition: dgCollisionDeformableMesh.h:47
dgCollisionDeformableMesh::CalculateSurfaceArea
dgFloat32 CalculateSurfaceArea(const dgDeformableNode *const node0, const dgDeformableNode *const node1, dgVector &minBox, dgVector &maxBox) const
Definition: dgCollisionDeformableMesh.cpp:445
dgList
Definition: dgList.h:33
dgCollisionDeformableMesh::ImproveTotalFitness
void ImproveTotalFitness()
Definition: dgCollisionDeformableMesh.cpp:726
dgCollisionDeformableMesh::dgMeshSegment::m_material
dgInt32 m_material
Definition: dgCollisionDeformableMesh.h:74
dgMeshEffect
Definition: dgMeshEffect.h:45
dgCollisionDeformableMesh::SetMass
virtual void SetMass(dgFloat32 mass)=0
dgCollisionDeformableMesh::m_isdoubleSided
bool m_isdoubleSided
Definition: dgCollisionDeformableMesh.h:145
dgCollisionDeformableMesh::GetBody
dgBody * GetBody() const
Definition: dgCollisionDeformableMesh.cpp:426
dgCollisionDeformableMesh::GetVisualVertexData
void GetVisualVertexData(dgInt32 vertexStrideInByte, dgFloat32 *const vertex, dgInt32 normalStrideInByte, dgFloat32 *const normals, dgInt32 uvStrideInByte0, dgFloat32 *const uv0)
Definition: dgCollisionDeformableMesh.cpp:812
dgCollisionDeformableMesh::m_skinThickness
dgFloat32 m_skinThickness
Definition: dgCollisionDeformableMesh.h:132
dgDeserialize
void(dgApi * dgDeserialize)(void *const userData, void *buffer, size_t size)
Definition: dgTypes.h:279
dgCollisionDeformableMesh::SetMatrix
virtual void SetMatrix(const dgMatrix &matrix)=0
dgCollisionDeformableMesh::m_nodesMemory
dgDeformableNode * m_nodesMemory
Definition: dgCollisionDeformableMesh.h:142
dgCollisionDeformableMesh::m_visualSegments
dgList< dgMeshSegment > m_visualSegments
Definition: dgCollisionDeformableMesh.h:131
dgCollisionDeformableMesh::dgParticle
Definition: dgCollisionDeformableMesh.h:39
dgCollisionDeformableMesh::ConstraintParticle
virtual void ConstraintParticle(dgInt32 particleIndex, const dgVector &posit, const dgBody *const body)=0
dgCollisionDeformableMesh
Definition: dgCollisionDeformableMesh.h:36
dgCollisionDeformableMesh::CalculateContacts
dgInt32 CalculateContacts(dgCollidingPairCollector::dgPair *const pair, dgCollisionParamProxy &proxy)
Definition: dgCollisionDeformableMesh.cpp:901
dgCollisionDeformableMesh::SetCollisionBBox
virtual void SetCollisionBBox(const dgVector &p0, const dgVector &p1)
Definition: dgCollisionDeformableMesh.cpp:431
dgCollisionDeformableMesh::GetFirtVisualSegment
void * GetFirtVisualSegment() const
Definition: dgCollisionDeformableMesh.cpp:871
dgCollisionDeformableMesh::~dgCollisionDeformableMesh
virtual ~dgCollisionDeformableMesh(void)
Definition: dgCollisionDeformableMesh.cpp:409
dgCollisionDeformableMesh::SanityCheck
bool SanityCheck() const
Definition: dgCollisionDeformableMesh.cpp:686
dgCollisionConvex
Definition: dgCollisionConvex.h:42
dgCollisionDeformableMesh::BuildTopDown
dgDeformableNode * BuildTopDown(dgInt32 count, dgDeformableNode *const children, dgDeformableNode *const parent)
Definition: dgCollisionDeformableMesh.cpp:455
dgCollisionDeformableMesh::CalcAABB
virtual void CalcAABB(const dgMatrix &matrix, dgVector &p0, dgVector &p1) const
Definition: dgCollisionDeformableMesh.cpp:944
dgCollisionDeformableMesh::DebugCollision
virtual void DebugCollision(const dgMatrix &matrixPtr, dgCollision::OnDebugCollisionMeshCallback callback, void *const userData) const
Definition: dgCollisionDeformableMesh.cpp:969
dgCollisionDeformableMesh::m_faceNormals
dgVector * m_faceNormals
Definition: dgCollisionDeformableMesh.h:140
dgCollisionDeformableMesh::ApplyExternalForces
virtual void ApplyExternalForces(dgFloat32 timestep)=0
timestep
dgFloat32 timestep
Definition: dgBallConstraint.h:34
dgCollision.h
dgCollisionDeformableMesh::dgMeshSegment::~dgMeshSegment
~dgMeshSegment()
Definition: dgCollisionDeformableMesh.h:67
dgCollisionDeformableMesh::m_world
dgWorld * m_world
Definition: dgCollisionDeformableMesh.h:137
dgCollisionDeformableMesh::m_visualVertexCount
dgInt32 m_visualVertexCount
Definition: dgCollisionDeformableMesh.h:135
dgCollisionDeformableMesh::m_rootNode
dgDeformableNode * m_rootNode
Definition: dgCollisionDeformableMesh.h:141
dgMatrix
Definition: dgMatrix.h:40
dgCollisionDeformableMesh::ImproveNodeFitness
void ImproveNodeFitness(dgDeformableNode *const node)
Definition: dgCollisionDeformableMesh.cpp:545
dgDeformableContact
Definition: dgDeformableContact.h:30
dgCollisionDeformableMesh::GetSegmentIndexCount
dgInt32 GetSegmentIndexCount(void *const segment) const
Definition: dgCollisionDeformableMesh.cpp:888
dgCollisionDeformableMesh::dgCollisionDeformableMesh
dgCollisionDeformableMesh(const dgCollisionDeformableMesh &source)
Definition: dgCollisionDeformableMesh.cpp:182
dgCollisionDeformableMesh::GetParticlePosition
dgVector GetParticlePosition(dgInt32 index) const
Definition: dgCollisionDeformableMesh.cpp:939
dgCollisionDeformableMesh::GetNextVisualSegment
void * GetNextVisualSegment(void *const segment) const
Definition: dgCollisionDeformableMesh.cpp:876
dgWorld
Definition: dgWorld.h:129
dgCollisionDeformableMesh::GetParticleCount
dgInt32 GetParticleCount() const
Definition: dgCollisionDeformableMesh.cpp:934
dgCollisionDeformableMesh::dgMeshSegment
Definition: dgCollisionDeformableMesh.h:61
dgCollisionDeformableMesh::dgDeformableNode
Definition: dgCollisionDeformableMesh.cpp:87
dgCollisionDeformableMesh::m_indexList
dgInt32 * m_indexList
Definition: dgCollisionDeformableMesh.h:139
dgCollisionDeformableMesh::m_basePosit
dgVector m_basePosit
Definition: dgCollisionDeformableMesh.h:129
dgCollisionDeformableMesh::dgParticle::m_unitMass
dgFloat32 * m_unitMass
Definition: dgCollisionDeformableMesh.h:49
dgCollisionDeformableMesh::dgMeshSegment::m_indexCount
dgInt32 m_indexCount
Definition: dgCollisionDeformableMesh.h:75
dgCollisionDeformableMesh::dgParticle::m_count
dgInt32 m_count
Definition: dgCollisionDeformableMesh.h:50
dgCollisionDeformableMesh::m_trianglesCount
dgInt32 m_trianglesCount
Definition: dgCollisionDeformableMesh.h:134
dgCollisionID
dgCollisionID
Definition: dgCollision.h:52
dgCollisionConvex.h
dgCollisionDeformableMesh::dgParticle::m_veloc
dgVector * m_veloc
Definition: dgCollisionDeformableMesh.h:48
dgCollisionParamProxy
Definition: dgContact.h:93
dgCollisionDeformableMesh::ResolvePositionsConstraints
virtual void ResolvePositionsConstraints(dgFloat32 timestep)=0
dgCollisionDeformableMesh::CalculateMassProperties
dgFloat32 CalculateMassProperties(const dgMatrix &offset, dgVector &inertia, dgVector &crossInertia, dgVector &centerOfMass) const
Definition: dgCollisionDeformableMesh.cpp:953