The topic is in the title. It’d be very useful for such things as making planets travel on an orbit without the fuss of physics. Setting CurveTension to 1 makes an almost-circular path, but it’s not what I’m after.
Any tips before I go code an orbital PathInterpolation?
Hang on, maybe I should just approximate what I’m after with more waypoints. Sorry, guys.
in TestCameraMotionPath i achieved a circular path with 4 waypoints and a tension of about 0.8.
You should check the testcase
Thanks for that! Some easy math and using 20 waypoints per orbit I’m getting near perfect ellipses
cool!
May I ask you if you could post the code? it could be a useful snippet.
thanks
Not sure how snippets work, but here goes:
pre type="java"
[java]// This snippet of code takes an x value (X) and an eccentricity value (E), and produces an elliptical path around the origin. It should be straight-forward to adapt to other uses.
float x = (float) X;
// Do calculation from http://www.1728.com/ellipse.htm
float y = (float) (X * Math.sqrt(1 - Math.pow(E, 2)));
// Find one of the ellipses foci, to orbit around.
float foci = (float) Math.sqrt(Math.pow((x/2), 2) - Math.pow((y/2), 2));
final float numberOfWaypoints = 20;
MotionPath path = new MotionPath();
for (int i = 0; i < numberOfWaypoints; i++) {
path.addWayPoint(new Vector3f((float) (Math.cos((i * 2 * Math.PI)/numberOfWaypoints) * x) + foci, 0, (float) Math.sin(i * (2 * Math.PI)/numberOfWaypoints) * y));
}
path.enableDebugShape(assetManager, rootNode);
// Tension might need a little adjusting depending on how many waypoints you want. I think
// 0.5 is acceptable for 20 waypoints.
path.setCurveTension(0.5f);
path.setCycle(true);[/java]/pre