Game Development Reference
In-Depth Information
float d;
float InitialLength;
} Spring, *pSpring;
The new EndPoint structure is as follows:
typedef struct _EndPointRef {
int ref;
Vector pt;
} EndPoint;
Here, ref is the index referring to the Object to which the spring is attached, and pt is
the point in the attached Object 's local coordinate system to which the spring is attached.
Notice from Figure 13-4 that the first spring, the topmost one, is connected to a single
object; the other end of it is connected to a fixed point in space. We'll use a ref of −1 to
indicate that a spring's endpoint is connected to a fixed point in space instead of an
As in the rope example, we have a few important define s and variables to set up:
#define _NUM_OBJECTS 10
#define _NUM_SPRINGS 10
#define _SPRING_K 1000
#define _SPRING_D 100
RigidBody2D Objects[_NUM_OBJECTS];
Spring Springs[_NUM_SPRINGS];
These are the same as before except now we have 10 springs instead of 9, and Objects
is of type RigidBody2D instead of Particle .
The damping and spring constants play the same role here as they did in the rope
Initially our linked chain is set up horizontally, just like the rope example, but with the
link and spring indices shown in Figure 13-5 . Each rectangle represents a rigid link, and
a spring attached to the left end of each link connects the link to its neighbor to the left.
In the case of the first link, L0 , the spring connects the left end of the link to a fixed point
in space.
Search Nedrilad ::

Custom Search