
<refentry id="gluUnProject4">
    <refmeta>
        <refmetainfo>
            <copyright>
                <year>1991-2006</year>
                <holder>Silicon Graphics, Inc.</holder>
            </copyright>
        </refmetainfo>
        <refentrytitle>gluUnProject4</refentrytitle>
        <manvolnum>3G</manvolnum>
    </refmeta>
    <refnamediv>
        <refname>gluUnProject4</refname>
        <refpurpose>map window and clip coordinates to object coordinates</refpurpose>
    </refnamediv>
    <refsynopsisdiv><title>C Specification</title>
        <funcsynopsis>
            <funcprototype>
                <funcdef>GLint <function>gluUnProject4</function></funcdef>
                <paramdef>GLdouble <parameter>winX</parameter></paramdef>
                <paramdef>GLdouble <parameter>winY</parameter></paramdef>
                <paramdef>GLdouble <parameter>winZ</parameter></paramdef>
                <paramdef>GLdouble <parameter>clipW</parameter></paramdef>
                <paramdef>const GLdouble * <parameter>model</parameter></paramdef>
                <paramdef>const GLdouble * <parameter>proj</parameter></paramdef>
                <paramdef>const GLint * <parameter>view</parameter></paramdef>
                <paramdef>GLdouble <parameter>nearVal</parameter></paramdef>
                <paramdef>GLdouble <parameter>farVal</parameter></paramdef>
                <paramdef>GLdouble* <parameter>objX</parameter></paramdef>
                <paramdef>GLdouble* <parameter>objY</parameter></paramdef>
                <paramdef>GLdouble* <parameter>objZ</parameter></paramdef>
                <paramdef>GLdouble* <parameter>objW</parameter></paramdef>
            </funcprototype>
        </funcsynopsis>
    </refsynopsisdiv>
    <!-- eqn: ignoring delim $$ -->
    <refsect1 id="parameters"><title>Parameters</title>
        <variablelist>
        <varlistentry>
            <term><parameter>winX</parameter></term>
            <term><parameter>winY</parameter></term>
            <term><parameter>winZ</parameter></term>
            <listitem>
                <para>
                    Specify the window coordinates to be mapped.
                </para>
            </listitem>
        </varlistentry>
        <varlistentry>
            <term><parameter>clipW</parameter></term>
            <listitem>
                <para>
                    Specify the clip w coordinate to be mapped.
                </para>
            </listitem>
        </varlistentry>
        <varlistentry>
            <term><parameter>model</parameter></term>
            <listitem>
                <para>
                    Specifies the modelview matrix (as from a <citerefentry><refentrytitle>glGetDoublev</refentrytitle></citerefentry> call).
                </para>
            </listitem>
        </varlistentry>
        <varlistentry>
            <term><parameter>proj</parameter></term>
            <listitem>
                <para>
                    Specifies the projection matrix (as from a <citerefentry><refentrytitle>glGetDoublev</refentrytitle></citerefentry> call).
                </para>
            </listitem>
        </varlistentry>
        <varlistentry>
            <term><parameter>view</parameter></term>
            <listitem>
                <para>
                    Specifies the viewport (as from a <citerefentry><refentrytitle>glGetIntegerv</refentrytitle></citerefentry> call).
                </para>
            </listitem>
        </varlistentry>
        <varlistentry>
            <term><parameter>nearVal</parameter></term>
            <term><parameter>farVal</parameter></term>
            <listitem>
                <para>
                    Specifies the near and far planes (as from a <citerefentry><refentrytitle>glGetDoublev</refentrytitle></citerefentry> call).
                </para>
            </listitem>
        </varlistentry>
        <varlistentry>
            <term><parameter>objX</parameter></term>
            <term><parameter>objY</parameter></term>
            <term><parameter>objZ</parameter></term>
            <term><parameter>objW</parameter></term>
            <listitem>
                <para>
                    Returns the computed object coordinates.
                </para>
            </listitem>
        </varlistentry>
        </variablelist>
    </refsect1>
    <refsect1 id="description"><title>Description</title>
        <para>
            <function>gluUnProject4</function> maps the specified window coordinatesi: <parameter>winX</parameter>, <parameter>winY</parameter>, and <parameter>winZ</parameter>
            and its clip w coordinate <parameter>clipW</parameter>
            into object 
            coordinates 
            <inlineequation><mml:math>
                <!-- eqn: (objX, objY, objZ, objW):-->
                <mml:mfenced open="(" close=")">
                    <mml:mi mathvariant="italic">objX</mml:mi>
                    <mml:mi mathvariant="italic">objY</mml:mi>
                    <mml:mi mathvariant="italic">objZ</mml:mi>
                    <mml:mi mathvariant="italic">objW</mml:mi>
                </mml:mfenced>
            </mml:math></inlineequation>
            using <parameter>model</parameter>, <parameter>proj</parameter>, and <parameter>view</parameter>. <parameter>clipW</parameter> can be other than
            1 as for vertices in <citerefentry><refentrytitle>glFeedbackBuffer</refentrytitle></citerefentry> when data type 
            <constant>GLU_4D_COLOR_TEXTURE</constant> is returned.
            This also handles the case
            where the <parameter>nearVal</parameter> and <parameter>farVal</parameter> planes are different from the default,
            0 and 1, respectively.
            A return 
            value of <constant>GLU_TRUE</constant> indicates success; a return value of <constant>GLU_FALSE</constant>
            indicates failure.
        </para>
        <para>
            To compute the coordinates 
            <inlineequation><mml:math>
                <!-- eqn: (objX, objY, objZ, objW):-->
                <mml:mfenced open="(" close=")">
                    <mml:mi mathvariant="italic">objX</mml:mi>
                    <mml:mi mathvariant="italic">objY</mml:mi>
                    <mml:mi mathvariant="italic">objZ</mml:mi>
                    <mml:mi mathvariant="italic">objW</mml:mi>
                </mml:mfenced>
            </mml:math></inlineequation>,
            <function>gluUnProject4</function> multiplies the normalized device coordinates by the inverse of
            <parameter>model</parameter> * <parameter>proj</parameter> as follows:
        </para>
        <para>
            <informalequation><mml:math>
                <!-- eqn: left ( cpile {  objX above  objY above  objZ above  objW}    right )  =  INV(P M)  left ( cpile {  {2(winX  -  view[0])} over {view[2]}  -  1 above  {2(winY  -  view[1])} over {view[3]}  -  1 above  {2(winZ  -  nearVal)} over {(farVal  -  nearVal)}  -  1 above  clipW}    right ):-->
                <mml:mrow>
                    <mml:mfenced open="(" close=")">
                        <mml:mtable>
                            <mml:mtr><mml:mtd>
                                <mml:mi mathvariant="italic">objX</mml:mi>
                            </mml:mtd></mml:mtr>
                            <mml:mtr><mml:mtd>
                                <mml:mi mathvariant="italic">objY</mml:mi>
                            </mml:mtd></mml:mtr>
                            <mml:mtr><mml:mtd>
                                <mml:mi mathvariant="italic">objZ</mml:mi>
                            </mml:mtd></mml:mtr>
                            <mml:mtr><mml:mtd>
                                <mml:mi mathvariant="italic">objW</mml:mi>
                            </mml:mtd></mml:mtr>
                        </mml:mtable>
                    </mml:mfenced>
                    <mml:mo>=</mml:mo>
                    <mml:mrow>
                        <mml:mrow>
                            <mml:mi mathvariant="italic">INV</mml:mi>
                            <mml:mo>&af;</mml:mo>
                            <mml:mfenced open="(" close=")">
                                <mml:mrow>
                                    <mml:mi mathvariant="italic">P</mml:mi>
                                    <mml:mo>&it;</mml:mo>
                                    <mml:mi mathvariant="italic">M</mml:mi>
                                </mml:mrow>
                            </mml:mfenced>
                        </mml:mrow>
                        <mml:mo>&it;</mml:mo>
                        <mml:mfenced open="(" close=")">
                            <mml:mtable>
                                <mml:mtr><mml:mtd>
                                    <mml:mrow>
                                        <mml:mfrac>
                                            <mml:mfenced open="" close="">
                                                <mml:mrow>
                                                    <mml:mn>2</mml:mn>
                                                    <mml:mo>&af;</mml:mo>
                                                    <mml:mfenced open="(" close=")">
                                                        <mml:mrow>
                                                            <mml:mi mathvariant="italic">winX</mml:mi>
                                                            <mml:mo>-</mml:mo>
                                                            <mml:mrow>
                                                                <mml:mi mathvariant="italic">view</mml:mi>
                                                                <mml:mo>&af;</mml:mo>
                                                                <mml:mfenced open="[" close="]">
                                                                    <mml:mn>0</mml:mn>
                                                                </mml:mfenced>
                                                            </mml:mrow>
                                                        </mml:mrow>
                                                    </mml:mfenced>
                                                </mml:mrow>
                                            </mml:mfenced>
                                            <mml:mfenced open="" close="">
                                                <mml:mrow>
                                                    <mml:mi mathvariant="italic">view</mml:mi>
                                                    <mml:mo>&af;</mml:mo>
                                                    <mml:mfenced open="[" close="]">
                                                        <mml:mn>2</mml:mn>
                                                    </mml:mfenced>
                                                </mml:mrow>
                                            </mml:mfenced>
                                        </mml:mfrac>
                                        <mml:mo>-</mml:mo>
                                        <mml:mn>1</mml:mn>
                                    </mml:mrow>
                                </mml:mtd></mml:mtr>
                                <mml:mtr><mml:mtd>
                                    <mml:mrow>
                                        <mml:mfrac>
                                            <mml:mfenced open="" close="">
                                                <mml:mrow>
                                                    <mml:mn>2</mml:mn>
                                                    <mml:mo>&af;</mml:mo>
                                                    <mml:mfenced open="(" close=")">
                                                        <mml:mrow>
                                                            <mml:mi mathvariant="italic">winY</mml:mi>
                                                            <mml:mo>-</mml:mo>
                                                            <mml:mrow>
                                                                <mml:mi mathvariant="italic">view</mml:mi>
                                                                <mml:mo>&af;</mml:mo>
                                                                <mml:mfenced open="[" close="]">
                                                                    <mml:mn>1</mml:mn>
                                                                </mml:mfenced>
                                                            </mml:mrow>
                                                        </mml:mrow>
                                                    </mml:mfenced>
                                                </mml:mrow>
                                            </mml:mfenced>
                                            <mml:mfenced open="" close="">
                                                <mml:mrow>
                                                    <mml:mi mathvariant="italic">view</mml:mi>
                                                    <mml:mo>&af;</mml:mo>
                                                    <mml:mfenced open="[" close="]">
                                                        <mml:mn>3</mml:mn>
                                                    </mml:mfenced>
                                                </mml:mrow>
                                            </mml:mfenced>
                                        </mml:mfrac>
                                        <mml:mo>-</mml:mo>
                                        <mml:mn>1</mml:mn>
                                    </mml:mrow>
                                </mml:mtd></mml:mtr>
                                <mml:mtr><mml:mtd>
                                    <mml:mrow>
                                        <mml:mfrac>
                                            <mml:mfenced open="" close="">
                                                <mml:mrow>
                                                    <mml:mn>2</mml:mn>
                                                    <mml:mo>&af;</mml:mo>
                                                    <mml:mfenced open="(" close=")">
                                                        <mml:mrow>
                                                            <mml:mi mathvariant="italic">winZ</mml:mi>
                                                            <mml:mo>-</mml:mo>
                                                            <mml:mi mathvariant="italic">nearVal</mml:mi>
                                                        </mml:mrow>
                                                    </mml:mfenced>
                                                </mml:mrow>
                                            </mml:mfenced>
                                            <mml:mfenced open="" close="">
                                                <mml:mfenced open="(" close=")">
                                                    <mml:mrow>
                                                        <mml:mi mathvariant="italic">farVal</mml:mi>
                                                        <mml:mo>-</mml:mo>
                                                        <mml:mi mathvariant="italic">nearVal</mml:mi>
                                                    </mml:mrow>
                                                </mml:mfenced>
                                            </mml:mfenced>
                                        </mml:mfrac>
                                        <mml:mo>-</mml:mo>
                                        <mml:mn>1</mml:mn>
                                    </mml:mrow>
                                </mml:mtd></mml:mtr>
                                <mml:mtr><mml:mtd>
                                    <mml:mi mathvariant="italic">clipW</mml:mi>
                                </mml:mtd></mml:mtr>
                            </mml:mtable>
                        </mml:mfenced>
                    </mml:mrow>
                </mml:mrow>
            </mml:math></informalequation>
        </para>
        <para>
            <inlineequation><mml:math><mml:mi mathvariant="italic">INV</mml:mi></mml:math></inlineequation>
            denotes matrix inversion. 
        </para>
        <para>
            <function>gluUnProject4</function> is equivalent to <citerefentry><refentrytitle>gluUnProject</refentrytitle></citerefentry> when <parameter>clipW</parameter> is 1, <parameter>nearVal</parameter> is 0, and
            <parameter>farVal</parameter> is 1.
        </para>
    </refsect1>
    <refsect1 id="notes"><title>Notes</title>
        <para>
            <function>gluUnProject4</function> is available only if the GLU version is 1.3 or greater.
        </para>
    </refsect1>
    <refsect1 id="seealso"><title>See Also</title>
        <para>
            <citerefentry><refentrytitle>gluProject</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>gluUnProject</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glFeedbackBuffer</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glGet</refentrytitle></citerefentry>
        </para>
    </refsect1>
    <refsect1 id="Copyright"><title>Copyright</title>
        <para>
            Copyright <trademark class="copyright"></trademark> 1991-2006
            Silicon Graphics, Inc. This document is licensed under the SGI
            Free Software B License. For details, see
            <ulink url="http://oss.sgi.com/projects/FreeB/">http://oss.sgi.com/projects/FreeB/</ulink>.
        </para>
    </refsect1>
</refentry>
