Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

Thread: transforming fron (x, y, z) to (x, y)

  1. #1
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264

    transforming fron (x, y, z) to (x, y)

    I've done my own code and also used gluUnProject() to get the windows coordinates, but seems as if both my code and gluUnProject() have problems (I'm not getting the right numbers)

    I also did some tests with GL_FEEDBACK with GL_2D but this gives even different numbers????

    I'm plotting a single point on the screen (window under Windows 9x/NT) and trouble is, I don't know where it's going to be placed.

    Has anyone figured out how to do this calculation, preferably without the use of any GL functions?

    thanks
    V-man
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  2. #2
    Junior Member Regular Contributor
    Join Date
    Feb 2000
    Posts
    154

    Re: transforming fron (x, y, z) to (x, y)

    Hmm dont know exactly what you want to do but this is how I convert xyz to screen xy:

    ScreenX = X / Z + ScreenCenterX
    ScreenY = Y / Z + ScreenCenterY

    Or you could replace those two divides with one by doing:

    OneZ = 1/Z
    ScreenX = X * OneZ + ScreenCenterX
    ScreenY = Y * OneZ + ScreenCenterY

    Cheers

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,982

    Re: transforming fron (x, y, z) to (x, y)

    The only problen with what you are saying AndersO, is that the viewpoint have to be located at (0,0,0) and looking along the z-axis. When your viewpoint is placed elsewhere, or looking at another direction, you wont get the right coordinates.

    Bob

  4. #4
    Intern Contributor
    Join Date
    Feb 2000
    Location
    Italy
    Posts
    77

    Re: transforming fron (x, y, z) to (x, y)

    Originally posted by V-man:
    [...] but seems as if both my code and gluUnProject() have problems (I'm not getting the right numbers)
    So why should I trust your reply to my question on gluUnProject, in the topic I posted???
    AT LEAST YOU SHOULD HAVE TOLD ME!! HOPE YOU DO NEXT TIME
    --
    Paolo M.

  5. #5
    Junior Member Regular Contributor
    Join Date
    Feb 2000
    Posts
    154

    Re: transforming fron (x, y, z) to (x, y)

    Yea.. Forgot about that. And fov must also be accounted for somehow..

    No its probably easier (or more accurate) to ask OpenGL where a certain xyz coord will "land on screen".

    But that I haven't done. So I'll shut up now!..

  6. #6
    Junior Member Newbie
    Join Date
    Feb 2000
    Location
    Mallorca, Spain
    Posts
    1

    Re: transforming fron (x, y, z) to (x, y)

    You only have to multiply the desired vertex by the eye matrix. You will obtain the screen coordinates in the x,y of the new vertex.
    Also, you can multiply the first vertex by the modelview matrix before, if you have changed it.

  7. #7
    Junior Member Newbie
    Join Date
    Jan 2002
    Location
    Worcester,MA,USA
    Posts
    16

    Re: transforming fron (x, y, z) to (x, y)

    Hi get a load of my answer, it's going to be where you put it. make a card board model of
    3D space, use 3 pieces put together as left-hand 3d space. study it try my figure make your own

    glBegin(GL_Lines) etc...
    glVertex(x,y,z); <--6.0,4.0,2.0
    glVertex(x,y,z); <--2.0,-4.0,3.3 (-4.0=-Y value of 4.0 on negative real based on local 0.0.0)

    Reference 'local origin' best way there is other ways end up with floopy animations or poor ploting accuracy
    +y
    | /-Z
    | /
    -X___ |/________+x
    /
    /|
    / | -4.0 belongs to this real(-y)
    +Z |
    -y


    [This message has been edited by o9i8 (edited 01-25-2002).]
    opngl

  8. #8
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Jul 2000
    Location
    S41.16.25 E173.16.21
    Posts
    2,407

    Re: transforming fron (x, y, z) to (x, y)

    are u supplying the correct Z value to gluunproject, (ive never had problems with it)

  9. #9
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,982

    Re: transforming fron (x, y, z) to (x, y)

    Hey, this thread is almost two years old!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •