I have been googling this for about two days. I have got to a point where I can find a direction based on my mouse position on screen, but it seems to not be affected by the yaw or pitch of my camera.
IntBuffer viewport = ByteBuffer.allocateDirect((Integer.SIZE/8)*16).order(ByteOrder.nativeOrder()).asIntBuffer();
FloatBuffer modelview = ByteBuffer.allocateDirect((Float.SIZE/8)*16).order(ByteOrder.nativeOrder()).asFloatBuffer();
FloatBuffer projection = ByteBuffer.allocateDirect((Float.SIZE/8)*16).order(ByteOrder.nativeOrder()).asFloatBuffer();
FloatBuffer pickingRayBuffer = ByteBuffer.allocateDirect((Float.SIZE/8)*3).order(ByteOrder.nativeOrder()).asFloatBuffer();
GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelview);
GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projection);
GL11.glGetInteger(GL11.GL_VIEWPORT, viewport);
float winX = (float) Mouse.getX();
// convert window coordinates to opengl coordinates (top left to bottom left for (0,0)
float winY = (float) viewport.get(3) -(float) Mouse.getX();
// now unproject this to get the vector in to the screen
// take the frustrm and unproject in to the screen
// frustrum has a near plane and a far plane
// first the near vector
GLU.gluUnProject(winX, winY, 0, modelview, projection, viewport, pickingRayBuffer);
Vector3f nearVector = new Vector3f(pickingRayBuffer.get(0),pickingRayBuffer.get(1),pickingRayBuffer.get(2));
pickingRayBuffer.rewind();
// now the far vector
GLU.gluUnProject(winX, winY, 1, modelview, projection, viewport, pickingRayBuffer);
Vector3f farVector = new Vector3f(pickingRayBuffer.get(0),pickingRayBuffer.get(1),pickingRayBuffer.get(2));
This is my current code, now what do I add to find what part of the world my mouse is clicking on?
I need to be able to find the xz coordinates when a cirtain y value is inputted.
Ie, a method in a similar format to this:
public static Vector2f getCoordAtY(Ray ray, float y)...
Thanks in advance!