how do i use guunproject? and is there any way to change an x-y position with a specified depth on the screen to an x-y-z position within opengl?
That’s how I do it .
your Z will be got based on your depth Buffer .
static IntBuffer viewport = BufferUtils.createIntBuffer(16);
static FloatBuffer modelview = BufferUtils.createFloatBuffer(16);
static FloatBuffer projection = BufferUtils.createFloatBuffer(16);
static FloatBuffer winZ = BufferUtils.createFloatBuffer(1);
static FloatBuffer position = BufferUtils.createFloatBuffer(3);
/* PomVertice is just a class with float x,y,z coordinates */
static public PomVertice getMousePosition(int mouseX, int mouseY)
{
viewport.clear();
modelview.clear();
projection.clear();
winZ.clear();;
position.clear();
float winX, winY;
GL11.glGetFloat( GL11.GL_MODELVIEW_MATRIX, modelview );
GL11.glGetFloat( GL11.GL_PROJECTION_MATRIX, projection );
GL11.glGetInteger( GL11.GL_VIEWPORT, viewport );
winX = (float)mouseX;
winY = //(float)viewport.get(3) -// (float)mouseY; /* it depends on how you're treating you Y axis */
GL11.glReadPixels(mouseX, (int)winY, 1, 1, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, winZ);
float zz = winZ.get();
GLU.gluUnProject(winX, winY, zz, modelview, projection, viewport, position);
PomVertice v = new PomVertice(position.get(0),position.get(1),position.get(2));
return v ;
}
OK i get it. if i use a distance from the camera say, from my mouse wheel, it would tell me where to draw my pointer in 3d space
P.S how would i get a rendered cursor to always face me? point sprites?