OpenGL 绘制B样条曲线

本文介绍如何使用OpenGL绘制B样条曲线,包括closed-B样条曲线的绘制方法,并提供了详细的参考资料。通过示例代码展示了如何实现鼠标交互来动态调整B样条曲线的控制点。
摘要由CSDN通过智能技术生成

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

http://blog.csdn.net/yangtrees/article/details/9026411

绘制B样条曲线:

#include <stdlib.h>#include <GL/glut.h>#pragma comment(lib,"glut32.lib")//#if 0// the points of the curve - these are the same as the bezier curve// points demonstrated in the bezier curve example.float Points[4][3] = { { 10,10,0 }, {  5,10,2 }, { -5,0,0 }, {
   -10,5,-2}};#define NUM_POINTS 4// The following sets of 4 indices are the curves that need to// be drawn to create a clamped cubic b-spline. In total there// are 5 curve segments to draw.//// 0 0 0 1//    0 0 1 2//      0 1 2 3//        1 2 3 3//          2 3 3 3//// Remember this when trying to understand knot vectors!!//#elsefloat Points[9][3] = { { 10,5,0 }, {  5,10,0 }, { -5,15,0 }, { -10,-5,0 }, { 4,-4,0 }, { 10,5,0 }, {  5,10,0 }, { -5,15,0 }, { -10,-5,0 }};#define NUM_POINTS 9//若绘制过首尾控制点的曲线  // 0 0 0 1// 0 0 1 2// 0 1 2 3// 1 2 3 4// 2 3 4 5// 3 4 5 6// 4 5 6 6// 5 6 6 6//// Remember this when trying to understand knot vectors!!////若绘制首尾相接的平滑曲线 ,即为当前绘制// 0 1 2 3// 1 2 3 4// 2 3 4 5// 3 4 5 6#endif// the level of detail for the curveunsigned int LOD=20;#define NUM_SEGMENTS (NUM_POINTS-3)//float* GetPoint(int i) // return 1st point if (i<0)  {  return Points[0]; } if (i<NUM_POINTS) {  return Points[i]; } // return last point return Points[NUM_POINTS-1];}//------------------------------------------------------------ OnKeyPress()void myIdle(void) { glutPostRedisplay();}//------------------------------------------------------------ OnDraw()void OnDraw() // clear the screen & depth buffer glClear(GL_COLOR_BUFFER_BIT); // clear the previous transform glLoadIdentity(); // set the camera position //  gluLookAt( 1,10,30, // eye pos //   0,0,0, // aim point //   0,1,0); // up direction //  glColor3f(0.5,0.2,0); glPointSize(3); //  //  // draw curve hull glColor3f(0.3,0,0.5); glBegin(GL_LINE_STRIP); for(int i=0;i!=NUM_POINTS;++i) {  glVertex3fv( Points[i] ); } glEnd(); glColor3f(0,1,0); // begin drawing our curve glBegin(GL_LINE_STRIP); for(int start_cv=0,j=0;j<NUM_SEGMENTS;j++,start_cv++) {  // for each section of curve, draw LOD number of divisions  for(int i=0;i!=LOD;++i)   {   // use the parametric time value 0 to 1 for this curve   // segment.   float t = (float)i/LOD;   // the t value inverted   float it = 1.0f-t;   // calculate blending functions for cubic bspline   float b0 = it*it*it/6.0f
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值