Game Development Reference
In-Depth Information
Table 2.1
Codes
0
1
2
4
5
6
8
9
10
0
0
0
0
0
0
0
0
0
0
1
0
1
0
0
1
0
0
1
0
2
0
0
2
0
0
2
0
0
2
4
0
0
0
4
4
4
0
0
0
5
0
1
0
4
5
4
0
1
0
6
0
0
2
4
4
6
0
0
2
8
0
0
0
0
0
0
8
8
8
9
0
1
0
0
1
0
8
9
8
10
0
0
2
0
0
2
8
8
10
A table of values for a bitwise And-ing of the start and end point codes
will help in the understanding of the result of this operation (Table 2.1).
Looking at Table 2.1, we can see that if the start point is in section 1 and
the end point is in section 5, then the result of a bitwise And-ing is 1; since
this is not zero the function returns FALSE, indicating that there is nothing
to draw. If the bitwise test results in a zero value then the aim of the
remainder of the function is to determine where the line crosses the
canvas area and return both a TRUE to indicate that drawing is required
and revised values for xs , ys , xe and ye that are within the canvas
area.
To adjust the start and end points we use the slope or gradient of the
line that we have calculated and stored as the variable m . If the code
value for the point when And-ed with 8 does not equal zero, then the point
must be off to the left; in this case we aim to set x to 0, but what value
should we store for y ? Here we use the fact that we have added - x to the
y value, so we must subtract x times the slope of the line to y . Similar