I have written a method that eases handling of rotation a lot, if people like it it could be put into Quaternion to enable everyone to use it like this:
someSpatial.getLocalRotation().lookAt( destination, up );
the method looks like this:
/**
* <code>lookAt</code> is a convienence method for auto-setting the
* quaternion based on a direction and an up vector. It computes
* the rotation to transform the x-axis to point into 'direction'
* and the y-axis to 'up'.
*
* @param direction
* where to look at in terms of local coordinates
* @param up
* a vector indicating the local up direction.
* (typically {0, 1, 0} in jME.)
*/
public void lookAt(Vector3f direction, Vector3f up ) {
tmpYaxis.set( direction ).normalizeLocal();
tmpZaxis.set( up ).crossLocal( direction ).normalizeLocal();
tmpXaxis.set( direction ).crossLocal( tmpZaxis ).normalizeLocal();
fromAxes( tmpXaxis, tmpYaxis, tmpZaxis );
}
um, well, if I had found it, I could have omitted the testing
but as Mojo said - it can be used in more cases if it's in Quaternion - Spatial.lookAt could simply use the one in Quaternion then
I think it's good too, but maybe it should be named "pointAt"?
Well, a Quaternion cannot "look at" something, it can't "point at" something, either. But I'd keep lookAt as name, as it's named like that in Camera and Spatial and does quite (or exactly) the same.
You seem to be assuming that all games use one direction as the front of a model. One game may need to have the object rotated so the unrotated +x accesses points to the new vector while anther may need the