資源簡(jiǎn)介
計(jì)算機(jī)輔助幾何設(shè)計(jì)之Bezier曲線(任意次數(shù))程序?qū)崿F(xiàn),并可用鼠標(biāo)左鍵進(jìn)行屏幕選點(diǎn),利用右鍵選中某一控制點(diǎn)并拖動(dòng)控制點(diǎn)實(shí)時(shí)改變Bezier曲線形狀。
代碼片段和文件信息
//?bezier.cpp?:?定義控制臺(tái)應(yīng)用程序的入口點(diǎn)。
//
#include?“stdafx.h“
int?_tmain(int?argc?_TCHAR*?argv[])
{
return?0;
}
#include?????
#include?????
#include?????
#include???
#include????
#include?
using?namespace?std;
int?SCREEN_HEIGHT?=?480;
int?NUMPOINTS?=?0;
class?Point
{
public:
float?x?y;
void?setxy(float?x2?float?y2)
{
x?=?x2;
y?=?y2;
}
Point??operator&(const?Point?&?rPoint)
{
x?=?rPoint.x;
y?=?rPoint.y;
return?*this;
}
};
int?n=0;
Point?*abc?=?new?Point[n];
double?*a?=?new?double[n];
void?myInit()
{
glClearColor(0.0?0.0?0.0?0.0);
glColor3f(1.0f?0.0?0.0);
glPointSize(4.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0?640?0.0?480.0);
}
void?drawDot(Point?pt)
{
glBegin(GL_POINTS);
glVertex2f(pt.x?pt.y);
glEnd();
glFlush();
}
void?drawLine(Point?p1?Point?p2)
{
glBegin(GL_LINES);
glVertex2f(p1.x?p1.y);
glVertex2f(p2.x?p2.y);
glEnd();
glFlush();
}
int?fac(int?k)
{
int?s?=?1;
if?(k?==?0)
{
s=?1;
}
else?
{
????for?(int?i?=?1;?i?<=?k;i++)
???{
???s?=?s*i;
???}
}
return?s;
}
void?displayImage(void)
{ //畫出包含控制點(diǎn)的B樣條曲線
glClear(GL_COLOR_BUFFER_BIT);
glPointSize(1.0);
glColor3f(1.0?0.0?0.0);
}
Point?drawBezier(int?N?double?t)
{
Point?P;
for?(int?i?=?0;?i? {
a[i]=(fac(N-1)/(fac(i)*fac(N?-1-?i)))*pow(ti)*pow(1-tN-i-1);
}
P.x?=?0;
P.y?=?0;
for?(int?i?=?0;?i? {
P.x?=?P.x?+?a[i]?*abc[i].x;
P.y?=?P.y?+?a[i]?*abc[i].y;
}
return?P;
}
bool?onmove;
int?controlIndex?=?0;
int?isDot(int?x?int?y)?{?//判斷是否為控制點(diǎn)??
int?i;
y?=?480.0?-?y;
for?(i?=?0;?i? if?((x?-?abc[i].x)*(x?-?abc[i].x)?+?(y?-?abc[i].y)*(y?-?abc[i].y)?<=16)
???????{
controlIndex?=?i;
return?controlIndex;
}
/*else?return?n+1;*/
}
void?mousemove(int?xmove?int?ymove){
glEnable(GL_COLOR_LOGIC_OP);??
glLogicOp(GL_XOR);
glClear(GL_COLOR_BUFFER_BIT);
abc[controlIndex].x?=?xmove;
abc[controlIndex].y?=?480.0?-?ymove;
glColor3f(0.0?1.0?0.0);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
for?(int?i?=?0;?i? {
????????glVertex2f(abc[i].x?abc[i].y);
}
glEnd();
?????for?(int?j?=?0;?j?(n?-?1);?j++)
{
drawLine(abc[j]?abc[j?+?1]);
}
Point?POld?=?abc[0];
for?(double?t?=?0.0;?t?<=?1.0;?t?+=?0.01)
{
Point?P?=?drawBezier(n?t);
drawLine(POld?P);
POld?=?P;
}??
glFlush();
}
void?myMouse(int?button?int?state?int?x?int?y)
{
switch?(button)?{
case?GLUT_LEFT_BUTTON:
if?(state?==?GLUT_DOWN) {
abc[NUMPOINTS].x?=?x; abc[NUMPOINTS].y?=?480.0?-?y;
NUMPOINTS++;
if?(NUMPOINTS?>?n)
{
return;
}
}
if?(NUMPOINTS?==?n)
{
glColor3f(1.0?0.0?1.0);
for?(int?i?=?0;?i? {
drawDot(abc[i]);
}
glColor3f(0.0?1.0?0.0);
for?(int?j?=?0;?j?(n?-?1);?j++)
{
dra
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-12-01?18:06??bezier(OpenGL版)\
?????目錄???????????0??2017-09-19?00:23??bezier(OpenGL版)\Debug\
?????文件???????76288??2017-12-01?17:57??bezier(OpenGL版)\Debug\bezier.exe
?????文件??????429596??2017-12-01?17:57??bezier(OpenGL版)\Debug\bezier.ilk
?????文件?????2248704??2017-12-01?17:57??bezier(OpenGL版)\Debug\bezier.pdb
?????目錄???????????0??2017-12-01?17:57??bezier(OpenGL版)\bezier\
?????目錄???????????0??2017-12-01?17:57??bezier(OpenGL版)\bezier\Debug\
?????文件????????1577??2017-12-01?17:57??bezier(OpenGL版)\bezier\Debug\bezier.log
?????文件??????175879??2017-12-01?17:57??bezier(OpenGL版)\bezier\Debug\bezier.obj
?????文件?????2359296??2017-09-19?12:30??bezier(OpenGL版)\bezier\Debug\bezier.pch
?????目錄???????????0??2017-12-01?17:57??bezier(OpenGL版)\bezier\Debug\bezier.tlog\
?????文件???????25598??2017-12-01?17:57??bezier(OpenGL版)\bezier\Debug\bezier.tlog\CL.read.1.tlog
?????文件?????????874??2017-12-01?17:57??bezier(OpenGL版)\bezier\Debug\bezier.tlog\CL.write.1.tlog
?????文件?????????166??2017-12-01?17:57??bezier(OpenGL版)\bezier\Debug\bezier.tlog\bezier.lastbuildstate
?????文件????????2642??2017-12-01?17:57??bezier(OpenGL版)\bezier\Debug\bezier.tlog\cl.command.1.tlog
?????文件????????2284??2017-12-01?17:57??bezier(OpenGL版)\bezier\Debug\bezier.tlog\li
?????文件????????3058??2017-12-01?17:57??bezier(OpenGL版)\bezier\Debug\bezier.tlog\li
?????文件?????????460??2017-12-01?17:57??bezier(OpenGL版)\bezier\Debug\bezier.tlog\li
?????文件???????11542??2017-09-19?12:30??bezier(OpenGL版)\bezier\Debug\stdafx.obj
?????文件?????1002496??2017-12-01?17:57??bezier(OpenGL版)\bezier\Debug\vc120.idb
?????文件??????495616??2017-12-01?17:57??bezier(OpenGL版)\bezier\Debug\vc120.pdb
?????文件????????1503??2017-09-07?12:37??bezier(OpenGL版)\bezier\ReadMe.txt
?????文件????????4129??2017-12-01?17:57??bezier(OpenGL版)\bezier\bezier.cpp
?????文件????????4531??2017-09-07?12:37??bezier(OpenGL版)\bezier\bezier.vcxproj
?????文件????????1313??2017-09-07?12:37??bezier(OpenGL版)\bezier\bezier.vcxproj.filters
?????文件?????????212??2017-09-07?12:37??bezier(OpenGL版)\bezier\stdafx.cpp
?????文件?????????234??2017-09-07?12:37??bezier(OpenGL版)\bezier\stdafx.h
?????文件?????????236??2017-09-07?12:37??bezier(OpenGL版)\bezier\targetver.h
?????文件????33423360??2017-12-01?18:06??bezier(OpenGL版)\bezier.sdf
?????文件?????????964??2017-09-07?12:37??bezier(OpenGL版)\bezier.sln
?????文件???????20992??2017-12-01?18:06??bezier(OpenGL版)\bezier.v12.suo
............此處省略5個(gè)文件信息
評(píng)論
共有 條評(píng)論