Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.jme3.app.SimpleApplication;
- import com.jme3.material.Material;
- import com.jme3.math.ColorRGBA;
- import com.jme3.math.FastMath;
- import com.jme3.math.Vector3f;
- import com.jme3.scene.Geometry;
- import com.jme3.scene.Node;
- import com.jme3.scene.debug.Arrow;
- import com.jme3.scene.debug.Grid;
- import com.jme3.scene.shape.Box;
- import com.jme3.texture.Texture;
- public class WorldToLocal extends SimpleApplication {
- static Node container, pivot;
- static Material blank, wireframe;
- public static void main(String[] args) {
- WorldToLocal app = new WorldToLocal();
- app.start();
- }
- @Override
- public void simpleInitApp() {
- blank = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
- blank.setColor("Color", ColorRGBA.White);
- wireframe = blank.clone();
- wireframe.getAdditionalRenderState().setWireframe(true);
- flyCam.setMoveSpeed(10);
- //something to contain the pivot node, translated and rotated for testing
- container = new Node();
- container.setLocalTranslation(-0.5f, 1, 2);
- container.rotate(0, 45*FastMath.DEG_TO_RAD, -10*FastMath.DEG_TO_RAD);
- rootNode.attachChild(container);
- // the node that needs to face the tgt point
- pivot = new Node();
- pivot.setLocalTranslation(container.worldToLocal(Vector3f.ZERO, new Vector3f()));
- container.attachChild(pivot);
- // a point to look at
- Geometry tgt = new Geometry("realpoint", new Box(0.1f,0.1f,0.1f));
- tgt.setLocalTranslation(new Vector3f(-5,2,4));
- tgt.setMaterial(blank);
- rootNode.attachChild(tgt);
- //making an arrow that faces the z.axis. this geometry shouldn't be rotated but the parent node
- Arrow arrow = new Arrow(Vector3f.UNIT_Z.mult(2));
- arrow.setLineWidth(8);
- Geometry zaxisvector = new Geometry("vector", arrow);
- zaxisvector.setMaterial(blank);
- pivot.attachChild(zaxisvector);
- //should work but doesn't
- pivot.lookAt(pivot.worldToLocal(tgt.getWorldTranslation(), new Vector3f()), Vector3f.UNIT_Y);
- //works but shouldn't (comment out to test out the previous lookAt)
- pivot.lookAt(pivot.getWorldRotation().mult(pivot.worldToLocal(tgt.getWorldTranslation().add(pivot.getWorldTranslation()),new Vector3f())), Vector3f.UNIT_Y);
- //grid for reference 1 box = 1 unit
- rootNode.attachChild(attachGrid(Vector3f.ZERO, 81, ColorRGBA.White));
- }
- private Geometry attachGrid(Vector3f pos, int size, ColorRGBA color){
- Geometry g = new Geometry("wireframe grid", new Grid(size, size, 1));
- g.setMaterial(wireframe);
- g.center().move(pos);
- rootNode.attachChild(g);
- return g;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement