re: the original post, it looks like that code is tracking the camera's orientation rather than it's relative position?
re: replies about rotation in general, take a look at this:
import com.jme.app.SimpleGame;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Sphere;
public class RotationEx extends SimpleGame {
Quaternion q = null;
Sphere s1 = null;
Sphere s2 = null;
Box b = null;
Node n = null;
@Override
protected void simpleInitGame() {
s1 = new Sphere("Sphere1", 10, 10, 2.0f);
s2 = new Sphere("Sphere2", 10, 10, 2.0f);
s1.setLocalTranslation(-10.0f, 0, 0);
s2.setLocalTranslation(5.0f, 0, 0);
b = new Box("Box", new Vector3f( -5.0f, -1.0f, -0.5f), new Vector3f( 0.0f, 1.0f, 0.5f));
b.setLocalTranslation( 0, 5.0f, 0);
q = new Quaternion();
n = new Node ("centreOfRotation");
n.attachChild(s2);
rootNode.attachChild(s1);
rootNode.attachChild(b);
rootNode.attachChild(n);
wireState.setEnabled(true);
}
protected void simpleUpdate() {
q.fromAngleNormalAxis(1.0f * tpf, new Vector3f(0,1.0f,0) );
n.getLocalRotation().multLocal(q);
s1.getLocalRotation().multLocal(q);
s2.getLocalRotation().multLocal(q);
b.getLocalRotation().multLocal(q);
}
/**
* @param args
*/
public static void main(String[] args) {
RotationEx demo = new RotationEx();
demo.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
demo.start();
}
}
Basically, just like with anything else, you have to tell the computer where the center of rotation is.
Coordinates 0,0,0 are how you do that - that is always the center of rotation.
Now, where you want that to be depends what the object is.
Example: A ball, you will probably want to rotate around it's physical centre.
With a bat however, that wouldn't be much use. You usually swing a bat around it's grip - so that's where you would have your origin (0,0,0).
In the example code: There are two spheres. Both are spinning around their centers.
This is accomplished by applying rotation directly to them.
One sphere is also orbiting around a central point. This is because it is attached to node n.
Node n is also spinning. Because the sphere is positioned 10 units away from n, it swings around that point.
Lastly, there is a box. The box is defined like so:
b = new Box("Box", new Vector3f( -5.0f, -1.0f, -0.5f), new Vector3f( 0.0f, 1.0f, 0.5f));
The x coordinates of it's corners are -5 and 0. That means the shape is entirely on the left side of the center point.
Just the right edge touches the centre point, which is why it swings around it's end.
If it were defined like this:
b = new Box("Box", new Vector3f( -2.5f, -1.0f, -0.5f), new Vector3f( 2.5f, 1.0f, 0.5f));
Then it would rotate around it's center, as the points are evenly spaced on either side of (0,0,0).
In short, like foobar says, if rotation isn't working the way you want, move the points around (0,0,0) to define what your object should rotate around. You can do this in the code for primitives, or in your modeller for loaded models.
Hope that helps.