Spring Classes

Two classes needed: PointMass and Spring

PointMass

Attributes:
Mass
Position
Velocity
Acceleration

Functions:
Clear forces - reset acceleration, at start of frame
Apply force - add its effect to the acceleration, using F=ma
Update - apply current acceleration & velocity

Other features:
Freeze - point will not move on update
Drag - automatically added during update

Code:

Spring

Attributes:
Two PointMasses
Spring constant
Rest length

Functions:
Apply - compute current spring force, and apply it to the two PointMasses

Other features:
Constructor - if no rest length is given, use the current distance between the PointMasses
Draw line - draw an OpenGL line between the two PointMasses

Code:



Examples:



The classes make it easier to build systems of multiple springs




next