Tao.OpenGl SDK Documentation

Glu.gluUnProject4 Method 

Maps window and clip coordinates to object coordinates.

[Visual Basic]
Public Shared Function gluUnProject4( _
   ByVal winX As Double, _
   ByVal winY As Double, _
   ByVal winZ As Double, _
   ByVal clipW As Double, _
   ByVal modelMatrix As Double(), _
   ByVal projectionMatrix As Double(), _
   ByVal viewport As Integer(), _
   ByVal nearVal As Double, _
   ByVal farVal As Double, _
   ByRef objX As Double, _
   ByRef objY As Double, _
   ByRef objZ As Double, _
   ByRef objW As Double _
) As Integer
[C#]
public static int gluUnProject4(
   double winX,
   double winY,
   double winZ,
   double clipW,
   double[] modelMatrix,
   double[] projectionMatrix,
   int[] viewport,
   double nearVal,
   double farVal,
   out double objX,
   out double objY,
   out double objZ,
   out double objW
);

Parameters

winX
The window's x axis coordinate to be mapped.
winY
The window's y axis coordinate to be mapped.
winZ
The window's z axis coordinate to be mapped.
clipW
The clip w coordinate to be mapped.
modelMatrix
The modelview matrix (as from a glGetDoublev call).
projectionMatrix
The projection matrix (as from a glGetDoublev call).
viewport
The viewport (as from a glGetIntegerv call).
nearVal
The near plane (as from a glGetDoublev call).
farVal
The far plane (as from a glGetDoublev call).
objX
The computed object's x axis coordinate.
objY
The computed object's y axis coordinate.
objZ
The computed object's z axis coordinate.
objW
The computed object's clip w coordinate.

Return Value

A return value of GL_TRUE indicates success; a return value of GL_FALSE indicates failure.

Remarks

gluUnProject4 maps the specified window coordinates winX, winY and winZ and its clip w coordinate clipW into object coordinates (objX, objY, objZ, objW) using modelMatrix, projectionMatrix and viewport. clipW can be other than 1 as for vertices in glFeedbackBuffer when data type GL_4D_COLOR_TEXTURE is returned. This also handles the case where the nearVal and farVal planes are different from the default, 0 and 1, respectively. A return value of GL_TRUE indicates success; a return value of GL_FALSE indicates failure.

To compute the coordinates (objX, objY, objZ and objW), gluUnProject4 multiplies the normalized device coordinates by the inverse of modelMatrix multiplied by projectionMatrix as follows:

            ( 2(winX - viewport[0]  )
            | ---------------- - 1  |
            |     viewport[2]       |
            |                       |
            | 2(winY - viewport[1]  |
            ( objX  )             | ---------------- - 1  |
            | objY  | = INV(PM) * |     viewport[3]       |
            | objZ  |             |                       |
            ( objW  )             |  2(winZ - nearVal)    |
            |  -------------- - 1   |
            |    farVal - nearVal   |
            |                       |
            (        clipW          )
            

INV() denotes matrix inversion.

gluUnProject4 is equivalent to gluUnProject when clipW is 1, nearVal is 0 and farVal is 1.

gluUnProject4 is available only if the GLU version is 1.3 or greater.

See Also

Glu Class | Tao.OpenGl Namespace | glFeedbackBuffer | glGetDoublev | glGetIntegerv | gluProject | gluUnProject