資源簡介
基于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? 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? {
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說明書
評論
共有 條評論