should be somewhere in examples
/**
* get 3d coordinate of srcPoint on object's surface from 2d coordinates.
*
* @param camera scene camera
* @param buffer
* @param x screen (mouse) X coordinate
* @param y screen (mouse) Y coordinate
* @param object to check against
* @return
*/
public static SimpleVector getAbsoluteCoordinate(Camera camera, FrameBuffer buffer, int x, int y, Object3D object) {
SimpleVector rezult = null;
if (camera != null && buffer != null) {
SimpleVector rayTemp = Interact2D.reproject2D3D(camera, buffer, x, y);
rayTemp.normalize();
Matrix orient = camera.getFront();
float[] dump = orient.getDump();
SimpleVector ray = new SimpleVector();
ray.x = dump[0] * rayTemp.x + dump[1] * rayTemp.y + dump[2] * rayTemp.z + dump[3] * 1;
ray.y = dump[4] * rayTemp.x + dump[5] * rayTemp.y + dump[6] * rayTemp.z + dump[7] * 1;
ray.z = dump[8] * rayTemp.x + dump[9] * rayTemp.y + dump[10] * rayTemp.z + dump[11] * 1;
float distance = object.rayIntersectsAABB(camera.getPosition(), ray);
if (distance != Object3D.RAY_MISSES_BOX) {
rezult = new SimpleVector(camera.getPosition());
ray.scalarMul(distance);
rezult.add(ray);
}
}
return rezult;
}