写三种画直线的方法,任意选择一种,实现鼠标点击两个点,使其连成一条线
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<gl\glut.h>
using namespace std;
int m0, m1, n0, n1;//声明全局变量,起始坐标和终止坐标
//int winwidth = 1024, winheight = 720;//窗口长宽
int winwidth = 800, winheight = 500;//窗口长宽
void DrawLine(); //实际上画直线的函数
void DDALine(int, int, int, int);
void MidpointLine(int, int, int, int);
void BresenhamLine(int, int, int, int);
//数据交换
void swap(GLint& a, GLint& b) { GLint t = a; a = b; b = t; }
//在屏幕上画一个点
void setPixel(GLint x, GLint y)
{
glBegin(GL_POINTS);
glVertex2i(x, y);
glEnd();
}
//实际上画直线的函数
void DrawLine() {
/*自己选择要用的方法*/
//DDALine(m0, n0, m1, n1); //DDA画线法
//MidpointLine(m0,n0,m1,n1);//中点划线法
BresenhamLine(m0, n0, m1, n1);//BresenhamLine算法
}
/*DDA画线法*/
void DDALine(int x0, int y0, int x1, int y1)
{
glClear(GL_COLOR_BUFFER_BIT);//清除窗口显示内容
int dx, dy, steps, i;
float x, y, delta_