I am trying to learn jMonkeyEngine, and I have now learned to move my cube geometry with the move() method.
[java]
public void simpleUpdate(float tpf) {
//geom is an object variable storing my cube, and cubeSpeed is storing a constant speed value for the cube movement
geom.move( tpf * cubeSpeed, 0.0f, 0.0f );
}
[/java]
However, this approach make the cube move along the x azis infinite. My question is then this.
How can i make use of linear interpolation, to make the cube move between 1 vector3f location (start position), to another vector3f location (end position), and then stop at the end position??
I have tried to use FastMath.interpolateLinear( scale, startVector3, endVector3 ), but I can’t get the box, to move, when I insert this into the move() method… So how can I make my cube move from start position to end position, and then stop at the end position??
move() is relative. If you want linear interpolation then you should abandon move since you no longer want to be moving relative, you want to be moving some interpolation between two points.
@pspeed said:
move() is relative. If you want linear interpolation then you should abandon move since you no longer want to be moving relative, you want to be moving some interpolation between two points.
I am not sure what you mean, how can I then do it, can you provide an example of some simple code? I have also tried searching for it on the internet, but i can't find any examples using JME 3.
@martin-rohwedder said:
I am not sure what you mean, how can I then do it, can you provide an example of some simple code? I have also tried searching for it on the internet, but i can't find any examples using JME 3.
Though how can I make it move for a constant speed for each WU it comes across?? now when I increase the distance between startPos and endPos, my cube just goes there faster. How can I make the cube go to the end position at the same speed as it would when the end position was closer??
Calculate the distance between the start and end using
[java]
float distance = startPos.distance(endPos);
[/java]
and factor that into your interp progress like so:
[java]
interp += (mySpeed/distance) * tpf;
[/java]
@sgold said:
Calculate the distance between the start and end using
[java]
float distance = startPos.distance(endPos);
[/java]
and factor that into your interp progress like so:
[java]
interp += (mySpeed/distance) * tpf;
[/java]