View Full Version : clipping
06-25-2004, 02:00 AM
I have to implement a clipping routine according to the opengl specification.
This what i've been doing so far:
1. clipped vertexes/triangles with the camera near/far plane after they have been transformed to camera space.
2. projected the vertexes
3. clipped against left/bottom/right/top plane.
Now i've read that with opengl all visible vertexes have to be within:
-w < x < w
-w < y < w
-w < z < w
my problem: i have no idea what this w is.
06-25-2004, 03:05 AM
Read the OpenGL Programming Guide (RedBook)Appendix F Homogenous Coordinates or any other 3D graphics book.
In general, w is the homogenous extension to 3D coordinates, which allows to put the translation into the same matrix as the other transformations.
The matrix gets 4x4 by this and all vertices (coordinates, 3d data) need to be expanded into 4D (x, y, z, w) by appending a w coordinate which is 1.0 for real points (0.0 for vectors).
The matrix4x4 * vector4 multiplication results in 4D coordinates now. This is where your post-transform w at each coordinate comes from and clipping is done with the above formulae before the vertices are reprojected into 3D space by dividing through w.
06-25-2004, 06:38 AM
thanks for the answer.
i've read sth. like this before
but didn't quite get it.
i multiply my projection matrix with the vertex vector ( x0, y0, z0, 1 ) and get a new vector
( x1, y1, z1, w1).
now this w i get is used to clip?
so i always clip to a perfect cube (2*w1 in all directions)?
if i do this i have different clipping planes for each vertex (with perspective projection w1=-z0)?
so my main problem with this is the fact that this w would differ from vertex to vertex.
or is this w something from my projectipon matrix?
06-25-2004, 08:01 AM
Yes, you got it.
You're working on coordinates which lie inside a viewing frustum.
It's a "cube" (still 4D) for each vertex in the clip coordinates, but w is different per vertex because of the perspective projection.
06-26-2004, 07:51 PM
I have read w as acting like this
glVertex4f(10.0,5.0,15.0,5.0);where the w argument(5.0) divides all of them doing this
07-04-2004, 11:33 PM
i've tried to get this to work but came across another problem:
now here is an example to better describe it:
i have 2 projected vertexes forming a line:
A (x1= -2.47, y1= 3.29, z1= -13.6, w1= 7)
B (x2= 4.94, y2= -13.18, z2= -4, w2= 15)
after checking them against the clipspace i find that A is in front of the near plane.
so i try to interpolate:
i calculate the ratio= ( -w1 - z1 ) / (z2 -z1) = ( -7+13.6) / ( -4+13.6) = 0.6875
now i apply it like this:
x_new = x1 + (x2-x1)*ratio
y_new = y1 + (y2-y1)*ratio = -8.0
z_new = nearPlane = -w1 = -7
w_new = w1 = 7
this way i get stuck with y_new = -8.0 which is below w_new and should therefor be below the bottom clipping plane.
since the y-values of both vertexes were within the clipping space my y_new should be within it as well.
so i guess i'm making some mistake during interpolation.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.