void ClothSystem::initStructuralSprings() { float springConst = 200.0; float restLength = 1.0 * CLOTH_DETAIL; for (int i = 0; i < CLOTH_HEIGHT; ++i) { for (int k = 0; k < CLOTH_WIDTH; ++k) { int ind = indexOf(i, k); int up = indexOf(i-1, k); int down = indexOf(i+1, k); int left = indexOf(i, k-1); int right = indexOf(i, k+1); if (i != 0) { setSpring(ind, up, springConst, restLength); } if (i != CLOTH_HEIGHT - 1) { setSpring(ind, down, springConst, restLength); } if (k != 0) { setSpring(ind, left, springConst, restLength); } if (k != CLOTH_WIDTH - 1) { setSpring(ind, right, springConst, restLength); } } } }
void ClothSystem::initShearSprings() { float springConst = 200.0; float restLength = sqrt(2) * CLOTH_DETAIL; for (int i = 0; i < CLOTH_HEIGHT; ++i) { for (int k = 0; k < CLOTH_WIDTH; ++k) { int ind = indexOf(i, k); int upLeft = indexOf(i-1, k-1); int downRight = indexOf(i+1, k+1); int downLeft = indexOf(i+1, k-1); int upRight = indexOf(i-1, k+1); if ( i != 0 && k != CLOTH_WIDTH - 1 ) { setSpring(ind, upRight, springConst, restLength); } if ( i != 0 && k != 0) { setSpring(ind, upLeft, springConst, restLength); } if ( i != CLOTH_HEIGHT - 1 && k != 0 ) { setSpring(ind, downLeft, springConst, restLength); } if (i != CLOTH_HEIGHT - 1 && k != CLOTH_WIDTH - 1) { setSpring(ind, downRight, springConst, restLength); } } } }
void ClothSystem::initFlexSprings() { float springConst = 200.0; float restLength = 2.0 * CLOTH_DETAIL; for (int i = 0; i < CLOTH_HEIGHT; ++i) { for (int k = 0; k < CLOTH_WIDTH; ++k) { int ind = indexOf(i, k); int up = indexOf(i-2, k); int down = indexOf(i+2, k); int left = indexOf(i, k-2); int right = indexOf(i, k+2); if (i > 1) { setSpring(ind, up, springConst, restLength); } if (i < 6) { setSpring(ind, down, springConst, restLength); } if (k > 1) { setSpring(ind, left, springConst, restLength); } if (k < 6) { setSpring(ind, right, springConst, restLength); } } } }
bool GSpringDamperJoint::setSpring(RMatrix K_) { if ( K_.RowSize() * K_.ColSize() != pJoint->getDOF() ) return false; return setSpring(K_.GetPtr()); }