Hi
I am currently working on a some sort of editor. The terrain of this editor is a map built out of tiles (squares).
When i click my GLJPanel i sent a mouseevent because I want to check if I click on a tile.
So basicly I want to convert my X and Y mouse coordinate to Coordinate in the XZ plane (since Y axis is the one pointing up).
So far I tried to do this using glu.gluUnProject but i have no success doing so
During init methode of GLEventListener
this.viewport = IntBuffer.allocate(4); // Where The Viewport Values Will Be Stored
this.modelview = FloatBuffer.allocate(16); // Where The 16 Doubles Of The Modelview Matrix Are To Be Stored
this.projectionview = FloatBuffer.allocate(16); // Where The 16 Doubles Of The Projection Matrix Are To Be Stored
Whenever I reshape my window I update the buffers
gl.glGetIntegerv(GL2.GL_VIEWPORT, this.viewport);
gl.glGetFloatv(GL2.GL_PROJECTION_MATRIX, this.projectionview);
Every time a frame is drawn i update modelview buffer in display method
gl.glGetFloatv(GL2.GL_MODELVIEW_MATRIX, this.modelview);
This is the code i execute when i want to convert the mouse to XZ plane coordinates
float winX, winY; // Holds Our X, Y and Z Coordinates
winX = (float)this.pickX; // Holds The Mouse X Coordinate
winY = (float)this.pickY; // Holds The Mouse Y Coordinate
winY = (float)this.viewport.get(3) - winY - 1; // Subtract The Current Mouse Y Coordinate From The Screen Height.
FloatBuffer projectedPositions = FloatBuffer.allocate(3);
boolean succes = new GLU().gluUnProject(winX, winY, 0.0f, this.modelview, this.projectionview, this.viewport, projectedPositions);
System.out.println(projectedPositions.get(0)+" "+projectedPositions.get(1)+" "+projectedPositions.get(2)+" "+succes);
Am I using the wrong method or am I passing along the wrong arguments?
When i see at least 10 tiles on my screen, each tile = 1.0f x 1.0f the difference between most left and most right tile on my screen is maybe 0.1f so something is obviously going wrong
Thx for any help