我正在创建一个程序,允许我在 3 个空间中绘制点,使用 Catmull-Rom 样条线连接它们,然后围绕样条线绘制一个圆柱体。我正在使用GL_TRIANGLES_STRIP
以短间隔连接围绕样条线绘制的点圈,希望将它们全部连接到样条线周围的圆柱体中。
我已经设法在这些间隔处绘制完整的点圆,使用GL_POINTS
,并将它们正确定位到关于 Frenet 框架的线。不幸的是,要使用GL_TRIANGLE_STRIP
,我相信我需要在一组两个点之间一次绘制一个点。
我遇到的问题是,glMultMatrix
在glBegin
. 下面的代码将绘制一个点圈,但在原点,glMultMatrix
我用来平移和定位点圈的glbegin
. 有针对这个的解决方法吗?
//The matrixes that are applied to the circle of points
GLfloat M1[16]={
N1.x(),N1.y(),N1.z(),0,
B1.x(),B1.y(),B1.z(),0,
T1.x(),T1.y(),T1.z(),0,
fromPoint->x,fromPoint->y,fromPoint->z,1
};
GLfloat M2[16]={
N2.x(),N2.y(),N2.z(),0,
B2.x(),B2.y(),B2.z(),0,
T2.x(),T2.y(),T2.z(),0,
toPoint->x,toPoint->y,toPoint->z,1
};
glBegin(GL_TRIANGLE_STRIP);
GLfloat x, y;
GLfloat radius = 0.4f;
GLint pointCount = 180;
for (GLfloat theta = 0; theta < 2*M_PI; theta += (2*M_PI)/pointCount) {
x = radius * cos(theta);
y = radius * sin(theta);
// Now push a matrix, multiply it, draw a point and pop the matrix
glPushMatrix();
glMultMatrixf(& M1[0]);
// Draw the point here
glVertex3f(x, y, 0);
glPopMatrix();
// Do the same again for the second section
glPushMatrix();
glMultMatrixf(& M2[0]);
glVertex3f(x, y, 0);
glPopMatrix();
}
glEnd();