• 大小: 1.76MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-10-04
  • 语言: 其他
  • 标签: opengl  

资源简介

资源包括一个实验报告文档和源程序代码。输入点的个数,程序画出相应的贝塞尔曲线,交互操作通过控制每个点的移动从而改变贝塞尔曲线的形状

资源截图

代码片段和文件信息

#include
#include
#include

#define MAX 20
GLfloat ctrlpoints[MAX][3]={0.0};
//GLfloat ctrlpoints[3][3]={{-4.0-2.00.0}{-1.00.20.0}{4.0-2.30.0}};
int n;
void ctrlpointsInput(void)
{
int ij;
printf(“Please input the numbers of the control points:n= “);
scanf(“%d“&n);
printf(“Please input the control points: \n“);
for(i=0;i {
for(j=0;j<=2;j++)
scanf(“%f“&ctrlpoints[i][j]);
}
}

void myInit(void)
{   
ctrlpointsInput();
glClearColor(0.00.00.00.0); 
glShadeModel(GL_FLAT);  
}

void drawline(void)
{
glMap1f(GL_MAP1_VERTEX_30.01.03n&ctrlpoints[0][0]);
glEnable(GL_MAP1_VERTEX_3);
glColor3f(1.01.01.0);   
glBegin(GL_LINE_STRIP);     
for(int j=0;j<=60;j++)      
glEvalCoord1f((GLfloat)j/60.0); 
glEnd(); 
}

/*void redmark(int e)
{
int j=0;
glPointSize(5.0);
glBegin(GL_POINTS);
while(j!=e) j++;
glColor3f(1.00.00.0);
glVertex3fv(&ctrlpoints[j][0]);
glEnd();
glFlush();
}*/
void redmark(int e)
{
glPointSize(5.0);
glBegin(GL_POINTS);
glColor3f(1.01.00.0);
for(int j=0;j {
glColor3f(1.01.00.0);
glVertex3fv(&ctrlpoints[j][0]);
}
for(j=e+1;j {
glVertex3fv(&ctrlpoints[j][0]);
}
glColor3f(1.00.00.0);
glVertex3fv(&ctrlpoints[e][0]);
glEnd();
glFlush();
}

void myDisplay(void)
{  
int i;
    glClear(GL_COLOR_BUFFER_BIT); 
drawline();
glPointSize(5.0);  
glColor3f(1.01.00.0); 
glBegin(GL_POINTS);     
for(i=0;i glVertex3fv(&ctrlpoints[i][0]);
glEnd();  
glFlush();


void reshape(int wint h)
{  
glViewport(00(GLsizei)w(GLsizei)h); 
glMatrixMode(GL_PROJECTION); 
glLoadIdentity(); 
if(w<=h)   
glOrtho(-5.05.0-5.0*(GLfloat)h/(GLfloat)w5.0*(GLfloat)h/(GLfloat)w-5.05.0); 
else   
glOrtho(-5.0*(GLfloat)w/(GLfloat)h5.0*(GLfloat)w/(GLfloat)h-5.05.0-5.05.0); 
glMatrixMode(GL_MODELVIEW);  
glLoadIdentity();


int t=0;
void myKeyboard(unsigned char keyint x int y)
{
switch(key)
{
case‘j‘:
redmark((t+1)%n);
t=t+1;
break;
case‘k‘:
redmark((t-1)%n);
t=t-1;
break;
    case‘e‘:
exit(0);
    break;
case‘w‘:
ctrlpoints[t%n][1]+=0.1;
drawline();
glutPostRedisplay();
break;
case‘s‘:
ctrlpoints[t%n][1]-=0.1;
drawline();
glutPostRedisplay();
break;
case‘a‘:
ctrlpoints[t%n][0]-=0.1;
drawline();
glutPostRedisplay();
break;
case‘d‘:
ctrlpoints[t%n][0]+=0.1;
drawline();
glutPostRedisplay();
break;
      default:
      break;
}
}

int main(int argcchar**argv)
{  
glutInit(&argcargv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500500);
glutInitWindowPosition(100100);
glutCreateWindow(“贝塞尔曲线的绘制“);
myInit();
glutDisplayFunc(myDisplay);
glutReshapeFunc(reshape);
    glutKeyboardFunc(myKeyboard);
glutMainLoop();
return 0;
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       4344  2012-12-09 15:19  project-02周游2010213445\beziercurve\beziercurve.dsp

     文件        530  2012-12-09 14:20  project-02周游2010213445\beziercurve\beziercurve.dsw

     文件      33792  2012-12-09 15:19  project-02周游2010213445\beziercurve\beziercurve.ncb

     文件      48640  2012-12-09 15:19  project-02周游2010213445\beziercurve\beziercurve.opt

     文件       1049  2012-12-09 14:46  project-02周游2010213445\beziercurve\beziercurve.plg

     文件       2949  2012-12-11 15:08  project-02周游2010213445\beziercurve\beziervurve.cpp

     文件       3461  2012-12-15 15:39  project-02周游2010213445\beziercurve\beziervurve.dsp

     文件        530  2012-12-15 15:39  project-02周游2010213445\beziercurve\beziervurve.dsw

     文件      41984  2012-12-15 15:39  project-02周游2010213445\beziercurve\beziervurve.ncb

     文件      48640  2012-12-15 15:39  project-02周游2010213445\beziercurve\beziervurve.opt

     文件        779  2012-12-15 15:39  project-02周游2010213445\beziercurve\beziervurve.plg

     文件     192582  2012-12-09 14:36  project-02周游2010213445\beziercurve\Debug\beziercurve.exe

     文件     229924  2012-12-09 14:36  project-02周游2010213445\beziercurve\Debug\beziercurve.ilk

     文件     340124  2012-12-09 14:20  project-02周游2010213445\beziercurve\Debug\beziercurve.pch

     文件     451584  2012-12-09 14:36  project-02周游2010213445\beziercurve\Debug\beziercurve.pdb

     文件     208966  2012-12-15 15:39  project-02周游2010213445\beziercurve\Debug\beziervurve.exe

     文件     337992  2012-12-15 15:39  project-02周游2010213445\beziercurve\Debug\beziervurve.ilk

     文件      14593  2012-12-15 15:39  project-02周游2010213445\beziercurve\Debug\beziervurve.obj

     文件     353580  2012-12-15 15:39  project-02周游2010213445\beziercurve\Debug\beziervurve.pch

     文件     492544  2012-12-15 15:39  project-02周游2010213445\beziercurve\Debug\beziervurve.pdb

     文件      41984  2012-12-15 15:39  project-02周游2010213445\beziercurve\Debug\vc60.idb

     文件      45056  2012-12-15 15:39  project-02周游2010213445\beziercurve\Debug\vc60.pdb

     文件       2949  2012-12-27 18:46  project-02周游2010213445\chengxu.txt

     文件    1136640  2012-12-28 15:41  project-02周游2010213445\OPENGL报告T.ppt

     文件      33792  2012-12-30 19:59  project-02周游2010213445\曲线\Debug\vc60.idb

     文件      53248  2012-12-30 19:55  project-02周游2010213445\曲线\Debug\vc60.pdb

     文件     204856  2012-12-30 19:55  project-02周游2010213445\曲线\Debug\曲线.exe

     文件     269792  2012-12-30 19:55  project-02周游2010213445\曲线\Debug\曲线.ilk

     文件      16224  2012-12-30 19:55  project-02周游2010213445\曲线\Debug\曲线.obj

     文件     339984  2012-12-30 19:51  project-02周游2010213445\曲线\Debug\曲线.pch

............此处省略16个文件信息

评论

共有 条评论