Jam*_*mie 1 c++ opengl qt-creator opengl-1.x
我正在创建一个程序,允许我在3个空间中绘制点,使用Catmull-Rom Spline连接它们,然后在Spline周围绘制一个圆柱体.我GL_TRIANGLES_STRIP用来连接在Spline周围画出的点的圆圈,以便将它们全部连接成Spline周围的圆柱体.
我已经设法在这些间隔绘制完整的圆点,使用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();
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,当glBegin内部时,glMultMatrix似乎不起作用
在glBegin和glEnd之间只能使用GL命令的子集.命令是glVertex,glColor,glSecondaryColor,glIndex,glNormal,glFogCoord,glTexCoord,glMultiTexCoord,glVertexAttrib,glEvalCoord,glEvalPoint,glArrayElement,glMaterial和glEdgeFlag.此外,可以使用glCallList或glCallLists来执行仅包含前面命令的显示列表. 如果在glBegin和glEnd之间执行任何其他GL命令,则设置错误标志并忽略该命令.
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
};
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
glBegin(GL_POINTS);
glVertex3f(x, y, 0);
glEnd();
glPopMatrix();
// Do the same again for the second section
glPushMatrix();
glMultMatrixf(& M2[0]);
glBegin(GL_POINTS);
glVertex3f(x, y, 0);
glEnd();
glPopMatrix();
}
Run Code Online (Sandbox Code Playgroud)
或者应用转换客户端并手动OpenGL一个大块的顶点来一次渲染.
编辑:或完全拉出循环外的矩阵乘法:
GLfloat x, y;
GLfloat radius = 0.4f;
GLint pointCount = 180;
glPushMatrix();
glMultMatrixf(& M1[0]);
glBegin(GL_POINTS);
for (GLfloat theta = 0; theta < 2*M_PI; theta += (2*M_PI)/pointCount)
{
x = radius * cos(theta);
y = radius * sin(theta);
// Draw the point here
glVertex3f(x, y, 0);
}
glEnd();
glPopMatrix();
glPushMatrix();
glMultMatrixf(& M2[0]);
glBegin(GL_POINTS);
for (GLfloat theta = 0; theta < 2*M_PI; theta += (2*M_PI)/pointCount)
{
x = radius * cos(theta);
y = radius * sin(theta);
// Draw the point here
glVertex3f(x, y, 0);
}
glEnd();
glPopMatrix();
Run Code Online (Sandbox Code Playgroud)