Hi, i opened a new thread because my issue seems to be based on an other problem…
Code
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package foxnet.test;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.bounding.OrientedBoundingBox;
import com.jme.input.AbsoluteMouse;
import com.jme.input.FirstPersonHandler;
import com.jme.input.InputHandler;
import com.jme.input.MouseInput;
import com.jme.input.action.InputAction;
import com.jme.input.action.InputActionEvent;
import com.jme.intersection.BoundingPickResults;
import com.jme.intersection.IntersectionRecord;
import com.jme.math.Ray;
import com.jme.math.Vector2f;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Line;
import com.jme.scene.Spatial.CullHint;
import com.jme.scene.shape.Box;
/**
*
* @author Kr0e
*/
public class gui3dTest extends SimpleGame {
class PickAction extends InputAction {
public void performAction( InputActionEvent evt ) {
if ( evt.getTriggerPressed() ) {
Vector2f screenPos = new Vector2f(am.getHotSpotPosition().x,
am.getHotSpotPosition().y);
Vector3f worldCoords = display.getWorldCoordinates(screenPos, 0);
Vector3f worldCoords2 = display.getWorldCoordinates(screenPos, 1);
Ray mouseRay = new Ray(worldCoords,
worldCoords2.subtractLocal(worldCoords).normalizeLocal());
rootNode.detachChildNamed("line");
Line line = new Line("line", new Vector3f[]{
worldCoords, worldCoords.add(worldCoords2.mult(100) )
} , null, null, null);
rootNode.attachChild(line);
IntersectionRecord ir = box.getModelBound().intersectsWhere(mouseRay);
System.out.println(ir.getClosestDistance());
}
}
}
AbsoluteMouse am;
Box box;
@Override
protected void simpleInitGame() {
MouseInput.get().setCursorVisible(true);
((FirstPersonHandler)input).getMouseLookHandler().setEnabled(false);
am = new AbsoluteMouse("The Mouse", display.getWidth(), display.getHeight());
am.setLocalTranslation(new Vector3f(display.getWidth() / 2,
display.getHeight() / 2, 0));
am.registerWithInputHandler(input);
box = new Box("n", new Vector3f(), 4, 4, 4);
box.setModelBound(new OrientedBoundingBox());
box.getLocalRotation().fromAngleAxis(43, new Vector3f(0,1,0));
box.updateModelBound();
input.addAction( new PickAction(), InputHandler.DEVICE_MOUSE, 0, InputHandler.AXIS_NONE, false );
rootNode.attachChild(am);
rootNode.attachChild(box);
}
public static void main(String[] argv) {
new gui3dTest().start();
}
}
On the image you see the console output and the ray which goes trough a box with an OBB but the output shows that the box is not picked... Whats wrong here ?