资源简介
鼠标选取关键点绘制曲线,可以鼠标对关键点进行拖拽,实现平移,旋转操作。
代码片段和文件信息
// curve.cpp : Defines the entry point for the console application.
//
#include “stdafx.h“
#include “GL/glut.h“
void init();
void keyboard(unsigned char key int x int y);
void drawCurves(void);
void curve_menu(int id);
void display(void);
void points_mouse(int button int state int x int y);
void reshape(int w int h);
void initLight(void);
#define MAX_CPTS 25 /* fixed maximum number of control points */
#define Bezier 1
#define Bspline 2
#define Bez3d 3
GLfloat cpts[MAX_CPTS][3];
int ncpts = 0;
static int width = 500 height = 500; /* window width and height */
GLint type=0;
GLfloat newcpts[MAX_CPTS][3];
static GLfloat xx=0.0;
static GLfloat yy=0.0;
static GLfloat zz=1.0;
static GLfloat theta[]={0.00.00.0};
static GLint axis=2;
//添加变量
double object_x = 0object_y = 0object_z = 0; //3D坐标
GLdouble winx winy winz; //2D坐标
int m_drawPos = -1;
bool isPro = false;
bool isRun = false;
/* Bez3d‘s control points*/
GLfloat points[4][4][3]={
{{-0.5-0.50.6}{-0.2-0.50.6}
{0.3-0.5-0.4}{0.5-0.50.6}}
{{-0.5-0.30.4}{-0.30.50.6}
{0.30.30.4}{0.5-0.3-0.5}}
{{-0.50.30.6}{-0.30.30.5}
{0.30.30.8}{0.5-0.50.5}}
{{-0.50.5-0.6}{-0.30.5-0.6}
{0.30.30.4}{0.50.5-0.5}}
};
void vmult(float m[4][4] float v[4][3] float r[4][3]){
int ijk;
for(i=0;i<4;i++)
for(j=0;j<3;j++)
{
r[i][j]=0;
for(k=0;k<4;k++)
r[i][j]+=m[i][k]*v[k][j];
}
}
static float mbspline[4][4]=
{
{1.0/6.0 4.0/6.0 1.0/6.0 0.0}
{0.0 4.0/6.0 2.0/6.0 0.0}
{0.0 2.0/6.0 4.0/6.00.0}
{0.0 1.0/6.0 4.0/6.0 1.0/6.0}
};
static float midentity[4][4]=
{
{1.0 0.0 0.0 0.0}
{0.0 1.0 0.0 0.0}
{0.0 0.0 1.0 0.0}
{0.0 0.0 0.0 1.0}
};
void computeMatrix(float m[][4])
{
for(int i = 0;i<4;i++)
for(int j = 0; j<4;j++)
{
m[i][j] = mbspline[i][j];
}
}
void init()
{
glClearColor(1.0 1.0 1.0 1.0);
glColor3f(0.0 0.0 0.0);
glPointSize(5.0);
glEnable(GL_MAP1_VERTEX_3);
glutAddMenuEntry(“Bezier“1);
glutAddMenuEntry(“Bspline“2);
glutAddMenuEntry(“Bez3d“3);
glutAddMenuEntry(“clear “4);
glutAddMenuEntry(“quit“5);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glEnable(GL_POINT_SMOOTH);
glEnable(GL_LINE_SMOOTH);
glHint(GL_POINT_SMOOTH_HINT GL_NICEST); // Make round points not square points
glHint(GL_LINE_SMOOTH_HINT GL_NICEST); // Antialias the lines
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA);
}
/* draw the three kinds of curves*/
void draw_Bezier()
{
int i;
for(i=0; i {
/* draw the curve using OpenGL evaluators */
glMap1f(GL_MAP1_VERTEX_3 0.0 1.0 3 4 cpts[i]);
glMapGrid1f(30 0.0 1.0);
glEvalMesh1(GL_LINE 0 30);
}
}
void DrawBspline()
{
int i=0;
int step;
flo
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10782 2010-01-31 22:09 curve\curve.cpp
文件 874 2010-01-19 21:52 curve\curve.sln
..A..H. 15360 2010-01-31 22:15 curve\curve.suo
文件 5855 2010-01-19 22:08 curve\curve.vcproj
文件 1427 2010-01-31 22:15 curve\curve.vcproj.CHINA-CC7F7FBC2.Administrator.user
文件 1202 2010-01-15 20:56 curve\ReadMe.txt
文件 292 2010-01-15 20:56 curve\StdAfx.cpp
文件 769 2010-01-15 20:56 curve\StdAfx.h
目录 0 2010-01-31 22:15 curve
----------- --------- ---------- ----- ----
36561 9
- 上一篇:NDIS的实现程序NDIS的实现程序
- 下一篇:stock data
评论
共有 条评论