adjust velocity after solving PBD springs/links
This commit is contained in:
@@ -23,8 +23,8 @@ extern bool gReset;
|
|||||||
float clothWidth = 4;
|
float clothWidth = 4;
|
||||||
float clothHeight= 4;
|
float clothHeight= 4;
|
||||||
|
|
||||||
int width = 32;//64;
|
int width = 64;
|
||||||
int height = 32;//64;
|
int height = 64;
|
||||||
|
|
||||||
int numPoints = width*height;
|
int numPoints = width*height;
|
||||||
float clothMass = 100.f;
|
float clothMass = 100.f;
|
||||||
@@ -153,7 +153,7 @@ void CpuSoftClothDemo::clientMoveAndDisplay()
|
|||||||
if (m_data->m_clothShapeIndex>=0 && m_data->m_clothVertices)
|
if (m_data->m_clothShapeIndex>=0 && m_data->m_clothVertices)
|
||||||
{
|
{
|
||||||
|
|
||||||
float deltaTime = 1./1000.;//1./60.f;
|
float deltaTime = 1./100.;//1./60.f;
|
||||||
//float deltaTime = 1./60.f;
|
//float deltaTime = 1./60.f;
|
||||||
|
|
||||||
//write positions
|
//write positions
|
||||||
@@ -266,9 +266,6 @@ void CpuSoftClothDemo::setupScene(const ConstructionInfo& ci)
|
|||||||
{
|
{
|
||||||
for(int x = 0; x < width; x++)
|
for(int x = 0; x < width; x++)
|
||||||
{
|
{
|
||||||
double coord = b3Sin(x/5.0)*0.01+1;
|
|
||||||
//coord = sin(y/);
|
|
||||||
|
|
||||||
float posX = (x/((float)(width-1)))*(clothWidth);
|
float posX = (x/((float)(width-1)))*(clothWidth);
|
||||||
float posZ = ((y-height/2.f)/((float)(height-1)))*(clothHeight);
|
float posZ = ((y-height/2.f)/((float)(height-1)))*(clothHeight);
|
||||||
|
|
||||||
|
|||||||
@@ -6,15 +6,22 @@
|
|||||||
void PositionBasedDynamics::solveLinks(struct CpuSoftClothDemoInternalData* clothData, char* vertexPositions, int vertexStride,float dt)
|
void PositionBasedDynamics::solveLinks(struct CpuSoftClothDemoInternalData* clothData, char* vertexPositions, int vertexStride,float dt)
|
||||||
{
|
{
|
||||||
float kst = 1.f;
|
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++)
|
for(int i=0; i<clothData->m_springs.size();i++)
|
||||||
{
|
{
|
||||||
|
|
||||||
ClothSpring& link=clothData->m_springs[i];
|
ClothSpring& link=clothData->m_springs[i];
|
||||||
|
//if(l.m_c0>0)//avoid links between two particles with mass==0
|
||||||
//if(l.m_c0>0)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
float invMassA = clothData->m_particleMasses[link.m_particleIndexA]? 1.f/clothData->m_particleMasses[link.m_particleIndexA] : 0.f;
|
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)
|
void PositionBasedDynamics::solveConstraints(struct CpuSoftClothDemoInternalData* clothData, char* vtx, int vertexStride,float dt)
|
||||||
|
|||||||
Reference in New Issue
Block a user