If I have an object at point p1 rotated on the z axis, and another point p2 with the direction between p1 and p2 described by a vection v1 (where x and y are valued - this is two dimensional), how can I find the difference between the rotation?

Sorry, these quaternions are driving me nuts. I’m trying to translate mouse clicks to a Quad and have a ship on the quad turn towards the click coordinates:

`pre type="java"`

Vector3f clickLocation = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0);

Vector3f direction = cam.getWorldCoordinates(inputManager.getCursorPosition(), 1);

direction.subtractLocal(clickLocation).normalizeLocal();

Ray ray = new Ray(clickLocation, direction);

CollisionResults results = new CollisionResults();

backdropGeom.collideWith(ray, results);

for(int i = 0; i < results.size(); i++)

{

loc = results.getCollision(i).getContactPoint();

Vector3f direction2 = loc.subtractLocal(vehicle.getPhysicsLocation()).normalizeLocal();

Quaternion heading = vehicle.getPhysicsRotation();

// I’m stuck here :(

}`/pre`

Quaternions for Spatials are relative rotations from the y-up z-forward rotation, maybe that helps you.

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:math_for_dummies

normen said:

Quaternions for Spatials are relative rotations from the y-up z-forward rotation, maybe that helps you.

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:math_for_dummies

So first, my axes are twisted around, right?

If the game is top-down perspective, that is, looking down the Z axis onto the X-Y axes, then that's one problem because of the way the quaternions are calculated. So I'll have to take the mouse click coordinates and switch them around as well as rotate my objects differently and the camera. Because when I use Quaternion.clone().lookAt() nothing makes sense no matter which axis I pass as the up vector.

Well, if you use lookAt, you have to specify the up-Vector (y=up) of the spatial you want to rotate and the target directon (z=towards you) you want to have e.g.

[java]

//get some target vector (z/forward direction)

Vector3f target = getTargetDirection();

Vector3f up = new Vector3f(0,1,0);

//rotate z-up vector by the current rotation;

spatial.getLocalRotation().multLocal(up);

Quaternion newRotation = spatial.getLocalRotation().lookAt(target, up);

spatial.setLocalRotation(newRotation);

[/java]

Also note that spatial.lookAt() and quaternion.lookAt() do different things. The other questions are answered in the presentation.

Quaternion.lookAt(target, up) doesn’t return anything.

Yeah, sorry, I was writing off the top of my head.

[java]

Quaternion newRotation = spatial.getLocalRotation().clone();

newRotation.lookAt(target, up);

[/java]

Hey, thanks for your help. I have to study the math more.