1、编写程序实现Sutherland-Hodgeman 多边形裁剪算法。
#include<GL/glut.h>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
typedef struct
{
float x, y;
}wcPt2D;
typedef enum
{
Left, Right, Bottom, Top
}Boundary;
int Inside(wcPt2D p, Boundary b, wcPt2D wMin, wcPt2D wMax)
{
switch (b)
{
case Left:
if (p.x < wMin.x) return (false);
break;
case Right:
if (p.x > wMax.x) return (false);
break;
case Bottom:
if (p.y < wMin.y) return (false);
break;
case Top:
if (p.y > wMax.y) return (false);
break;
}
return true;
}
int Cross(wcPt2D p1, wcPt2D p2, Boundary b, wcPt2D wMin, wcPt2D wMax)
{
if (Inside(p1, b, wMin, wMax) == Inside(p2, b, wMin, wMax))
return (false);
else
return true;
}
wcPt2D Intersect(wcPt2D p1, wcPt2D p2, Boundary b, wcPt2D wMin, wcPt2D wMax)
{
wcPt2D iPt;
float m;
if (p1.x != p2.x) m = (p2.y - p1.y) / (p2.x - p1.x);
switch (b) {
case Left:
iPt.x