openGL实现简单的鼠标键盘事件操作

本文介绍了一个使用OpenGL实现的多边形编辑器,用户可以通过鼠标和键盘进行绘制、删除和移动点的操作。当按下'b'键开始绘制,'d'键删除指定点,'m'键移动点,'r'键刷新屏幕,'q'键退出程序。编辑过程包括在画布上动态绘制线条,移动顶点以及删除顶点并重新连接线段。
摘要由CSDN通过智能技术生成

There are some bugs in my program.

Polyline Editor:
Using a mouse and keyboard to do polyline editing.
在这里插入图片描述
(a) A house in the process of being drawn. The user has just clicked at the position drawn, and a line has been drawn from the previous point to the one designated by the mouse.
(b) Moving a point. The user positions the cursor near the vertex of some polyline, presses down the mouse button, and “drags” the chosen point to some other location before releasing the button. Upon release of the button, the previous lines connected to this point are erased, and new lines are drawn to it.
© A point is deleted from a polyline. The user clicks near the vertex of some polyline, and the two line segments connected to that vertex are erased. Then the two other endpoints of the segments just erased are connected with a line segment.

The functionality of the program should include the following “actions”:

Begin (‘b’) (create a new polyline)
Delete (‘d’) (delete the next point pointed to)
Move (‘m’) (drag the point pointed to to a new location)
Refresh (‘r’) (erase the screen and redraw all the polylines)
Quit (‘q’) (exit from the program)

#include<Windows.h>
#include<gl/glut.h> 
#include<math.h>
#include<iostream>
#include<vector>
using namespace std;

int signal;

const int screenWidth = 1200;
const int screenHeight = 800;
const int windowPositionX = 100;
const int windowPositionY = 100;

class Point{
   
public:
	double x;
	double y;
	Point(double x, double y){
   
		this->x = x;
		this->y = y;
	}
	Point(){
   
	}
};

class Node{
   
public:
	Point p;
	Node *next;
	Node *last;
	Node(Point t):p(t.x, t.y){
   
		next = this;
		last = this;
	}
};
Node* operateNode;

class List{
   
public:
	Node *head;
	int length;
	List(){
   
		length = 0;
		head = NULL;
	}
	void push(Point newp){
   
		Node *cur = new Node(newp);
		cur->p = newp;
		if (this->length == 0){
   
			cur->next = cur;
			cur->last = cur;
			this->head = cur;
		} else{
   
			if (head == NULL)cout << "Impossible !!!!***********" << endl;
			cur->last = this->head;
			cur->next = this->head->next;
			this->head->next->last = cur;
			this->head->next = cur;
			this->head = cur;
		}
		this->length++;
	}
	Node *search(Point p){
   
		Node *cur = this->head;
		while (1){
   
			if (cur->p.x == p.x && cur->p.y == p.y){
   
				break;
			}
			else{
   
				cur = cur->next;
			}
		}
		return cur;
	}
	void show(){
   
		cout << "this list shows:" << endl;
		cout << "head:" << this->head << endl;
		Node *curr = this->head;
		do{
   
			if (curr == this->head)cout << "H";
			cout << "(" << curr->p.x << "," << curr
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值