package lecture9; import com.jme3.app.SimpleApplication; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.FastMath; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import com.jme3.scene.shape.Box; import com.jme3.scene.Geometry; import com.jme3.scene.Node; import com.jme3.scene.shape.Sphere; public class rotate2 extends SimpleApplication { private Geometry earth; private Geometry moon; private Vector3f axis = new Vector3f(1, 2, 3); private Quaternion quat = new Quaternion(); private Node pivotNode = new Node("PN"); private float angle = 0; public static void main(String[] args) { rotate2 app = new rotate2(); // app.setConfigShowMode(ConfigShowMode.AlwaysShow); app.start(); } @Override public void simpleInitApp() { Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); // create a simple material mat.setColor("Color", ColorRGBA.Blue); Sphere a = new Sphere(100, 100, 1); earth = new Geometry("earth", a); earth.setMaterial(mat); rootNode.attachChild(earth); Box b = new Box(0.3f, 0.3f, 0.3f); moon = new Geometry("moon", b); moon.setMaterial(mat); moon.setLocalTranslation(3, 0, 0); pivotNode.attachChild(moon); rootNode.attachChild(pivotNode); } @Override public void simpleUpdate(float tpf) { if (tpf < 1) { angle = angle + (tpf * 1); if (angle <= 2*FastMath.PI) { } else { angle -= 2*FastMath.PI; } } quat.fromAngleAxis(angle, axis); pivotNode.setLocalRotation(quat); // moon.setLocalTranslation(moon.getLocalTranslation().add(tpf*5,0,0)); } }