[英]Rotating Vertex Array Object not working
I am using vertex arrays to store circle vertices and colors. 我使用顶点数组来存储圆顶点和颜色。
Here is the setup function: 这是设置功能:
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);
}
The global declaration of the arrays is here: 数组的全局声明在这里:
static float Vertices1[500] = { 0 };
static float Colors1[500] = { 0 };
The arrays are all set up here (R is the radius, X and Y are the (X,Y) center, and t is the angle parameter of the circle) 数组都在这里设置(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;
}
}
Finally, this is where the shape is drawn. 最后,这是绘制形状的地方。
// 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();
}
Without the Rotation, the circle draws just fine. 没有旋转,圆圈就会很好。 The circle also draws fine with any Scale/Translate function. 圆圈也可以使用任何缩放/翻译功能。 I suspect there is some special protocol necessary to rotate an object drawn with vertex arrays. 我怀疑旋转用顶点数组绘制的对象需要一些特殊的协议。
Can anyone tell me where I have gone wrong, what I will need to do in order to rotate the object, or offer any advice? 任何人都可以告诉我哪里出错,我需要做什么来旋转对象,或提供任何建议?
glRotatef(15, 1, 0, 0);
^ why the X axis?
The default ortho projection matrix has pretty tight near/far clipping planes: -1 to 1. 默认的正投影矩阵具有相当紧密的近/远剪裁平面:-1到1。
Rotating your circle of X/Y coordinates outside of the X/Y plane will tend to make those points get clipped. 旋转X / Y平面之外的X / Y坐标圆将倾向于使这些点被剪裁。
Rotate around the Z axis instead: 改为绕Z轴旋转:
glRotatef(15, 0, 0, 1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.