Hey All,
I'm having some issues with picking in parallel projection mode. I think I'm doing something really dumb…and need some help.
I'm setting up the camera using the following code.
DisplaySystem display = DisplaySystem.getDisplaySystem();
Camera cam = display.getRenderer().getCamera();
cam.setParallelProjection(true);
float aspect = (float) display.getWidth() / display.getHeight();
cam.setFrustum(0.0f,
1000.0f,
-20.0f * aspect,
20.0f * aspect,
-20.0f,
20.0f);
cam.update();
I'm then trying to pick the results with the following code:
Vector2f screenPos = new Vector2f();
// Get the position that the mouse is pointing to
screenPos.set(am.getHotSpotPosition().x, am.getHotSpotPosition().y);
// Get the world location of that X,Y value
Vector3f worldCoords = DisplaySystem.getDisplaySystem()
.getWorldCoordinates(screenPos,
1.0f);
// Get the camera
Camera cam = DisplaySystem.getDisplaySystem()
.getRenderer()
.getCamera();
// Create a ray starting from the camera, and going in the direction
// of the mouse's location
Ray mouseRay = new Ray(DisplaySystem.getDisplaySystem().getWorldCoordinates(screenPos, 0.0f),
worldCoords);
mouseRay.getDirection().normalizeLocal();
results.clear();
rootNode.calculatePick(mouseRay, results);
I calculate the mouse pick all the time (I know this can slow it down...) and what I'm noticing is that it is picking objects and triangle that the absolute mouse is not hovering over.
If I change the frustrums start positions, the issue gets more and more exaggerated. I'm curious as to what I'm doing wrong. I would think that the Ray would shoot directly out, but it looks like it is almost in a 'perspective' mode.
Any ideas what I'm doing wrong?