rttidus's picture

How to use glu.UnProject for Vector3?

To be honest, I am a very beginner for OpenTK and I don't have much time, so I can say I really have studied just surface of OpenTK or Opengl.

On my project, I need to pick some objects, actually, I just need to get a vector of a texture when I click some points on my display.

I searched lots of times, and I thoght I needed to use Glu.unproject function. But I can't use this now, cuz they don't have this function any more.

on websites, there is only for verctor4 or vector3d unprojuct function.

HOW do I make or get unproject function for verctor3?

I got this source from this site.

public void MouseInput(int mouseX, int mouseY) {
BeginView(); // Setup Model and Projection Matrices

GL.GetInteger(GetPName.Viewport, viewport);
GL.GetDouble(GetPName.ModelviewMatrix, modelViewMatrix);
GL.GetDouble(GetPName.ProjectionMatrix, projectionMatrix1);

Vector3 win = new Vector3(mouseX, viewport[3] - mouseY, 0);
object t = win.Z; // Must box the float
GL.ReadPixels(mouseX, viewport[3] - mouseY, 1, 1, OpenTK.Graphics.OpenGL.PixelFormat.DepthComponent, PixelType.Float, PixelPtr);
win.Z = (float)t; // Unbox the float

Vector3 worldPosition;
glu.UnProject(win, modelViewMatrix, projectionMatrix, viewport, worldPosition);



I really need your help, thanks.