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

Thread: 3D line segment to 2D pixel height?

  1. #1
    Intern Newbie
    Join Date
    Apr 2003
    Posts
    34

    3D line segment to 2D pixel height?

    Let's say I have a 3D line segment between two vertices. How do I work out the vertical extent of this line segment (i.e. its height in pixels or some other unit of measure) on my screen?

  2. #2
    Senior Member OpenGL Pro sqrt[-1]'s Avatar
    Join Date
    Jun 2002
    Location
    Australia
    Posts
    1,006

    Re: 3D line segment to 2D pixel height?

    Can't you just:
    v1 = vertex1
    v2 = vertex2

    Multiply v1 and v2 by the modelview matrix then multiply by the projection matrix to get into screen space. Then do the "w" divide on both and then get the difference in "y" coordinates. (This will get you coordinates in normalized screen space with 0,0 in the center of the screen. To get to pixels, add 1 and divide by two (x+1)/2 then multiply by the viewport pixel size. You may also have to flip the y coordinate first (1-y) to get 0,0 at the top of the viewport (if necessary))

Posting Permissions

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