Hello,
I have a problem with the following getAbsoluteCoordinates() function (it wat posted on the forum) :
public 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.getBack();
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, true);
if (distance != Object3D.RAY_MISSES_BOX) {
//rezult = new SimpleVector(camera.getPosition());
ray.scalarMul(distance);
rezult=new SimpleVector(ray);
//rezult.add(ray);
}
else{
rezult = new SimpleVector(SimpleVector.ORIGIN);
}
}
return rezult;
} // getAbsoluteCoordinate()
I have a level with objects on it and i want to select an object to move it. So, when i click on the level, i call getAbsoluteCoordinates() with each objet in my list (the parameter object in the function) and if it returns something (something different than the origin vector), it means that an object has been found.
The problem is that it is not very accurate (sometimes i even have to click outside the object
). The more the camera is far and the more it is not accurate.
I absolutely don't know if it comes from my object that is not at the position i see it or if it comes from the coordinates returned by the function.
Help me please
Thank you very much