List of usage examples for com.badlogic.gdx.math.collision Ray getEndPoint
public Vector3 getEndPoint(final Vector3 out, final float distance)
From source file:com.mbrlabs.mundus.commons.terrain.Terrain.java
License:Apache License
public Vector3 getRayIntersection(Vector3 out, Ray ray) { // TODO improve performance. use binary search float curDistance = 2; int rounds = 0; ray.getEndPoint(out, curDistance); boolean isUnder = isUnderTerrain(out); while (true) { rounds++;/* www . j a v a 2 s . c o m*/ ray.getEndPoint(out, curDistance); boolean u = isUnderTerrain(out); if (u != isUnder || rounds == 10000) { return out; } curDistance += u ? -0.1f : 0.1f; } }
From source file:com.mbrlabs.mundus.editor.tools.TranslateTool.java
License:Apache License
@Override public void act() { super.act();// w w w .j ava2 s. c o m if (getProjectManager().current().currScene.currentSelection != null) { translateHandles(); if (state == TransformState.IDLE) return; Ray ray = getProjectManager().current().currScene.viewport.getPickRay(Gdx.input.getX(), Gdx.input.getY()); Vector3 rayEnd = getProjectManager().current().currScene.currentSelection.getLocalPosition(temp0); float dst = getProjectManager().current().currScene.cam.position.dst(rayEnd); rayEnd = ray.getEndPoint(rayEnd, dst); if (initTranslate) { initTranslate = false; lastPos.set(rayEnd); } GameObject go = getProjectManager().current().currScene.currentSelection; boolean modified = false; Vector3 vec = new Vector3(); if (state == TransformState.TRANSFORM_XZ) { vec.set(rayEnd.x - lastPos.x, 0, rayEnd.z - lastPos.z); modified = true; } else if (state == TransformState.TRANSFORM_X) { vec.set(rayEnd.x - lastPos.x, 0, 0); modified = true; } else if (state == TransformState.TRANSFORM_Y) { vec.set(0, rayEnd.y - lastPos.y, 0); modified = true; } else if (state == TransformState.TRANSFORM_Z) { vec.set(0, 0, rayEnd.z - lastPos.z); modified = true; } // TODO translation in global sapce // if(globalSpace) { // System.out.println("Before: " + vec); // System.out.println("After: " + vec); // } go.translate(vec); if (modified) { gameObjectModifiedEvent.setGameObject(getProjectManager().current().currScene.currentSelection); Mundus.INSTANCE.postEvent(gameObjectModifiedEvent); } lastPos.set(rayEnd); } }
From source file:com.mbrlabs.mundus.tools.TranslateTool.java
License:Apache License
@Override public void act() { super.act();//from ww w .ja v a 2 s. c o m if (projectManager.current().currScene.currentSelection != null) { translateHandles(); if (state == TransformState.IDLE) return; Ray ray = projectManager.current().currScene.viewport.getPickRay(Gdx.input.getX(), Gdx.input.getY()); Vector3 rayEnd = projectManager.current().currScene.currentSelection.getLocalPosition(temp0); float dst = projectManager.current().currScene.cam.position.dst(rayEnd); rayEnd = ray.getEndPoint(rayEnd, dst); if (initTranslate) { initTranslate = false; lastPos.set(rayEnd); } GameObject go = projectManager.current().currScene.currentSelection; boolean modified = false; Vector3 vec = new Vector3(); if (state == TransformState.TRANSFORM_XZ) { vec.set(rayEnd.x - lastPos.x, 0, rayEnd.z - lastPos.z); modified = true; } else if (state == TransformState.TRANSFORM_X) { vec.set(rayEnd.x - lastPos.x, 0, 0); modified = true; } else if (state == TransformState.TRANSFORM_Y) { vec.set(0, rayEnd.y - lastPos.y, 0); modified = true; } else if (state == TransformState.TRANSFORM_Z) { vec.set(0, 0, rayEnd.z - lastPos.z); modified = true; } // TODO translation in global sapce // if(globalSpace) { // System.out.println("Before: " + vec); // System.out.println("After: " + vec); // } go.translate(vec); if (modified) { gameObjectModifiedEvent.setGameObject(projectManager.current().currScene.currentSelection); Mundus.postEvent(gameObjectModifiedEvent); } lastPos.set(rayEnd); } }
From source file:com.nsoft.boxuniverse.world.BaseWorld.java
License:Open Source License
public void debug(int x, int y) { BaseBlock.BlockDefinition a = new BaseBlock.BlockDefinition(); a.material = BaseMaterial.load(BaseMaterial.getNameFromIndex(MaterialSelector)); a.depth = 1;//from www.j a va2 s .c om a.width = 1; a.height = 1; Ray ray = cam.getPickRay(x * 2 - Gdx.graphics.getWidth() / 2 + cam.position.x * 2, y * 2 - Gdx.graphics.getHeight() / 2 + cam.position.y * 2); Vector3 pos = new Vector3(); a.X = (int) ray.getEndPoint(pos, -ray.origin.z / ray.direction.z).x; a.Y = (int) ray.getEndPoint(pos, -ray.origin.z / ray.direction.z).y; a.world = layers[layerSelector].mundo; layers[layerSelector].addNewBlock(a); }