Well, the title explains what I need to know

So if I have a basic lwjgl/opengl 3D world with some entities which can be some NPC's or other game stuff. And lets say I want to make floating names, test if object is seen by camera etc. I need to know exact 2D point coordinates when I have 3D point location data.
This is how I did 3D picking (needs to be "reversed"):
Please tell me if there's a better way.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public static Vector3f getMousePosition(int mouseX, int mouseY) { viewport = BufferUtils.createIntBuffer(16); modelview = BufferUtils.createFloatBuffer(16); projection = BufferUtils.createFloatBuffer(16); winZ = BufferUtils.createFloatBuffer(1); position = BufferUtils.createFloatBuffer(3); GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelview); GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projection); GL11.glGetInteger(GL11.GL_VIEWPORT, viewport); GL11.glReadPixels(mouseX, mouseY, 1, 1, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, winZ);
if (winZ.get(0) == 1) { return null; } GLU.gluUnProject(mouseX, mouseY, winZ.get(), modelview, projection, viewport, position); return new Vector3f(position.get(0), position.get(1), position.get(2)); } |
So I was thinking...
By using this (found on stackoverflow):
1
| screen_coordinates = projection_matrix * modelview_matrix * world_coordinates |
Could I somehow get position this way? I need help
