package lecture10; 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.Spatial; import com.jme3.scene.debug.Arrow; import com.jme3.system.Timer; public class cross_product2 extends SimpleApplication { private Timer t; private float currentT; private float timeoutR; private float startAngle; private float targetAngle; private Vector3f axisV; Spatial gyArrow; public static void main(String[] args) { cross_product2 app = new cross_product2(); // 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); Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); // create a simple material mat1.setColor("Color", ColorRGBA.White); Vector3f v = new Vector3f(0, 1, 0).normalize(); Vector3f u = new Vector3f(1, 0, 0).normalize(); // draw a v as the starting vector // but with a different color to differentiate with later vector Arrow orig_Arrow = new Arrow(v); Spatial gOrigArrow = new Geometry("X",orig_Arrow); gOrigArrow.setMaterial(mat1); rootNode.attachChild(gOrigArrow); // initialise another v // for rotation Arrow yArrow = new Arrow(v); gyArrow = new Geometry("Y", yArrow); gyArrow.setMaterial(mat); rootNode.attachChild(gyArrow); // compute axis and angle by // cross and dot product, respectively Vector3f axis = v.cross(u); float angle = FastMath.acos(v.dot(u)); currentT = 0; timeoutR = 10; startAngle = 0; targetAngle = angle; axisV = axis; } @Override public void simpleUpdate(float tpf) { currentT = currentT + 1; if (currentT < timeoutR * (1 / tpf)) { float currentAngle = (startAngle + (currentT/(timeoutR * (1/tpf)))*targetAngle); Quaternion q = new Quaternion(); currentAngle += tpf; q.fromAngleAxis(currentAngle, axisV); gyArrow.setLocalRotation(q); } } }