-
Notifications
You must be signed in to change notification settings - Fork 4
Linear and bezier splines
You might need to use splines in your scripts. NoLimitsFramework provides a couple of spline classes. The spline classes are all extending the base class com.nolimitsframework.spline.Spline.
The base class provides some methods like addPoint(Vector3f point) and getOffsetByLength(float offset). Just check the source codes to see which methods are provided. After writing the series of these wiki articles I am going to write an API documentation.
There is three different splines types:
- Linear spline
- Bezier spline
- Track spline
The linear or bezier spline will be instantiated this way:
Spline someSplinePath = new SplineLinear();
or
Spline someSplinePath = new SplineBezier();
Now you can add some spline vertices:
someSplinePath.addPoint(new Vector3f(0.0f, 1.0f, 0.0f));
someSplinePath.addPoint(new Vector3f(10.0f, 10.0f, 0.0f));
This is pretty easy. Now you can catch a vector point on a given offset:
Vector3f point = someSplinePath.getOffsetByLength(10.0f);
Track spline is useful to generate a spline from a certain track path from your track path in the editor. This might be used for a cable lift.
This spline type is slightly different. com.nolimitsframework.spline.TrackSpline extends a Linear Spline.
But lets move to the important part, the construction of the class.
public TrackSpline(Vector3f startOrigin, float length, bool backward, float division);
Okay. let me explain those arguments.
-
startOrigin: This is a Vector3f value, basically its the position where your spline should begin. For example if you want to catch the spline for lift, just take the coordinates of the first vertex of your lift.
-
length: Length of your spline. You can just set triggers on your no limits editor, double click on it, and read out the offset. If you use two triggers, just take the difference of both offsets, and well, that is your spline length.
-
backward: Generate the spline backward? In most cases false
-
division: Subdivisions. Given in length. For example: add point every 0.1 meters. Can this be called sample rate? I don´t know, but I guess you got me.
Of course you can use methods like
Vector3f point = someSplinePath.getOffsetByLength(10.0f);
for this type of spline.
Further wiki articles will teach you how to use splines powerful.