JTalton's picture

Glu.UnProject replacement for OpenTK.Math

Project:The Open Toolkit library
Version:0.9.9-3
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:confirmed
Description

While Glu support has been marked deprecated and moved to OpenTK.Compatability, the replacement OpenTK.Math does not have a UnProject function.


Comments

the Fiddler's picture

#1

Status:open» confirmed

Function definition (we can do better):

int gluUnProject(
      winx,
      winy,
      winz,
    const GLdouble modelMatrix,
    const GLdouble projMatrix,
    const GLint viewport,
      objx,
      objy,
      objz);

Probably belongs to MathHelper class.

karlschiffmann's picture

#2

Any idea when this feature may be added to the OpenTK release? Thank you...

the Fiddler's picture

#3

Unless someone posts a patch, I'd guess soon after opentk-1.0-final is out.

aklev's picture

#4

    Public Function UnProject(ByVal w As Vector4d, ByVal modelMatrix As Matrix4d, ByVal projMatrix As Matrix4d, _
                              ByVal viewport() As Double, ByRef obj As Vector4d) As Boolean
 
        Dim p As Matrix4d = Matrix4d.Mult(modelMatrix, projMatrix)
        Dim finalMatrix As Matrix4d = Matrix4d.Invert(p)
        Dim [in] As Vector4d = w
 
        ' Map x and y from window coordinates 
        [in].X = ([in].X - viewport(0)) / viewport(2)
        [in].Y = ([in].Y - viewport(1)) / viewport(3)
        ' Map to range -1 to 1 
        [in].X = [in].X * 2.0 - 1.0
        [in].Y = [in].Y * 2.0 - 1.0
        [in].Z = [in].Z * 2.0 - 1.0
        [in].W = 1.0
        Dim out As Vector4d = Vector4d.Transform([in], finalMatrix)
 
        If out.Z = 0.0 Then
            Return False
        End If
 
        out.X /= out.W
        out.Y /= out.W
        out.Z /= out.W
        obj = out
 
        Return True
 
    End Function
the Fiddler's picture

#5

Thanks, I will add this to trunk.

aklev's picture

#6

Small inaccuracy ...

    Public Function UnProject(ByVal w As Vector4d, ByVal modelMatrix As Matrix4d, ByVal projMatrix As Matrix4d, _
                              ByVal viewport() As Double, ByRef obj As Vector4d) As Boolean
 
        Dim p As Matrix4d = Matrix4d.Mult(modelMatrix, projMatrix)
        Dim finalMatrix As Matrix4d = Matrix4d.Invert(p)
        Dim [in] As Vector4d = w
 
        ' Map x and y from window coordinates 
        [in].X = ([in].X - viewport(0)) / viewport(2)
        [in].Y = ([in].Y - viewport(1)) / viewport(3)
        ' Map to range -1 to 1 
        [in].X = [in].X * 2.0 - 1.0
        [in].Y = [in].Y * 2.0 - 1.0
        [in].Z = [in].Z * 2.0 - 1.0
        [in].W = 1.0
        Dim out As Vector4d = Vector4d.Transform([in], finalMatrix)
 
        If out.W = 0.0 Then  ' Small inaccuracy ...
            Return False
        End If
 
        out.X /= out.W
        out.Y /= out.W
        out.Z /= out.W
        obj = out
 
        Return True
 
    End Function