旋转顶点阵列对象不起作用
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);
相关文章:
- 在函数中声明的 ifStream 对象在发布模式下不起作用
- 即使我正在.cpp文件中实例化一个伪对象,.cpp文件内模板函数的定义也不起作用
- C++ 对象数组字符串输入在控制台上不起作用
- 自定义类型转换运算符在转发引用上调用时不起作用(当对象按值传递时有效)
- 模板参数类型推导在函数对象中不起作用
- 对列表迭代器指向的对象不起作用的引用
- 更新对象中的值不起作用
- 为什么重载运算符上的异常说明符'<<'不适用于任何 std::ostream 对象,但对库中定义的运算符不起作用?
- GCC:当层次结构中存在虚拟继承时,C++11 内联对象初始化(使用 "this")不起作用
- 抽象类型的对象 - 覆盖不起作用吗?
- 面向对象 成本计算C++不起作用
- 对象的排序向量不起作用
- 操作员=超载不起作用,除非对象已经初始化
- OpenGL 移动对象不起作用
- 使用纹理绘制多个对象不起作用
- 创建不可变的 CFArray 对象 - Apple 示例不起作用
- 矢量push_back在类对象中不起作用
- 线程对象的 WaitForSingleObject 在 DLL 卸载中不起作用
- 为什么类构造函数在通过复制初始化对象时不起作用
- 传递的临时 concreate 派生对象,其中需要对抽象基的引用不起作用?