Game Development Reference
In-Depth Information
j = Springs[i].End1.ref;
if(j != −1)
Objects[j].vSprings += F;
j = Springs[i].End2.ref;
if(j != −1)
Objects[j].vSprings −= F;
// convert force to first ref local coords
// Get local lever
// calc moment
// Compute and aggregate moments due to spring force
// on each connected object.
j = Springs[i].End1.ref;
if(j != −1)
{
Fo = VRotate2D(-Objects[j].fOrientation, F);
r = Springs[i].End1.pt;
M = r^Fo;
Objects[j].vMSprings += M;
}
j = Springs[i].End2.ref;
if(j!= −1)
{
Fo = VRotate2D(-Objects[j].fOrientation, F);
r = Springs[i].End2.pt;
M = r^Fo;
Objects[j].vMSprings −= M;
}
}
.
.
.
// Integrate equations of motion as usual.
.
.
.
// Render the scene as usual.
.
.
.
}
As in the rope example, UpdateSimulation steps through all the Springs , computing
their stretched or compressed length, the relative velocity of each spring's endpoints,
and the resulting spring forces. These calculations are a bit different in this current
example because we have to handle rotation, as explained earlier.
Search Nedrilad ::




Custom Search