-
Notifications
You must be signed in to change notification settings - Fork 4
Align to spline [constraint]
Align to spline constraints gives you easily the possibility to align a Transitionable object along a spline.
First, you have to instantiate a Spline.
Spline someSplinePath = new SplineBezier();
someSplinePath.addPoint(new Vector3f(0.0f, 1.0f, 0.0f));
someSplinePath.addPoint(new Vector3f(10.0f, 10.0f, 0.0f));
someSplinePath.addPoint(new Vector3f(20.0f, 0.0f, 0.0f));
Now get your scenery object (com.nolimitsframework.scenery.SceneryObject and com.nolimitsframework.animation.Animation)
SceneryObject Cube = new SceneryObject("Cube");
Every class (for example SceneryObject) which inherits com.nolimitsframework.transition.Transition provides the attachConstraint(Constraint) method.
Create an align to spline constraint (com.nolimitsframework.constraints.AlignToSpline). The constructor AlignToSpline(Spline, Tangential) description:
- Spline: This might be self explaining.
- Tangential: Align tangential along the spline
So just call
AlignToSpline alignToSomeSplinePath = new AlignToSpline(someSplinePath, true);
Now you can call
Cube.attachConstraint(alignToSomeSplinePath);
Now your Cube is aligned to the someSplinePath. The interesting part is, you can animate your cube to run along the spline. If you didn´t read the article about animations, just visit the basics of animations.
Animation AlignToSplineAnimation = Animation.createFromObject(alignToSomeSplinePath);
AlignToSplineAnimation.addAnimation(AlignToSpline.PROPERTY_POSITION_ABSOLUTE_POSITION, 10.0f, 0.0f, 5.0f, Easing.ELASTIC_IN_OUT);
This will give you an animation for your spline to move along the spline until the 10th meter is reached in 5 seconds.