1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
typedef int OutCode;
const int INSIDE = 0; // 0000
const int LEFT = 1; // 0001
const int RIGHT = 2; // 0010
const int BOTTOM = 4; // 0100
const int TOP = 8; // 1000
OutCode ComputeOutCode(vec3 p) //vec3 est un point (x,z,w)
{
OutCode code;
code = INSIDE; // initialised as being inside of clip window
if (p.z+p.x < 0) // to the left of clip window
code |= LEFT;
else if (p.z - p.x < 0) // to the right of clip window
code |= RIGHT;
if (p.z + p.y < 0) // below the clip window
code |= TOP;
else if (p.z - p.y < 0) // above the clip window
code |= BOTTOM;
return code;
}
void CohenSutherlandLineClipAndDraw(vec3 a, vec3 b)
{
int aOutCode = ComputeOutCode(a);
int bOutCode = ComputeOutCode(b);
if((aOutCode & bOutCode)!= 0)//reject line
cout << "rejected" <<endl;
if((aOutCode | bOutCode) == 0)//accepted line
cout << "accepted" <<endl;
} |
Partager