[英]Rotating Vertex Array Object not working
我使用顶点数组来存储圆顶点和颜色。
这是设置功能:
void setup1(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
// Enable two vertex arrays: co-ordinates and color.
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
// Specify locations for the co-ordinates and color arrays.
glVertexPointer(3, GL_FLOAT, 0, Vertices1);
glColorPointer(3, GL_FLOAT, 0, Colors1);
}
数组的全局声明在这里:
static float Vertices1[500] = { 0 };
static float Colors1[500] = { 0 };
数组都在这里设置(R是半径,X和Y是(X,Y)中心,t是圆的角度参数)
void doGlobals1()
{
for (int i = 0; i < numVertices1 * 3; i += 3)
{
Vertices1[i] = X + R * cos(t);
Vertices1[i + 1] = Y + R * sin(t);
Vertices1[i + 2] = 0.0;
t += 2 * PI / numVertices1;
}
for (int j = 0; j < numVertices1 * 3; j += 3)
{
Colors1[j] = (float)rand() / (float)RAND_MAX;
Colors1[j + 1] = (float)rand() / (float)RAND_MAX;
Colors1[j + 2] = (float)rand() / (float)RAND_MAX;
}
}
最后,这是绘制形状的地方。
// Window 1 drawing routine.
void drawScene1(void)
{
glutSetWindow(win1);
glLoadIdentity();
doGlobals1();
glClear(GL_COLOR_BUFFER_BIT);
glRotatef(15, 1, 0, 0);
glDrawArrays(GL_TRIANGLE_FAN, 0, numVertices1);
glFlush();
}
没有旋转,圆圈就会很好。 圆圈也可以使用任何缩放/翻译功能。 我怀疑旋转用顶点数组绘制的对象需要一些特殊的协议。
任何人都可以告诉我哪里出错,我需要做什么来旋转对象,或提供任何建议?
glRotatef(15, 1, 0, 0);
^ why the X axis?
默认的正投影矩阵具有相当紧密的近/远剪裁平面:-1到1。
旋转X / Y平面之外的X / Y坐标圆将倾向于使这些点被剪裁。
改为绕Z轴旋转:
glRotatef(15, 0, 0, 1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.