Graphics Reference
In-Depth Information
Assume that the world has been transformed to the coordinate system in which the
pixels on the screen correspond to the integer coordinate points of the rectangle
[XMIN,XMAX] ¥ [YMIN,YMAX] ¥ 0 and we are doing an orthogonal projection
(the camera is at -• on the z-axis). The function Depth(
p
) returns the z-coordinate
of the point
p
, and ix
p
will denote the x-coordinate of
p
rounded to the nearest
integer.
color array
COLOR[XMIN..XMAX]; { holds color of pixels on current scan line }
real array
DEPTH[XMIN..XMAX]; { holds z-value of point nearest to eye }
for
iy:=YMIN
to
YMAX
do
{ for each scan line of the screen }
begin
Initialize COLOR to the background color;
Initialize DEPTH to •;
for
each projected face F
do
if
F intersects the plane y = iy
then
begin
Let L be the line segment which is this intersection;
for each p
Œ L
do
if
Depth (
p
) < DEPTH [ix
p
]
then
begin
COLOR [ix
p
] := color of S;
DEPTH [ix
p
] := Depth (
p
);
end
end
;
Display COLOR;
end
;
Algorithm 7.7.2.
A scan line Z-buffer algorithm.
Figure 7.8.
Z-buffer spans.