View Full Version : intersection of a line and the viewport edges?
11-26-2001, 10:49 AM
I'm building a 3d data-viewer and wonder the best way to keep the axes labels (like
x, -x, y, -y, z, -z) in the viewport as the axes is rotated. Right now, keyboard arrow keys, etc, can rotate and zoom and labels are billboarded to always face front. But I need to know how to find out where the axes themselves intercept the edge of the window so I can put the lables in the right place. This seems difficult because it depends on the projection not just the data in the view. Any suggestions?
(I am using gluLookAt to "fly around" the axes, and I need to be able to switch between ortho and projective views.)
Thanks in advance. -Lorax
11-26-2001, 09:23 PM
you can easily using glProject and glUnproject functions find out where a point in "OpenGL space" actualy lies on screen and vice versa.
Then just find out the dimensions of your screen and look when the ending line goes out of screen, find intersection of this line with window edge and there place the letter.
glProject and glUnproject are very useful, you don't need to use them only when drawing something, you can also create your own matrix and they can find out for you both way transforming through these matrixes. No need for your own difficult computation.
hope it helps.
11-26-2001, 09:24 PM
sorry, it is "gluProject" and "gluUnProject"
11-27-2001, 10:14 AM
Thanks, Platinum, that helps alot!
After I posted my question, I began to see the problem as a classical clipping problem, that what you are looking for are the intersections of line segments (the axes) and their bouding box (or frustum). Now, I have no experinece with clipping, but it seems to me that that you would need to know the planes that form the bounding boxes then find the intersection of the lines with these planes. Now comes the tricky part: 6 planes are needed to describe a bounding volume, so each axis could need to be tested against up to 6 planes to fine the intersection. Ugh. Sounds awfully expensive. (I know because of the symmetries this could be reduced quite a bit, but still...)
Anyway, probably gluUnProject can be used to find the coodinates of the bounding volume by giving it the cornors of the window. I'd need to call it 4 times to get the upper left corner front and back and the lower right front and back.
However, how do I specify the "winZ" parameter to get the front and back planes? Anyone know? Is this always in the range 0 to 1?
Any good algorithms out there for this problem?
[This message has been edited by Lorax (edited 11-27-2001).]
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.