Rotation in BaseGame

Hello.



I was studding tutorial, and HelloAnimation.java file.

I modify this file to have only one Box which is rotating.

And it works correctly, but when I copy and paste this to file where I have BaseGame it doesn't work :confused:



Here is my file from SimpleGame:


public class test extends SimpleGame {
    public static void main(String[] args) {
       test app = new test();
        app.setDialogBehaviour(AbstractGame.ALWAYS_SHOW_PROPS_DIALOG);
        app.start();
    }

    protected void simpleInitGame()
    {
       
        // I create a box and attach it too my lightnode.  This lets me see where my light is
       Box b2=new Box("Blarg2",new Vector3f(-.5f,-.5f,-20.5f),new Vector3f(.5f,.5f,-19.5f));
        b2.setModelBound(new BoundingBox());
        b2.updateModelBound();
        rootNode.attachChild(b2);

        // I create a controller to rotate my pivot
        SpatialTransformer st=new SpatialTransformer(1);
        // I tell my spatial controller to change pivot
        st.setObject(b2,0,-1);

        // Assign a rotation for object 0 at time 0 to rotate 0 degrees around the z axis
        Quaternion x0=new Quaternion();
        x0.fromAngleAxis(0,new Vector3f(0,0,1));
        st.setRotation(0,0,x0);

        // Assign a rotation for object 0 at time 2 to rotate 180 degrees around the z axis
        Quaternion x180=new Quaternion();
        x180.fromAngleAxis(FastMath.DEG_TO_RAD*180,new Vector3f(0,0,1));
        st.setRotation(0,4,x180);
       
        // Prepare my controller to start moving around
        //st.interpolateMissing();
        // Tell my pivot it is controlled by st
        b2.addController(st);

        rootNode.attachChild(b2);
    }
}




this same code I was trying to put in "initGame()", after i run app I see my box, but it doesn't rotate like in first example.

Thanks in advice for any help.

Are you making sure you call updateGeometricState(tpf, true); on the rootNode during the update() method?

Also, BaseGame does not call simpleInitGame, that is a SimpleGame only method. If you want to do this, you will need to overwrite the update in BaseGame to call this function.

Thank you for answers.



I have update in my BaseGame, and I change it like this:


   protected void update(float interpolation) {
      //update the time to get the framerate
      timer.update();
      interpolation = timer.getTimePerFrame();
      
      scene.updateGeometricState(0.0f,true);

}



I'm not realy sure is that all I need? And if time (0.0f) is correct, but I also try some other numbers.

Ideally Vasquez21 you'd want to pass the interpolation into the updateGeom method:



protected void update(float interpolation) {
   //update the time to get the framerate
   timer.update();
   interpolation = timer.getTimePerFrame();
      
   scene.updateGeometricState(interpolation, true);

}



My understanding is that this value is used to determine how much to rotate/translate nodes when using things like SpatialTransformer.

Ohhh… that was pretty simple :slight_smile:

Thank you for help.