Rotation about itself


I learned how to scale, move the node

now I want to learn about rotation

I tried mostly with quaternion (althought it is still a bit unclear for me)

Box b1 = newBox("box1",min,max);

Quaternion rl = new Quaternion(); // rl = rotateleft

rl.fromAngleAxis(90, new Vector3f(0,0,1)); // if I understand well, then it rotates the box 90 grad along z axis


that code above rotate the whole box and move its location a bit, but I wanted to rotate the box to stay at its current position and rotate from its middle point

I also tried b1.getCenter();


but all of them failed (may be because I didnt use them right)

Can anyone help me ?

The box should not move when you apply a rotation.

When you create the box, make sure that the center is a empty vector. And don't modify the center. (use setLocalTranslation() to modify the location.)

I didnt modify the center (I dont even know how ^^ , maybe setcenter() ?)

can you take a look at my code ?

I used the setlocaltransition like you said, so i dont think i modified the center

may be the problem is quaternion.from angelaxis ?

I also made important code, where you should take a look, bold.

only 2 blocks  :D

import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.input.InputSystem;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.system.JmeException;
import com.jme.util.TextureManager;
import com.jme.util.Timer;
 * Tutorial 2 shows how to build our own Application
 * framework for Flag Rush.
 * For Flag Rush Tutorial Series.
 * @author Mark Powell
public class Leprobesson2 extends BaseGame {
   private Camera cam;
   private Node scene;
   private TextureState ts;
   private int width, height, depth, freq;
   private boolean fullscreen;
   protected Timer timer;
   private Box s;
   public static void main(String[] args) {
      Leprobesson2 app = new Leprobesson2();

   protected void update(float interpolation) {
      //update the time to get the framerate
      interpolation = timer.getTimePerFrame();
      //if escape was pressed, we exit
      if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit")) {
         finished = true;
      [b]if (KeyBindingManager.getKeyBindingManager().isValidCommand("right")) {
         Quaternion rot = new Quaternion().fromAngleAxis(1, new Vector3f(0,1,0));
      if (KeyBindingManager.getKeyBindingManager().isValidCommand("left")) {
//         s.setLocalRotation(s.getLocalRotation().
   protected void render(float interpolation) {
      //Clear the screen
    * initializes the display and camera.
   protected void initSystem() {
      //store the properties information
      width = settings.getWidth();
      height = settings.getHeight();
      depth = settings.getDepth();
      freq = settings.getFrequency();
      fullscreen = settings.isFullscreen();
      try {
         display = DisplaySystem.getDisplaySystem(settings.getRenderer());
         display.createWindow(width, height, depth, freq, fullscreen);
         cam = display.getRenderer().createCamera(width, height);
      } catch (JmeException e) {
      //set the background to black
      //initialize the camera
      cam.setFrustumPerspective(45.0f, (float)width / (float)height, 1, 1000);
      Vector3f loc = new Vector3f(0.0f, 0.0f, 25.0f);
      Vector3f left = new Vector3f(-1.0f, 0.0f, 0.0f);
      Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
      Vector3f dir = new Vector3f(0.0f, 0f, -1.0f);
      // Move our camera to a correct place and orientation.
      cam.setFrame(loc, left, up, dir);
      /** Signal that we've changed our camera's location/frustum. */
      /** Get a high resolution timer for FPS updates. */
           timer = Timer.getTimer();
    * initializes the scene
   protected void initGame() {
      scene = new Node("Scene graph node");
   [b]   //Create our Sphere
      Quaternion rot = new Quaternion().fromAngleAxis(1, new Vector3f(0,1,0));
      s = new Box("Sphere",new Vector3f(0,0,0),new Vector3f(10,10,10));
      s.setLocalTranslation(new Vector3f(0, 0, -40));
      s.setModelBound(new BoundingBox());
      ts = display.getRenderer().createTextureState();
      //update the scene graph for rendering
      scene.updateGeometricState(0.0f, true);
    * will be called if the resolution changes
   protected void reinit() {
      display.recreateWindow(width, height, depth, freq, fullscreen);
    * clean up the textures.
   protected void cleanup() {

edit: added code tags

The Center of your Box is 5,5,5 because the way you created the Box:

// the center will be 5,5,5:
s = new Box("Sphere",new Vector3f(0,0,0),new Vector3f(10,10,10));

// center will be 0,0,0
s = new Box("Sphere",new Vector3f(-5,-5,-5),new Vector3f(5,5,5));

// yet another constructor where center is explicitly st to 0,0,0:
s = new Box("Sphere",new Vector3f(0,0,0), 10, 10, 10);

Also when rotating you should always use the interpolation value to get a smoother rotation:

if (KeyBindingManager.getKeyBindingManager().isValidCommand("right")) {
   Quaternion rot = new Quaternion().fromAngleAxis(100*interpolation*FastMath.DEG_TO_RAD, new Vector3f(0,1,0));

it works much much better now  :smiley:

thank you very much