Graphics Reference
In-Depth Information
integer function ExtendedCsCode ( pnt2d p)
{ The Maillot extension of the Cohen-Sutherland encoding of points }
begin
if p.x < clipRegion[0].x then
begin
if p.y > clipRegion[3].y then return (6 or TWOBITS);
if p.y < clipRegion[0].y then return (12 or TWOBITS);
return (4);
end ;
if p.x > clipRegion[3].x then
begin
if p.y > clipRegion[3].y then return (3 or TWOBITS);
if p.y < clipRegion[0].y then return (9 or TWOBITS);
return (1);
end ;
if p.y > clipRegion[3].y then return (2);
if p.y < clipRegion[0].y then return (8);
return (0);
end ;
Algorithm 3.3.4.3.
An extended clipping code function.
used. This function adds the extra bit (TWOBITS), which we talked about. Within the
Cohen-Sutherland clipping the extra bit should be ignored.
Two functions in the Maillot algorithm, Algorithm 3.3.4.2, make use of Cohen-
Sutherland clipping:
CS_StartClip: This function defines global variables
startPt - the first point of the input polygon
startC - the extended Cohen-Sutherland code for startPt
and returns values SEGM or NOSEGM, where
SEGM means that the point is inside the clipping region
NOSEGM means that the point is outside the clipping region
CS_EndClip ( integer i): This function uses the global variables startC0 and
startPt, clips the segment [startPt,ith point of polygon],
and defines the global variables
startC, endC - the extended Cohen-Sutherland code for the start and end-
point, respectively
startPt, endPt - these are the original endpoints if there was no clipping or
are the clipped points otherwise
The function returns values SEGM, SEGM or CLIP, or NOSEGM, where
Search WWH ::




Custom Search