Jump to content
  • Advertisement
Sign in to follow this  

liang barsky clipping in homogeneous coordinates

This topic is 4692 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I'm trying to write line clipping in homogeneous coordinates, and now I've troubles with Liang Barsky algorithm I've also wrote sutherland clipping in homog. coords and it works perfectly but now I've troubles with computing intersections point for Liang Barsky. Clipper works only if both points have the same W. ps. sorry for my english..

Share this post

Link to post
Share on other sites
Clipping still works the same as in regular space. If (x',y',z') in eye space, and if the frustum has near N, far F, left L, right R, bottom B, and top L, then the homogeneous mapping is a point (x,y,z,w) where

x = 2*x'/(R-L) - (R+L)*z'/(N*(R-L)); |x| <= w
y = 2*y'/(T-B) - (T+B)*z'/(N*(T-B)); |y| <= w
z = F*(z'/N - 1)/(F-N); 0 <= z <= F/N
w = z'/N; 1 <= w <= F/N

For clipping purposes, you look only at the (x,y,w) values. Suppose the line segment is (1-t)*(x0,y0,w0) + t*(x1,y1,w1) for 0 <= t <= 1. Consider one of the frustum planes: x = w. If x0 < w0 and x1 > w1, then there must be a point (x,y,w) on the line segment for which x = w. Compute this by setting (1-t)*x0 + t*x1 = (1-t)*w0 + t*w1, so t = (w0-x0)/[(x1-x0)-(w1-w0)]. Say this point is (x(t),y(t),w(t)), where x(t) = w(t).

Is the problem that you are also trying to linearly interpolate the z-value? You cannot use a clip value of z(t) = (1-t)z0+t*z1 because of the "affine" term in the transformation from z' to z. If you were to linearly interpolate, the z-value at the point of intersection would be

z(t) = (1-t)*z0+t*z1 = N*[(1-t)*w0+t*w1] = N*w(t)

However, using the z' to z mapping once you have computed w(t), the correct value is

z(t) = F*(w(t) - 1)/(F-N)

Just a note. When clipping against all the planes one at a time, you should do the clipping against w = 1 first to avoid the "singularity" at the xyw-origin.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!