Rotation

hi,





I need a model to be rotated according to the person press the “Q” and "E "… If Q is pressures, the model rotates to the left. If E is pressed, the model rotates to the right …





how I could do this using the matrix or quaternion?





i read it: http://www.jmonkeyengine.com/wiki/doku.php/matrix , but not understand

Pardon me if I sound ignorant (I'm still learning JME), but is there a reason you want to use a matrix to rotate a model?



private void setKeyBindings(String api) {
        KeyBindingManager keyboard = KeyBindingManager.getKeyBindingManager();

        keyboard.set("turnRight", KeyInput.KEY_E);
        keyboard.set("turnLeft", KeyInput.KEY_Q);
    }

private void setActions(Spatial node) {
        KeyNodeRotateRightAction rotateRight = new KeyNodeRotateRightAction(node, 5f);
        rotateRight.setLockAxis(node.getLocalRotation().getRotationColumn(1));
        addAction(rotateRight, "turnRight", true);
 
        KeyNodeRotateLeftAction rotateLeft = new KeyNodeRotateLeftAction(node, 5f);
        rotateLeft.setLockAxis(node.getLocalRotation().getRotationColumn(1));
        addAction(rotateLeft, "turnLeft", true);
}



Couldn't you just rotate the models node like we all learned in Flag Rush? Or is there some advantage to using a matrix that I'm missing? :?

I'm not so sure he knows flagrush :stuck_out_tongue:



For me the fastest way to rotate a node for a certain amount of degree:



      Quaternion rotLeft = new Quaternion();
      rotLeft.fromAngleAxis(3*FastMath.DEG_TO_RAD, Vector3f.UNIT_Y);
      Node n = new Node();
      // rotate n about 3 deg to left (might right don't know the direction of positiv or negative degrees
      n.getLocalRotation().multLocal(rotLeft);
      // rotate again
      n.getLocalRotation().multLocal(rotLeft);



ttrocha,



Worked very well.





thank you very much!