一、实验目的和要求
- 熟悉曲线的定义和相关性质、理解生成Bézier曲线的迭代算法;
- 使用鼠标在在屏幕中任意设置控制点,并生成曲线。
二、实验内容
利用迭代算法绘制Bézier曲线,并实现鼠标交互:鼠标点击左键出现控制点,达到3次后绘制Bézier曲线。
三、实验过程及代码
#include <math.h>
#include <gl/glut.h>
int SCREEN_HEIGHT = 480;//屏幕高度
// 跟踪鼠标点击次数,达到3次后绘制Bezier曲线
int NUMPOINTS = 0;
//点
class Point {
public:
float x, y;
void setxy(float x2, float y2) {
x = x2; y = y2; }
const Point & operator=(const Point &rPoint) {
x = rPoint.x;
y = rPoint.y;
return *this;
}
};
Point abc[3];
void myInit() {
glClearColor(0.0, 0.0, 0.0, 0.0);
glColor3f(1.0, 0.0,