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 7 of 7

Thread: Vector from Vertex to Viewer

  1. #1
    Junior Member Regular Contributor
    Join Date
    Feb 2000
    Posts
    122

    Vector from Vertex to Viewer

    My objects and the viewer are moving and rotating around in an OpenGL-Scene. In that scene I want to draw particles as textures on a square (blended). To avoid distortions the squares have always to face the viewer. I know how to undo these rotations but that needs a lot of matrix multiplications. I think it would be much easier to set up the squares with the correct coordinates. So I need a vector from a point in 3D-space to the actual viewer or at least perpendicular to the viewing plane (distance is also intereting). Can anyone help?

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

    Re: Vector from Vertex to Viewer

    Hello Marc

    Creating a vector from one point to another is not to complicated. Let's say Px, Py and Pz is the point in 3d space you want a vector to, and Cx, Cy, Cz is the camera position.

    Vx = Px - Cx
    Vy = Py - Cy
    Vz = Pz - Cz

    ...where Vx, Vy, Vz is the vector FROM camera TO a point.

    If you want the square to always face the camera, you can use this vector as the squares normal.

    You said the distance was important. You can get the distance with sqrt(Vx*Vx + Vy*Vy + Vz*Vz)...

    Now, please don't ask me about how to setup the square to actually face the camera, cause i don't know that :P

    Bob

  3. #3

    Re: Vector from Vertex to Viewer

    I would use the matrix stuff... All the squares are facing in the same direction, so you can use a single inverse rotation matrix to rotate all of them. I mean, no need to calculate the same matrix for each particle.

    [This message has been edited by Hude (edited 03-01-2000).]

  4. #4
    Junior Member Regular Contributor
    Join Date
    Feb 2000
    Posts
    122

    Re: Vector from Vertex to Viewer

    Bob, getting a vector out of two points is not the Problem, but to get the coordinates of these two points is the problem (at least for me). How can I bring OpenGL to tell me, where a given point is locatet after several transformations? I don't want to do the matrix stuff by myself, because I think the OGL-drivers can do a better job by using MMX/ISSE/3DNow!

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

    Re: Vector from Vertex to Viewer

    Hude, is there something like glStoreMatrix? I saw only LoadMatrix and MultMatrix. At the moment I compile a displaylist with the rotations in it, but I'm not sure if that helps (no performance improvement).

  6. #6

    Re: Vector from Vertex to Viewer

    No, there is no such thing as glStoreMatrix or equivalent. And you can't get OpenGL tell where any transformed point is located in view space. So, this leaves you with two alternatives: 1) use OpenGL rotations, 2) make your own rotations.

  7. #7
    Junior Member Regular Contributor
    Join Date
    Feb 2000
    Posts
    122

    Re: Vector from Vertex to Viewer

    I think, that I have to use OpenGL rotations, too. But yesterday I found something like glStoreMatrix:

    glGetDoublev(GL_MODELVIEW_MATRIX, PointerToArrayWith16GLdouble)
    and
    glGetDoublev(GL_PROJECTION_MATRIX, PointerToArrayWith16GLdouble)

    there is a float-version, too (just for information, to whom it may concern ).

    Thank you for your time.

Posting Permissions

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