Bezier曲线(任意次数)程序实现可用鼠标选点并拖动控制点实时改变Bezier曲线形状
计算机辅助几何设计之Bezier曲线(任意次数)程序实现,并可用鼠标左键进行屏幕选点,利用右键选中某一控制点并拖动控制点实时改变Bezier曲线形状。
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 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版)Debugezier.exe
文件 429596 2017-12-01 17:57 bezier(OpenGL版)Debugezier.ilk
文件 2248704 2017-12-01 17:57 bezier(OpenGL版)Debugezier.pdb
目录 0 2017-12-01 17:57 bezier(OpenGL版)ezier
目录 0 2017-12-01 17:57 bezier(OpenGL版)ezierDebug
文件 1577 2017-12-01 17:57 bezier(OpenGL版)ezierDebugezier.log
文件 175879 2017-12-01 17:57 bezier(OpenGL版)ezierDebugezier.obj
文件 2359296 2017-09-19 12:30 bezier(OpenGL版)ezierDebugezier.pch
目录 0 2017-12-01 17:57 bezier(OpenGL版)ezierDebugezier.tlog
文件 25598 2017-12-01 17:57 bezier(OpenGL版)ezierDebugezier.tlogCL.read.1.tlog
文件 874 2017-12-01 17:57 bezier(OpenGL版)ezierDebugezier.tlogCL.write.1.tlog
文件 166 2017-12-01 17:57 bezier(OpenGL版)ezierDebugezier.tlogezier.lastbuildstate
文件 2642 2017-12-01 17:57 bezier(OpenGL版)ezierDebugezier.tlogcl.command.1.tlog
文件 2284 2017-12-01 17:57 bezier(OpenGL版)ezierDebugezier.tloglink.command.1.tlog
文件 3058 2017-12-01 17:57 bezier(OpenGL版)ezierDebugezier.tloglink.read.1.tlog
文件 460 2017-12-01 17:57 bezier(OpenGL版)ezierDebugezier.tloglink.write.1.tlog
文件 11542 2017-09-19 12:30 bezier(OpenGL版)ezierDebugstdafx.obj
文件 1002496 2017-12-01 17:57 bezier(OpenGL版)ezierDebugvc120.idb
文件 495616 2017-12-01 17:57 bezier(OpenGL版)ezierDebugvc120.pdb
文件 1503 2017-09-07 12:37 bezier(OpenGL版)ezierReadMe.txt
文件 4129 2017-12-01 17:57 bezier(OpenGL版)ezierezier.cpp
文件 4531 2017-09-07 12:37 bezier(OpenGL版)ezierezier.vcxproj
文件 1313 2017-09-07 12:37 bezier(OpenGL版)ezierezier.vcxproj.filters
文件 212 2017-09-07 12:37 bezier(OpenGL版)ezierstdafx.cpp
文件 234 2017-09-07 12:37 bezier(OpenGL版)ezierstdafx.h
文件 236 2017-09-07 12:37 bezier(OpenGL版)ezier argetver.h
文件 33423360 2017-12-01 18:06 bezier(OpenGL版)ezier.sdf
文件 964 2017-09-07 12:37 bezier(OpenGL版)ezier.sln
文件 20992 2017-12-01 18:06 bezier(OpenGL版)ezier.v12.suo
............此处省略5个文件信息
// bezier.cpp : 定义控制台应用程序的入口点。
//
#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)
{ //画出包含控制点的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 < N;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) { //判断是否为控制点
int i;
y = 480.0 - y;
for (i = 0; i < n; 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 < n; 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 < n; i++)
{
drawDot(abc[i]);
}
glColor3f(0.0 1.0 0.0);
for (int j = 0; j < (n - 1); j++)
{
dra
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 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版)Debugezier.exe
文件 429596 2017-12-01 17:57 bezier(OpenGL版)Debugezier.ilk
文件 2248704 2017-12-01 17:57 bezier(OpenGL版)Debugezier.pdb
目录 0 2017-12-01 17:57 bezier(OpenGL版)ezier
目录 0 2017-12-01 17:57 bezier(OpenGL版)ezierDebug
文件 1577 2017-12-01 17:57 bezier(OpenGL版)ezierDebugezier.log
文件 175879 2017-12-01 17:57 bezier(OpenGL版)ezierDebugezier.obj
文件 2359296 2017-09-19 12:30 bezier(OpenGL版)ezierDebugezier.pch
目录 0 2017-12-01 17:57 bezier(OpenGL版)ezierDebugezier.tlog
文件 25598 2017-12-01 17:57 bezier(OpenGL版)ezierDebugezier.tlogCL.read.1.tlog
文件 874 2017-12-01 17:57 bezier(OpenGL版)ezierDebugezier.tlogCL.write.1.tlog
文件 166 2017-12-01 17:57 bezier(OpenGL版)ezierDebugezier.tlogezier.lastbuildstate
文件 2642 2017-12-01 17:57 bezier(OpenGL版)ezierDebugezier.tlogcl.command.1.tlog
文件 2284 2017-12-01 17:57 bezier(OpenGL版)ezierDebugezier.tlogli
文件 3058 2017-12-01 17:57 bezier(OpenGL版)ezierDebugezier.tlogli
文件 460 2017-12-01 17:57 bezier(OpenGL版)ezierDebugezier.tlogli
文件 11542 2017-09-19 12:30 bezier(OpenGL版)ezierDebugstdafx.obj
文件 1002496 2017-12-01 17:57 bezier(OpenGL版)ezierDebugvc120.idb
文件 495616 2017-12-01 17:57 bezier(OpenGL版)ezierDebugvc120.pdb
文件 1503 2017-09-07 12:37 bezier(OpenGL版)ezierReadMe.txt
文件 4129 2017-12-01 17:57 bezier(OpenGL版)ezierezier.cpp
文件 4531 2017-09-07 12:37 bezier(OpenGL版)ezierezier.vcxproj
文件 1313 2017-09-07 12:37 bezier(OpenGL版)ezierezier.vcxproj.filters
文件 212 2017-09-07 12:37 bezier(OpenGL版)ezierstdafx.cpp
文件 234 2017-09-07 12:37 bezier(OpenGL版)ezierstdafx.h
文件 236 2017-09-07 12:37 bezier(OpenGL版)ezier argetver.h
文件 33423360 2017-12-01 18:06 bezier(OpenGL版)ezier.sdf
文件 964 2017-09-07 12:37 bezier(OpenGL版)ezier.sln
文件 20992 2017-12-01 18:06 bezier(OpenGL版)ezier.v12.suo
............此处省略5个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)