Convert 3D coordinates to 2D


I am facing an issue while converting 3D coordinates to 2D. My idea is to show a popup when I right click on a box. When I right click the popup appears but far away from the box.

Below is the code:
Vector2f ip = inputManager.getCursorPosition().clone();, ((int)ip.x), ((int)ip.y));

PS: I am using TWL for the popup menu

Look at the mouse picking tutorials for examples of converting from screen to 3d and back again.

I don’t think you want to convert 3D to 2D since you’ve got the 2D viewport coordinates of the mouse pointer from the InputManager.

One thing to watch out for is that the InputManager measures viewport Y-coordinates from the bottom edge of the viewport. If TWL measures from the top edge, then you need to convert like so: [java]
Vector2f mouseXY = getInputManager().getCursorPosition();
int mouseX = Math.round(mouseXY.x);
int displayHeight = cam.getHeight();
int mouseY = displayHeight - Math.round(mouseXY.y);, mouseX, mouseY)