Mail Archives: djgpp/1997/05/04/17:45:05
Tudor writes:
>Does NE1 know how the clipping of a 3d poly should be implemented?
I don't know of any net resources that cover this, but it's explained
very well in Foley & Van Damme, "Computer Graphics: Principles and
Practice". IMHO, that book is absolutely indispensable...
>I'm not talking of the clipping to a plane in the world, Im talking of
>doing some clipping to the poly when it is in the drawing function. For
>example if I draw a big circle close to an edge, the circle routine will
>clip and the program won't crash. Try doin this with a 3d poly...
Allegro does clip 3d polygons to the screen area, but such 2d clipping
is prone to all sorts of problems. Most seriously, it totally breaks
down if any of the vertices lie behind the camera, as the perspective
projection will output the wrong 2d vertex positions. Also if the Z
value is very small you are going to get either a division by zero or an
abnormally large vertex position, which is also going to cause trouble.
So the clipping has to be done in 3d space, before the projection onto
the screen...
>So if the polygon3d() function could do the clipping, it's cool. If not,
>I'm willing to code the routine if someone will care to explain how to
>do it. I was thinking of doin it in 2d after the perspective projection
The usual approach is to clip your polygons to a standard viewing
region, just before the perspective projection. This is most often the
pyramid formed by the planes x=z, x=-z, y=z, and y=-z (using the Allegro
coordinate system where z increases with depth into the screen). You
will also need a near clipping plane, z=n (some small constant), and
maybe also a far plane to prevent ridiculously distant objects from
getting drawn, z=f (some large constant).
The Allegro get_camera_matrix() function will transform points into this
standard space, so your rendering code would probably look something
like:
for each polygon:
apply camera matrix
clip
perspective project
draw the poly
repeat
>with respect to the screen limits, but since we're talkin about 3d
>textured polys, I got no ideea how to change the texture coords
>accordingly.
You just need to interpolate between the existing values. If you have
two vertices A and B, where A is visible but B isn't, the clip function
will need to create a temporary vertex C, somewhere in between A and B.
It's a simple linear interpolation, eg. if C lies X of the way between A
and B:
C.u = (A.u * (1-X)) + (B.u * X);
Likewise for the v coordinate, z value, gouraud shade colors, etc. Which
values need interpolating will obviously depend on which mode the
polygon is going to be rendered with...
--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
Beauty is a French phonetic corruption of a short cloth neck ornament.
- Raw text -