计算机图形学 - 实验6 - Cohen Sutherland裁剪算法

实验六:2学时)


一、 实验目的:

理解Cohen-Sutherland裁剪算法

 

二、 实验内容:

实现Cohen-Sutherland编码线段裁剪算法,能看到裁剪前后的屏幕显示效果

 

三、 实现效果及步骤(或流程)


源码如下:

// test6.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"

#include<GL/glut.h>
#include<stdio.h>
#include<math.h> 

class Point
{
public:
	float x, y;
};

bool hasLine = true, cut = false;
float offset = 10;
int winWidth = 400, winHeight = 300;
Point clippingWindow[4], line[2], bound[4][2], inside[2];// 用于记录线段line位于裁剪窗口内的两个端点

// 初始化裁剪窗口的四个顶点坐标
void initClippingWindow(void)
{
	// 左上角
	clippingWindow[0].x = -100;
	clippingWindow[0].y = 100;

	// 左下角
	clippingWindow[1].x = -100;
	clippingWindow[1].y = -100;

	// 右下角
	clippingWindow[2].x = 100;
	clippingWindow[2].y = -100;

	// 右上角
	clippingWindow[3].x = 100;
	clippingWindow[3].y = 100;
}

// 绘制裁剪窗口
void drawClippingWindow(void)
{
	glColor3f(0, 0, 0);
	glBegin(GL_LINE_LOOP);
	for (int i = 0; i < 4; i++)
		glVertex2f(clippingWindow[i].x, clippingWindow[i].y);
	glEnd();
}

// 更新边界
void updateBound(void)
{
	// 由裁剪窗口的左上角顶点和左下角定点组成的线,即左边界
	bound[0][0] 
  • 10
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值