Game Development Reference
In-Depth Information
.
Vector M;
Vector Fo;
// Initialize the spring forces and moments on each object to zero.
for(i=0; i<_NUM_OBJECTS; i++)
{
.
.
.
Objects[i].vMSprings.x = 0;
Objects[i].vMSprings.y = 0;
Objects[i].vMSprings.z = 0;
}
// Calculate all spring forces based on positions of connected objects
for(i=0; i<_NUM_SPRINGS; i++)
{
if(Springs[i].End1.ref == −1)
{
pt1 = Springs[i].End1.pt;
v1.x = v1.y = v1.z = 0; // point is not moving
} else {
j = Springs[i].End1.ref;
pt1 = Objects[j].vPosition + VRotate2D(Objects[j].fOrientation,
Springs[i].End1.pt);
v1 = Objects[j].vVelocity + VRotate2D(Objects[j].fOrientation,
Objects[j].vAngularVelocity^Springs[i].End1.pt);
}
if(Springs[i].End2.ref == −1)
{
pt2 = Springs[i].End2.pt;
v2.x = v2.y = v2.z = 0;
} else {
j = Springs[i].End2.ref;
pt2 = Objects[j].vPosition + VRotate2D(Objects[j].fOrientation,
Springs[i].End2.pt);
v2 = Objects[j].vVelocity + VRotate2D(Objects[j].fOrientation,
Objects[j].vAngularVelocity^Springs[i].End2.pt);
}
// Compute spring-damper force.
vr = v2 - v1;
r = pt2 - pt1;
dl = r.Magnitude() - Springs[i].InitialLength;
f = Springs[i].k * dl;
r.Normalize();
F = (r*f) + (Springs[i].d*(vr*r))*r;
// Aggregate the spring force on each connected object
Search Nedrilad ::




Custom Search