add options to perturb the softbody patch's initial position

This commit is contained in:
Xuchen Han 2019-08-12 12:07:24 -07:00
parent cfbd6c512a
commit 9e6e571732
2 changed files with 11 additions and 3 deletions

View File

@ -724,7 +724,8 @@ btSoftBody* btSoftBodyHelpers::CreatePatch(btSoftBodyWorldInfo& worldInfo, const
int resx,
int resy,
int fixeds,
bool gendiags)
bool gendiags,
btScalar perturbation)
{
#define IDX(_x_, _y_) ((_y_)*rx + (_x_))
/* Create nodes */
@ -744,7 +745,13 @@ btSoftBody* btSoftBodyHelpers::CreatePatch(btSoftBodyWorldInfo& worldInfo, const
for (int ix = 0; ix < rx; ++ix)
{
const btScalar tx = ix / (btScalar)(rx - 1);
x[IDX(ix, iy)] = lerp(py0, py1, tx);
btScalar pert = perturbation * btScalar(rand())/RAND_MAX;
btVector4 temp1 = py1;
temp1.setY(py1.getY() + pert);
btVector4 temp = py0;
pert = perturbation * btScalar(rand())/RAND_MAX;
temp.setY(py0.getY() + pert);
x[IDX(ix, iy)] = lerp(temp, temp1, tx);
m[IDX(ix, iy)] = 1;
}
}

View File

@ -92,7 +92,8 @@ struct btSoftBodyHelpers
int resx,
int resy,
int fixeds,
bool gendiags);
bool gendiags,
btScalar perturbation = 0.);
/* Create a patch with UV Texture Coordinates */
static btSoftBody* CreatePatchUV(btSoftBodyWorldInfo& worldInfo,
const btVector3& corner00,