资源简介
基于openGL的四种直线裁减算法,cohen-sutherland算法,中点分割裁剪算法,梁友栋算法,beck算法。
代码片段和文件信息
// Cys-Beck算法.cpp: 定义控制台应用程序的入口点。
//
#include // use as needed for your system
#include
#include
#include
//********* Data structure
struct GLintPoint //描述点的结构体 整型
{
GLint x y;
};
struct GLfloatPoint //描述点的结构体 浮点型
{
GLfloat x y;
};
const int MAX = 100;
class GLintPointArray //类型为GLintPoint的数组类
{
public:
int num; //计数
GLintPoint point[MAX]; //数组
};
class GLfloatPointArray //类型为GLfloatPoint的数组类
{
public:
int num;
GLfloatPoint point[MAX];
};
//********** Support subprograms
typedef GLfloat colorType[3]; //点的颜色值
void drawDot(GLint x GLint y GLfloat r GLfloat g GLfloat b)
{
glColor3f(r g b);
glBegin(GL_POINTS);
glVertex2i(x y);
glEnd();
}
void drawIntPolygon(GLintPointArray P colorType c)
{
glColor3fv(c);
glBegin(GL_LINE_LOOP);
for (int i = 0; i glVertex2i(P.point[i].x P.point[i].y);
glEnd();
}
void drawFloatPolygon(GLfloatPointArray P colorType c)
{
glColor3fv(c);
glBegin(GL_LINE_LOOP);
for (int i = 0; i < P.num; i++)
glVertex2f(P.point[i].x P.point[i].y);
glEnd();
}
//**************** myInit
void myInit(void)
{
glClearColor(1.0 1.0 1.0 0.0); // set white background color
glColor3f(0.0f 0.0f 0.0f); //default color
//glPointSize(2.0); // a ‘dot‘ is 4 by 4 pixels
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0 640.0 0.0 480.0);
}
//************** drawing subprograms go here
const int MaxN = 100;
typedef GLfloatPoint Normals[MaxN]; //数组
void buildfloatPolygon(GLfloatPointArray &P)
{
P.num = 5;
P.point[0].x = 100; P.point[0].y = 100;
P.point[1].x = 400; P.point[1].y = 100;
P.point[2].x = 400; P.point[2].y = 300;
P.point[3].x = 250; P.point[3].y = 400;
P.point[4].x = 100; P.point[4].y = 300;
}
float DotProduct(GLfloatPoint v1 GLfloatPoint v2)//两向量的乘积
{
return v1.x*v2.x + v1.y*v2.y;
}
void CalcNormals(GLfloatPointArray p Normals & n)//求每个顶点的内法矢
{
int i j k;
GLfloatPoint v;
for (i = 0; i < p.num; i++)
{
j = (i + 1) % p.num;
k = (i + (int)p.num - 1) % p.num;
if ((p.point[j].x - p.point[i].x) == 0) { //特殊情况 边框平行与y
n[i].x = 1; n[i].y = 0;
}
else if ((p.point[j].y - p.point[i].y) == 0) {//特殊情况 边框平行于x
n[i].x = 0; n[i].y = 1;
}
else {//一般情况 边框有斜率
float q = -((p.point[j].y - p.point[i].y) / (p.point[j].x - p.point[i].x));
n[i].x = 1; n[i].y = 1 / q;
}
v.x = p.point[k].x - p.point[i].x;
v.y = p.point[k].y - p.point[i].y;
if (DotProduct(n[i] v) < 0) //通过求向量乘积来判断求的是内法矢量还是外法矢量
{
n[i].x *= -1;
n[i].y *= -1;
}
}
}
void CBClip(GLfloatPoint p1 GLfloatPoint p2 Normals &n GLfloatPointArray p
bool & visible GLfloatPoint & ps GLfloatPoint & pe) //Beck裁减算法
{
float t1 t2 t; //t1是下限最小值 t2是上限最大值
GLfloatPoint D w;//D=P2-P1 W=P1-fi
int i;
t1 = 0.0;
t2 = 1.0;
D.x = p2.x - p1.x;
D.y = p2.y - p1.y;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-05-24 19:11 ComputerGraphicsexci5\
目录 0 2018-05-24 19:11 ComputerGraphicsexci5\Beck算法\
文件 5545 2018-05-22 17:30 ComputerGraphicsexci5\Beck算法\Beck.cpp
文件 4021 2018-05-21 21:33 ComputerGraphicsexci5\Beck算法\Beck算法.vcxproj
文件 945 2018-05-21 21:33 ComputerGraphicsexci5\Beck算法\Beck算法.vcxproj.filters
目录 0 2018-05-24 19:11 ComputerGraphicsexci5\Beck算法\Debug\
文件 175581 2018-05-22 20:57 ComputerGraphicsexci5\Beck算法\Debug\Beck.obj
文件 1357 2018-05-22 20:57 ComputerGraphicsexci5\Beck算法\Debug\Beck算法.Build.CppClean.log
文件 1656 2018-05-22 20:57 ComputerGraphicsexci5\Beck算法\Debug\Beck算法.log
目录 0 2018-05-24 19:11 ComputerGraphicsexci5\Beck算法\Debug\Beck算法.tlog\
文件 208 2018-05-22 20:57 ComputerGraphicsexci5\Beck算法\Debug\Beck算法.tlog\Beck算法.lastbuildstate
文件 29412 2018-05-22 20:57 ComputerGraphicsexci5\Beck算法\Debug\Beck算法.tlog\CL.read.1.tlog
文件 780 2018-05-22 20:57 ComputerGraphicsexci5\Beck算法\Debug\Beck算法.tlog\CL.write.1.tlog
文件 790 2018-05-22 20:57 ComputerGraphicsexci5\Beck算法\Debug\Beck算法.tlog\cl.command.1.tlog
文件 1450 2018-05-22 20:57 ComputerGraphicsexci5\Beck算法\Debug\Beck算法.tlog\li
文件 3538 2018-05-22 20:57 ComputerGraphicsexci5\Beck算法\Debug\Beck算法.tlog\li
文件 758 2018-05-22 20:57 ComputerGraphicsexci5\Beck算法\Debug\Beck算法.tlog\li
文件 723968 2018-05-22 20:57 ComputerGraphicsexci5\Beck算法\Debug\vc120.idb
文件 405504 2018-05-22 20:57 ComputerGraphicsexci5\Beck算法\Debug\vc120.pdb
目录 0 2018-05-24 19:11 ComputerGraphicsexci5\CohenSotherland\
文件 4085 2018-05-05 18:16 ComputerGraphicsexci5\CohenSotherland\CohenSotherland.vcxproj
文件 956 2018-05-05 18:16 ComputerGraphicsexci5\CohenSotherland\CohenSotherland.vcxproj.filters
文件 2615 2018-05-08 17:26 ComputerGraphicsexci5\CohenSotherland\CohenSutherLAND.cpp
目录 0 2018-05-24 19:11 ComputerGraphicsexci5\CohenSotherland\Debug\
文件 1733 2018-05-08 21:33 ComputerGraphicsexci5\CohenSotherland\Debug\CohenSotherland.log
文件 15491 2018-05-08 21:33 ComputerGraphicsexci5\CohenSotherland\Debug\CohenSutherLAND.obj
文件 1458 2018-05-08 21:33 ComputerGraphicsexci5\CohenSotherland\Debug\CohenSutherland.Build.CppClean.log
目录 0 2018-05-24 19:11 ComputerGraphicsexci5\CohenSotherland\Debug\CohenSutherland.tlog\
文件 2844 2018-05-08 21:33 ComputerGraphicsexci5\CohenSotherland\Debug\CohenSutherland.tlog\CL.read.1.tlog
文件 896 2018-05-08 21:33 ComputerGraphicsexci5\CohenSotherland\Debug\CohenSutherland.tlog\CL.write.1.tlog
文件 208 2018-05-08 21:33 ComputerGraphicsexci5\CohenSotherland\Debug\CohenSutherland.tlog\CohenSutherland.lastbuildstate
............此处省略90个文件信息
- 上一篇:微信竞猜游戏 H5在线竞猜源码完整版
- 下一篇:ACS800说明书
相关资源
- Computer graphics with opengl 4th edition 计算
- 程序员的自我修养 装载,链接,库
- 山东大学计算机图形学实验课程资源
- 一个基于easypr的车牌识别demo
- QT Creator快速入门(第3版 高清PDF)
- 计算机图形学(OpenGL版)第3版.pdf
- VS2015编译的OpenCV4.1.2
- 基于余数系统的sm2白盒数字签名
- OpenGL SuperBible 7 pdf
- Qt Creator快速入门(第三版)
- OpenGL编程指南(原书第8版) + OpenGL超
- 海康CH-HCNetSDKV5.3.6.30sdk_Win32_Win64.zip
- 《QT5开发及》教程配套
- 西电-面向对象课件褚华老师所著
- VS2017OpenGL 配置步骤
- 基于DirectX的简单GUI界面制作
- Game development and simulation with Unreal te
- Visual Studio 2017 符号文件
- bmp格式图片缩小
- 猫版马里奥VC工程源代码Visual Studio
- 基于MongoDB电子考试系统项目实践
- 读OBJ模型,加载多纹理
- OpenGL红宝书第七版带目录完整版PDF+源
- opengl自定义函数实现平移旋转缩放
- OpenGL 3D场景绘制 SiriusPrx 荒岛古堡.r
- OpenGL一个室内三维渲染OBJ文件导入和
- NeHe OpenGL Qt4教学代码
- Opengl 蘑菇、萤火虫、地形三维建模
- 计算机算法设计与分析第三版.pdf
- OPENGL纹理贴图正方体
评论
共有 条评论