arminia
November 30, 2010, 7:21pm
1
My idea is to simulate the move between 2 coordinates.
Here is a part of codes:
[java]/* calculate the angles */
public void angleXZBetweenDots(Vector3f start, Vector3f target) {
Vector2f start2D = new Vector2f(0f, 0f);
Vector2f targetXZ = new Vector2f(target.getX() - start.getX(),start.getZ() - target.getZ());
angleXZ = start2D.normalize().angleBetween(targetXZ.normalize());
Vector2f targetXY = new Vector2f(target.getX() - start.getX(),target.getY() - start.getY());
angleXY = start2D.normalize().angleBetween(targetXY.normalize());
pivot.rotate(0, angleXY, angleXZ);
}
public void update(float tpf) {
float x = FastMath.cos(angleXZ) * tpf * 1.5f;
float y = (x / FastMath.cos(angleXZ)) * FastMath.tan(angleXY); // incorrect, I think
float z = FastMath.sin(angleXZ) * tpf * 1.5f;
pivot.setLocalTranslation(pivot.getLocalTranslation().add(x, y, -z));
}[/java]
But I have 2 problems now:

the rotation is incorrect with [java]pivot.rotate(0, angleXY, angleXZ);[/java].
the movement is not synchronal. The movement on Y-axis is faster than the movements on X- and Z-axes.
Can someone help, please?

nehon
November 30, 2010, 7:33pm
2
I don’t get it, why the rotation?
why not just linearly interpolate between the 2 coords?
There is a convenience FastMath.interpolateLinear method to do so.

normen
November 30, 2010, 8:14pm
3
Yeah, the calculations you do are really funny
If there was not the convenience method Nehon suggested, simply subtracting Vector A from Vector B will give you the vector “in between” the two. Then you can simply multiply that vector by 0…1 and add it to Vector A. This would give you all points on A-B.

First, thx for your answer.
But I am new with JME3 and cant understand completely what you said. Can you please explain more in detail?
What I need is: first of all, rotate to the direction of the target, then move slowly to the target. (2 coordinates of start and target are known.)
thx again.

PS:
it would be best with an example.

something like
[java]Vector3f from; // already known
Vector3f to; // already known
Vector3f travel = to.substract(from);
Vector3f step = travel.mult(1/10); // 10 steps
Vector3f = new location(from);
for(int i=0; i<10; i++){
// travel from a to b in 10 steps
location.add(step);
}
[/java]Doing this from memory so don’t be too harsh
(edit: I think you can also let physics do the moving for you)

This can solve the movement-problem.
How about the rotation?

Kaizo
December 1, 2010, 5:00pm
8
Maybe you can use the lookAt function of the node to rotate it into the right direction. ( message me in icq)

What rotation? You already have your movement vectors. thats where you need to go. Just point your nose there.

arminia
December 1, 2010, 8:47pm
10
[java]Spatial bullet;
ParticleEmitter smoketrail;
smoketrail.setInWorldSpace(false);
Node pivot = new Node(“pivot”);
rootNode.attachChild(pivot);
pivot.attachChild(bullet);
pivot.attachChild(smoketrail);
pivot.setLocalTranslation(start);
pivot.lookAt(target,Vector3f.UNIT_Y);[/java]
I want to turn the bullet with smoketrail behind towards target.
With “pivot.lookAt(target,Vector3f.UNIT_Y)” I can only turn the bullet to the target, but the smoketrail doesn’t turn with the bullet together.
Do you know why?

nehon
December 1, 2010, 9:27pm
11
That makes more sense, you should have begin with that.
try to attach the bullet and the emitter to a node. use the lookat on the node, and interpolate the position of the node, this should work with almost no math

arminia
December 1, 2010, 10:14pm
12
You mean FastMath.interpolateLinear(scale, startValue, endValue)?
What’s the Vector3f als return? What does “scale” mean?
Can you explain it in detail? Thank you!

normen
December 1, 2010, 11:15pm
13
Its what I have explained. Scale is 0…1 for the single points on the way from a to b.

arminia
December 2, 2010, 1:08pm
14
Yep, thank you all for the help! Now the movement problem is solved.
Can you help me more with the rotation?
Like I said before:
With “pivot.lookAt(target,Vector3f.UNIT_Y)” I can only turn the bullet to the target, but the smoketrail doesn’t turn with the bullet together.

arminia
December 8, 2010, 1:14pm
15
Can anyone help me more with the rotation?