旋转顶点阵列对象不起作用

Rotating Vertex Array Object not working

本文关键字:不起作用 对象 阵列 顶点 旋转      更新时间:2023-10-16

我使用顶点数组来存储圆的顶点和颜色。

这是设置功能:

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);