Understanding AbstractControl to myself

i am trying to understand AbstractControl and i,ve make this short example but it won’t run whats the poblem , i,ve added image

below that what i do in this example and also Code
MAIN CLASS
public class Main extends SimpleApplication implements ActionListener{
Node node1;
public static final String MAPPING_MOVE_RIGHT=“moveRight”;
public static final String MAPPING_MOVE_LEFT=“moveLeft”;
public static void main(String[] args) {
Main app = new Main();
app.start();
}

@Override
public void simpleInitApp() {
   node1=new Node("boxNode");
   
   Box b = new Box(.5f, 3, .5f);
   Geometry  geom = new Geometry("Box", b);
   Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
   mat.setColor("Color", ColorRGBA.Blue);
   geom.setMaterial(mat);
   geom.setLocalTranslation(0, 1.5f, 0);
   node1.addControl(new Node_1_Control());
   rootNode.attachChild(node1);
  
   inputManager.addMapping(MAPPING_MOVE_RIGHT,new KeyTrigger(KeyInput.KEY_K) );
   inputManager.addMapping(MAPPING_MOVE_LEFT,new KeyTrigger(KeyInput.KEY_L) );
   inputManager.addListener(this, "moveLeft","moveRight"); 
}   

public void onAction(String name, boolean isPressed, float tpf) {
    if(name.equals("moveLeft")){node1.getControl(Node_1_Control.class).moveRight=isPressed;}
    else if(name.equals("moveRight")){node1.getControl(Node_1_Control.class).moveLeft=isPressed;}
};

}
CONTROL CLASS
public class Node_1_Control extends AbstractControl {
public boolean moveRight,moveLeft;

Node_1_Control() {
}
  @Override
protected void controlUpdate(float tpf) {
    if(moveRight){spatial.rotate(0, 0, 4*tpf);
    }else if(moveLeft){spatial.rotate(0, 0, -4*tpf);
    }
}

@Override
protected void controlRender(RenderManager rm, ViewPort vp) {
   
}

}

How doesn’t it run? Do you get a compile error? Runtime exception? Or does the application run but your spatial won’t rotate?

https://jmonkeyengine.github.io/wiki/tutorials/math/assets/fallback/index.html

Or in other words: The integer 4 * tpf (something very small) equals 0. Change it to 4f.
How many times I’ve fallen into that trap.

Nevermind that, it’s the divisions that get you. I guess I just failed my Java certification course with that answer :wink:

1 Like

It looks like you never add the geometry to the node1… so you have an empty node in the scene graph and won’t see anything.

thank u rickard i remove tpf and my code run well

and thank u pspeed i did not add geom to node1