LocalRotation about defined axis with fromAngleAxis

Hi,



how can I rotate a simple Box around its y axis? The thing is I moved the Box to another LocalTranslation. Nevertheless the rotation is done around my defined rotation axis (0,1,0) which is still related to the origin 0,0,0 :frowning:

and not to the center of the box. How to do a rotation around the center of the box? Simliar like the rotation of the earth within 24h :wink:



private Quaternion rotQuat = new Quaternion();
private float angle = 0;
private Vector3f axis = new Vector3f(0,1,0);

box = new Box( "Box", new Vector3f(0,0,-20), 5, 6, 5);
box.setLocalTranslation(new Vector3f(15,5,5));

@Override
public void update(float tpf)
{
 if (tpf < 1) {
 angle = angle + (tpf * 2);
   if (angle > 360) {
  angle = 0;
  }
 }

rotQuat.fromAngleAxis(angle, axis);
box.setLocalRotation(rotQuat);   
}




I use the StandardGame design and its part of a menu GameState.

It is around the "center" of the box but this code

box = new Box( "Box", new Vector3f(0,0,-20), 5, 6, 5);


makes your center -20 off in z direction. Maybe that's what confuses you?

Thank you. Now it works,



The "-20" did the confusion  :roll:



private float angle = 0;
private Vector3f axis = new Vector3f(0,1,0);

box = new Box( "Box", new [b]Vector3f()[/b], 5, 6, 5);
box.setLocalTranslation(new Vector3f(13,4,-15));

@Override
   public void update(float tpf)
   {      
      super.update(tpf);
       if (tpf < 1) {
            angle = angle + (tpf * 1);
            if (angle > 360) {
              angle = 0;
            }
          }
       box.getLocalRotation().fromAngleAxis(angle, axis);   
   }