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_product extends SimpleApplication { public static void main(String[] args) { cross_product app = new cross_product(); // 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); // from v rotate to u Vector3f u = new Vector3f(1, 0, 0).normalize(); Vector3f v = new Vector3f(0, 1, 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); Spatial 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)); // do rotation Quaternion q = new Quaternion(); q.fromAngleAxis(angle, axis); gyArrow.setLocalRotation(q); } @Override public void simpleUpdate(float tpf) { // } }