2
Bullet Continuous Collision Detection and Physics Library
3
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
5
This software is provided 'as-is', without any express or implied warranty.
6
In no event will the authors be held liable for any damages arising from the use of this software.
7
Permission is granted to anyone to use this software for any purpose,
8
including commercial applications, and to alter it and redistribute it freely,
9
subject to the following restrictions:
11
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13
3. This notice may not be removed or altered from any source distribution.
16
#ifndef BT_ACCELERATED_SOFT_BODY_CPU_SOLVER_H
17
#define BT_ACCELERATED_SOFT_BODY_CPU_SOLVER_H
19
#include "vectormath/vmInclude.h"
20
#include "BulletSoftBody/btSoftBodySolvers.h"
21
#include "BulletSoftBody/btSoftBodySolverVertexBuffer.h"
22
#include "BulletMultiThreaded/GpuSoftBodySolvers/CPU/btSoftBodySolverData.h"
24
struct btCPUCollisionShapeDescription
26
int softBodyIdentifier;
27
int collisionShapeType;
28
Vectormath::Aos::Transform3 shapeTransform;
45
Vectormath::Aos::Vector3 linearVelocity;
46
Vectormath::Aos::Vector3 angularVelocity;
48
btCPUCollisionShapeDescription()
50
collisionShapeType = 0;
56
class btCPUSoftBodySolver : public btSoftBodySolver
60
* Entry in the collision shape array.
61
* Specifies the shape type, the transform matrix and the necessary details of the collisionShape.
65
// Public because output classes need it. This is a better encapsulation to break in the short term
66
// Than having the solvers themselves need dependencies on DX, CL etc unnecessarily
69
struct CollisionObjectIndices
71
CollisionObjectIndices( int f, int e )
82
* SoftBody class to maintain information about a soft body instance
84
* This data addresses the main solver arrays.
86
class btAcceleratedSoftBodyInterface
89
/** Current number of vertices that are part of this cloth */
91
/** Maximum number of vertices allocated to be part of this cloth */
93
/** Current number of triangles that are part of this cloth */
95
/** Maximum number of triangles allocated to be part of this cloth */
97
/** Index of first vertex in the world allocated to this cloth */
99
/** Index of first triangle in the world allocated to this cloth */
101
/** Index of first link in the world allocated to this cloth */
103
/** Maximum number of links allocated to this cloth */
105
/** Current number of links allocated to this cloth */
108
/** The actual soft body this data represents */
109
btSoftBody *m_softBody;
113
btAcceleratedSoftBodyInterface( btSoftBody *softBody ) :
114
m_softBody( softBody )
126
int getNumVertices() const
128
return m_numVertices;
131
int getNumTriangles() const
133
return m_numTriangles;
136
int getMaxVertices() const
138
return m_maxVertices;
141
int getMaxTriangles() const
143
return m_maxTriangles;
146
int getFirstVertex() const
148
return m_firstVertex;
151
int getFirstTriangle() const
153
return m_firstTriangle;
157
* Update the bounds in the btSoftBody object
159
void updateBounds( const btVector3 &lowerBound, const btVector3 &upperBound );
161
// TODO: All of these set functions will have to do checks and
162
// update the world because restructuring of the arrays will be necessary
163
// Reasonable use of "friend"?
164
void setNumVertices( int numVertices )
166
m_numVertices = numVertices;
169
void setNumTriangles( int numTriangles )
171
m_numTriangles = numTriangles;
174
void setMaxVertices( int maxVertices )
176
m_maxVertices = maxVertices;
179
void setMaxTriangles( int maxTriangles )
181
m_maxTriangles = maxTriangles;
184
void setFirstVertex( int firstVertex )
186
m_firstVertex = firstVertex;
189
void setFirstTriangle( int firstTriangle )
191
m_firstTriangle = firstTriangle;
194
void setMaxLinks( int maxLinks )
196
m_maxLinks = maxLinks;
199
void setNumLinks( int numLinks )
201
m_numLinks = numLinks;
204
void setFirstLink( int firstLink )
206
m_firstLink = firstLink;
209
int getMaxLinks() const
214
int getNumLinks() const
219
int getFirstLink() const
224
btSoftBody* getSoftBody()
229
const btSoftBody* const getSoftBody() const
235
btSoftBodyLinkData m_linkData;
236
btSoftBodyVertexData m_vertexData;
237
btSoftBodyTriangleData m_triangleData;
244
/** Variable to define whether we need to update solver constants on the next iteration */
245
bool m_updateSolverConstants;
248
* Cloths owned by this solver.
249
* Only our cloths are in this array.
251
btAlignedObjectArray< btAcceleratedSoftBodyInterface * > m_softBodySet;
253
/** Acceleration value to be applied to all non-static vertices in the solver.
254
* Index n is cloth n, array sized by number of cloths in the world not the solver.
256
btAlignedObjectArray< Vectormath::Aos::Vector3 > m_perClothAcceleration;
258
/** Wind velocity to be applied normal to all non-static vertices in the solver.
259
* Index n is cloth n, array sized by number of cloths in the world not the solver.
261
btAlignedObjectArray< Vectormath::Aos::Vector3 > m_perClothWindVelocity;
263
/** Velocity damping factor */
264
btAlignedObjectArray< float > m_perClothDampingFactor;
266
/** Velocity correction coefficient */
267
btAlignedObjectArray< float > m_perClothVelocityCorrectionCoefficient;
269
/** Lift parameter for wind effect on cloth. */
270
btAlignedObjectArray< float > m_perClothLiftFactor;
272
/** Drag parameter for wind effect on cloth. */
273
btAlignedObjectArray< float > m_perClothDragFactor;
275
/** Density of the medium in which each cloth sits */
276
btAlignedObjectArray< float > m_perClothMediumDensity;
279
* Collision shape details: pair of index of first collision shape for the cloth and number of collision objects.
281
btAlignedObjectArray< CollisionObjectIndices > m_perClothCollisionObjects;
284
* Collision shapes being passed across to the cloths in this solver.
286
btAlignedObjectArray< btCPUCollisionShapeDescription > m_collisionObjectDetails;
289
void prepareCollisionConstraints();
291
Vectormath::Aos::Vector3 ProjectOnAxis( const Vectormath::Aos::Vector3 &v, const Vectormath::Aos::Vector3 &a );
293
void ApplyClampedForce( float solverdt, const Vectormath::Aos::Vector3 &force, const Vectormath::Aos::Vector3 &vertexVelocity, float inverseMass, Vectormath::Aos::Vector3 &vertexForce );
295
float computeTriangleArea(
296
const Vectormath::Aos::Point3 &vertex0,
297
const Vectormath::Aos::Point3 &vertex1,
298
const Vectormath::Aos::Point3 &vertex2 );
300
void applyForces( float solverdt );
301
void integrate( float solverdt );
302
void updateConstants( float timeStep );
303
int findSoftBodyIndex( const btSoftBody* const softBody );
305
/** Update the bounds of the soft body objects in the solver */
310
btCPUSoftBodySolver();
312
virtual ~btCPUSoftBodySolver();
315
virtual SolverTypes getSolverType() const
321
virtual btSoftBodyLinkData &getLinkData();
323
virtual btSoftBodyVertexData &getVertexData();
325
virtual btSoftBodyTriangleData &getTriangleData();
329
btAcceleratedSoftBodyInterface *findSoftBodyInterface( const btSoftBody* const softBody );
330
const btAcceleratedSoftBodyInterface * const findSoftBodyInterface( const btSoftBody* const softBody ) const;
334
virtual bool checkInitialized();
336
virtual void updateSoftBodies( );
338
virtual void optimize( btAlignedObjectArray< btSoftBody * > &softBodies , bool forceUpdate=false);
340
virtual void copyBackToSoftBodies();
342
virtual void solveConstraints( float solverdt );
344
virtual void predictMotion( float solverdt );
346
virtual void processCollision( btSoftBody *, btCollisionObject* );
348
virtual void processCollision( btSoftBody*, btSoftBody *);
354
* Class to manage movement of data from a solver to a given target.
355
* This version is the CPU to CPU generic version.
357
class btSoftBodySolverOutputCPUtoCPU : public btSoftBodySolverOutput
362
btSoftBodySolverOutputCPUtoCPU()
366
/** Output current computed vertex data to the vertex buffers for all cloths in the solver. */
367
virtual void copySoftBodyToVertexBuffer( const btSoftBody * const softBody, btVertexBufferDescriptor *vertexBuffer );
370
#endif // #ifndef BT_ACCELERATED_SOFT_BODY_CPU_SOLVER_H
b'\\ No newline at end of file'