Re: (x,y) -> (x, y, z)

New Message Reply Date view Thread view Subject view Author view

Dirk Luesebrink (crux++at++artcom.de)
Tue, 15 Dec 1998 12:27:57 +0100


try this:

take Mouse X and Y and normalize them to your Channel viewport, so that
they
are between 0.0 and 1.0. than you can to the following little vector
math:

bool
screen_to_world( pfVec3 seg[2], pfChannel* chan, float rel_x, float
rel_y)
{
    pfVec3 ll, lr, ul, ur;

        // get the lower lower left, lower right, upper left and
        // upper right corner of the near clipping plane of your
        // current viewing frustum
        //
    chan->getNear( ll, lr, ul, ur);

        // get direction vector in near plane from above plane
    pfVec3 right = lr - ll;
    pfVec3 up = ul - ll;

        // now the intersection point of the mouse ray with the
        // near plane can be expressed as follows:
    seg[0] = ll + rel_x * right + rel_y * up;

        // all of the above for the far clipping plane
    chan->getFar( ll, lr, ul, ur);
    right = lr - ll;
    up = ul - ll;
    seg[1] = ll + rel_x * right + rel_y * up;

        // seg[0] and seg[1] now contains the two intersection points
        // with the near and the far plane but is not clamped to the
sides.
        // so return whether mouse is in channel or not:
    return
        rel_x < 0.0 ? false :
        rel_x > 1.0 ? false :
        rel_y < 0.0 ? false :
        rel_y > 1.0 ? false :
        true
    ;
}

note: is make no difference for the function whether the frustum is
perspective,orthographic or off-axis.

dirk luesebrink

Dirk Scheffter wrote:
>
> Hi there,
>
> I want to convert the screen coords of the mouse pointer into world coords.
>
> (I've implemented a class to use a construction plain for clicking into 3d
> world. This I've done in OpenGL using gluUnProject. Now I want to use the same
> in my current Performer application.)
>
> I remember in Vega exists a function to do this. Is there something similar
> available in Performer?
>
> All help is appreciated.
>
> Greetings,
> Dirk.
>
> --
> ----------------------------------------------------
> Dipl.-Inf. Dirk Scheffter
> Fraunhofer IFF fon: +49 (0) 391/40 90-854
> Sandtorstr. 22 fax: +49 (0) 391/40 90-870
> D-39106 Magdeburg e-mail: scheff++at++iff.fhg.de
> Germany http://wwwue.iff.fhg.de/~scheff/
> ----------------------------------------------------
> =======================================================================
> List Archives, FAQ, FTP: http://www.sgi.com/software/performer/
> Submissions: info-performer++at++sgi.com
> Admin. requests: info-performer-request++at++sgi.com

-- 

dirk lüsebrink fon +49 (30) 210010 art+com crux++at++artcom.de fax +49 (30) 21001555 kleiststrasse 23-26 www.artcom.de 10787 berlin, germany


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Tue Dec 15 1998 - 03:18:44 PST

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.