package jme3test.helloworld;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
/** Sample 4 - how to trigger repeating actions from the main event loop.
* In this example, you use the loop to make the player character
* rotate continuously. */
public class HelloLoop extends SimpleApplication {
public static void main(String[] args){
HelloLoop app = new HelloLoop();
app.start();
}
protected Geometry player;
protected Geometry player2;
protected Node pivot;
protected Material matb;
protected Material mat;
@Override
public void simpleInitApp() {
/** this blue box is our player character */
Box b = new Box(1, 1, 1);
player = new Geometry("blue cube", b);
player.setLocalTranslation(new Vector3f(1,-1,1));
mat = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
player.setMaterial(mat);
rootNode.attachChild(player);
Box c = new Box(1, 1, 1);
player2 = new Geometry("red cube", c);
player2.setLocalTranslation(new Vector3f(1,3,1));
matb = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
matb.setColor("Color", ColorRGBA.Red);
player2.setMaterial(mat);
rootNode.attachChild(player2);
pivot = new Node("pivot");
rootNode.attachChild(pivot); // put this node in the scene
/** Attach the two boxes to the *pivot* node. (And transitively to the root node.) */
pivot.attachChild(player);
pivot.attachChild(player2);
/** Rotate the pivot node: Note that both boxes have rotated! */
// pivot.rotate(.4f,.4f,0f);
}
/* Use the main event loop to trigger repeating actions. */
@Override
public void simpleUpdate(float tpf) {
//make the player rotate:
player.rotate(0, 2*tpf, 0);
player2.rotate(0, -4*tpf, 0);
pivot.move(0, 2*tpf, 0);
pivot.rotate(1*tpf, 1*tpf,0);
}
}