CSharpGL.glm.project C# (CSharp) Method

project() public static method

Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates.
public static project ( vec3 modelPosition, CSharpGL.mat4 view, CSharpGL.mat4 proj, vec4 viewport ) : vec3
modelPosition vec3 The object.
view CSharpGL.mat4 The view.
proj CSharpGL.mat4 The proj.
viewport vec4 The viewport.
return vec3
        public static vec3 project(vec3 modelPosition, mat4 view, mat4 proj, vec4 viewport)
        {
            vec4 tmp = new vec4(modelPosition, (1f));
            tmp = view * tmp;
            tmp = proj * tmp;// this is gl_Position

            tmp /= tmp.w;// after this, tmp is normalized device coordinate.

            tmp = tmp * 0.5f + new vec4(0.5f, 0.5f, 0.5f, 0.5f);
            tmp[0] = tmp[0] * viewport[2] + viewport[0];
            tmp[1] = tmp[1] * viewport[3] + viewport[1];// after this, tmp is window coordinate.

            return new vec3(tmp.x, tmp.y, tmp.z);
        }