Vectors, quaternions and directions

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);


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  :(


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

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

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.


//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;


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



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.


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

newRotation.lookAt(target, up);


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