View Full Version : clipping the viewing volume

05-18-2006, 02:33 PM
I'm trying to implement OpenGL GPU Pipeline and got some troubles in clipping in the viewing volume: e.g.
I have line from V1(x1,y1,z1,w1)&V2(x2,y2,z2,w2) - clip coordinates - :
(ignore the ....)
V1 (x1,w1) o \
...................\ o V2 (x2,w2)
where x1>w1 and x2<w2 so I need to clip the line on x axis. I need to find t={x1-Xmax}/{x1-x2}, but what is W {Xmax}? How can I find him?

05-19-2006, 02:12 AM
Ok, in clipping space (post transformation) the coordinates are always in a cube of edge length 2 (from -1 to +1).

Said that, wouldn't be easier to find the clipping volume using some kind of plane-ray intersection?
I mean, take the ray (line) and test it against the 6 planes of the fustrum. Then you will have where the ray intersects with the fustrum(u should assume an infinite ray, so you should extend your segment to a ray).
Once you have that intersection you can clip as needed.

So, summarizing:

- Take your frustum from opengl (look at google for opengl frustum extraction)
- This frustum is in view space so:
-- Take your ray (in world coordinates) and multiply it by the modelview matrix
-- Test your ray against the frustum (you will get an intersection point P)
-- multiply P by the inverse of the modelview matrix (to return it to World coordinates)

Et voila, now you can do whatever you need with that point.

05-19-2006, 03:22 AM
IG, your artwork leaves very, very much to be desired, if you don't mind my saying so. Try using a "code" tag to preserve the formatting.

The unit cube clip-planes are in post-projective clip space, where they should be. I think you're suffering from a conceptual malady. A line in world-space is a line in post-projective clip space; a plane in world-space is a plane in post-projective clip-space. Either can be transformed into or out of either space. Of interest, consequently, is that they are both in the same space for clipping.