opengl - 在 OpenGL 中渲染 B 样条曲线

标签 opengl 3d rendering curves bspline

我一直致力于一个 OpenGL 项目,该项目本质上是绘制 B 样条曲线的练习。我的程序没有返回错误,但曲线不会显示。

给定一个长度为 13 的名为“coords”的控制点数组(控制点本身在屏幕上都可见),这是我的代码:

glBegin(GL_LINE_STRIP);

float x=0;
float y=0;
float z=0;
for (double u = 3; u <= 14; u+=0.1){

    for (int i = 1; i <=13; i++){
        x += NofU(u,i)*coords[i].x;
        y += NofU(u,i)*coords[i].y;
        z += NofU(u,i)*coords[i].z;
    }//for

}//for

glVertex3f(x, y, z);

glEnd();

其中“NofU”代表混合函数:

double NofU(double u, int i){

if (u < i)
    return 0;
else if (u < i+1)
    return (1/6)*pow(u,3);
else if (u < i+2)
    return (1/6)*((-3)*pow(u,3)+3*pow(u,2)+3*u+1);
else if (u < i+3)
    return (1/6)*(3*pow(u,3)-6*pow(u,2)+4);
else if (u < i+4)
    return (1/6)*pow((1-u),3);
else
    return 0;

}//NofU

当我尝试打印语句时,我最终得到的坐标值要么非常大,要么非常小,或者只是 0。

最佳答案

呃,glBegin/End block 内只有一个 glVertex3f 调用。所以你试图画一条只有一个点的线带,这是不可能的。 (不确定 OpenGL 是否真的会为此报告错误。)

希望这有帮助。

关于opengl - 在 OpenGL 中渲染 B 样条曲线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13435375/

相关文章:

opengl - 将 SDL2 纹理绑定(bind)到 GLSL 着色器

delphi - OpenGL:如何将 2D 形状车床成 3D?

c++ - glGenVertexArrays(1, &vao) 处的段错误;

java - 在 OpenGL 中获取相机在 X、Y 和 Z 轴上的弧度旋转?

ios - 向右滑动时如何旋转到 3d 立方体的另一个面

java - Android opengles 20 渲染问题

java - JPanel闪烁

image - 为什么 OpenGL 不能正确显示我加载的图像?

animation - 从 FBX 加载蒙皮信息

android - 为什么这些 Android 控件在 Galaxy S 上看起来很奇怪?