adjust velocity after solving PBD springs/links
This commit is contained in:
@@ -6,15 +6,22 @@
|
||||
void PositionBasedDynamics::solveLinks(struct CpuSoftClothDemoInternalData* clothData, char* vertexPositions, int vertexStride,float dt)
|
||||
{
|
||||
float kst = 1.f;
|
||||
float kLST = 1.f;
|
||||
float kLST = 1.f;//0.8f;
|
||||
float damping = 0.999;
|
||||
int numPoints = clothData->m_particleMasses.size();
|
||||
|
||||
b3AlignedObjectArray<b3Vector3> startPositions;
|
||||
|
||||
startPositions.resize(numPoints);
|
||||
for (int i=0;i<numPoints;i++)
|
||||
{
|
||||
startPositions[i] = (b3Vector3&)vertexPositions[i*vertexStride];
|
||||
}
|
||||
|
||||
for(int i=0; i<clothData->m_springs.size();i++)
|
||||
{
|
||||
|
||||
ClothSpring& link=clothData->m_springs[i];
|
||||
|
||||
//if(l.m_c0>0)
|
||||
//if(l.m_c0>0)//avoid links between two particles with mass==0
|
||||
{
|
||||
|
||||
float invMassA = clothData->m_particleMasses[link.m_particleIndexA]? 1.f/clothData->m_particleMasses[link.m_particleIndexA] : 0.f;
|
||||
@@ -37,6 +44,17 @@ void PositionBasedDynamics::solveLinks(struct CpuSoftClothDemoInternalData* clot
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//adjust velocity
|
||||
for (int i=0;i<numPoints;i++)
|
||||
{
|
||||
b3Vector3 endPosition = (b3Vector3&)vertexPositions[i*vertexStride];
|
||||
b3Vector3 diff = endPosition-startPositions[i];
|
||||
|
||||
clothData->m_velocities[i]+=(diff/dt);
|
||||
clothData->m_velocities[i]*=damping;
|
||||
}
|
||||
}
|
||||
|
||||
void PositionBasedDynamics::solveConstraints(struct CpuSoftClothDemoInternalData* clothData, char* vtx, int vertexStride,float dt)
|
||||
|
||||
Reference in New Issue
Block a user