问题
So I have been looking through tutorials (And questions on this site) and have found nothing to solve my problem. Here is the current code I am trying to implement:
private void pick() {
float[] matModelView = new float[16], matProjView = new float[16];
int[] view = new int[16];
float mouseX = width / 2;
float mouseY = height / 2;
Vector3f start = new Vector3f();
Vector3f end = new Vector3f();
FloatBuffer modelBuffer = compileBuffer(matModelView);
FloatBuffer projBuffer = compileBuffer(matProjView);
FloatBuffer startBuffer = compileBuffer(new float[]{start.x, start.y, start.z, 1});
FloatBuffer endBuffer = compileBuffer(new float[]{end.x, end.y, end.z, 1});
IntBuffer viewBuffer = compileBuffer(view);
glGetFloat(GL_MODELVIEW_MATRIX, modelBuffer);
glGetFloat(GL_PROJECTION_MATRIX, projBuffer);
glGetInteger(GL_VIEWPORT, viewBuffer);
gluUnProject(mouseX, mouseY, 0.0f, modelBuffer, projBuffer, viewBuffer, startBuffer);
gluUnProject(mouseX, mouseX, 1.0f, modelBuffer, projBuffer, viewBuffer, endBuffer);
start = new Vector3f(startBuffer.get(0), startBuffer.get(1), startBuffer.get(2));
end = new Vector3f(endBuffer.get(0), endBuffer.get(1), endBuffer.get(2));
picks.add(new Vector3f[]{start, end});
System.out.println("Mouse Coords: " + mouseX + ", " + mouseY);
System.out.println("Position: " + position.x + ", " + position.y + ", " + position.z);
System.out.println("Rotation: " + rotation.x + ", " + rotation.y + ", " + rotation.z);
System.out.println("Near Plane: " + start.x + ", " + start.y + ", " + start.z);
System.out.println("Far Plane: " + end.x + ", " + end.y + ", " + end.z);
}
I have the mouseX and Y set the way I do because my mouse is grabbed. Here is an image and some output for you. (I can't really explain the problem)
Mouse Coords: 400.0, 350.0
Position: 0.0, 0.0, 0.0 Rotation: 0.0, 0.0, 0.0 Near Plane: 0.0, 0.0, -0.1 Far Plane: 0.0, 4.2315264, -99.99771
So, for a rotation of X:0 Y:0 Z:0, the expected output of the Y coord should be the same as the input. It is higher. Here is a picture of that output.
Can anyone give me some kind of hint or explanation on why this would happen?
EDIT: Facepalms violently: I was pushing mouseX in the Y parameter of the second gluUnProject
来源:https://stackoverflow.com/questions/21345493/lwjgl-ray-picking-gluunproject