CSharpGL.glm.unProject C# (CSharp) Method

unProject() public static method

Map the specified window coordinates (win.x, win.y, win.z) into object coordinates.
public static unProject ( vec3 windowPos, CSharpGL.mat4 view, CSharpGL.mat4 proj, vec4 viewport ) : vec3
windowPos vec3 The win.
view CSharpGL.mat4 The view.
proj CSharpGL.mat4 The proj.
viewport vec4 The viewport.
return vec3
        public static vec3 unProject(vec3 windowPos, mat4 view, mat4 proj, vec4 viewport)
        {
            mat4 Inverse = glm.inverse(proj * view);

            vec4 tmp = new vec4(windowPos, (1f));
            tmp.x = (tmp.x - (viewport[0])) / (viewport[2]);
            tmp.y = (tmp.y - (viewport[1])) / (viewport[3]);
            tmp = tmp * (2f) - new vec4(1, 1, 1, 1);// after this, tmp is normalized device coordinate.

            vec4 obj = Inverse * tmp;
            obj /= obj.w;// after this, tmp is model coordinate.

            return new vec3(obj);
        }