如何在 opengl 中仅旋转特定对象而不影响其他对象?
How to rotate only a specific object without affecting the others in opengl?
我在 OpenGL 中制作一个风扇,里面有杆子和旋转的东西,当我尝试旋转它们时,所有的风扇都随着杆子旋转,我应该如何修复它,我使用了glutPostRedisplay()
,当我使用推送和 pup 矩阵旋转时,它根本不旋转, 它只以我写的角度旋转一次,有什么建议有帮助吗?
我在旋转中使用推送和 pup 矩阵,它根本不旋转,它只旋转一次
如果您使用glPushMatrix
/glPopMatrix
,则当前矩阵通过glPushMatrix
存储在矩阵堆栈上,并在调用glPopMatrix
时恢复。两者之间应用的所有矩阵变换都将丢失。
要实现连续旋转,您必须使用增加的旋转角度。创建一个全局变量angle
并递增它。例如:
float angle = 0.0f;
void draw()
{
// ...
glPushMatrix();
// apply rotation and increase angle
glRotatef(angle, 1.0f, 0.0f, 0.0f);
angle += 1.0f;
// draw the object
// ...
glPopMatrix();
// ...
}
在老式的 opengl 中,您将封装一对 glPushMatrix(矩阵堆栈的存储状态(和 glPopMatrix(恢复以前的转换(调用之间的转换更改。
glPushMatrix();
glRotatef(45.0f, 0, 1, 0); //< or whatever your rotation is.
drawObjectToBeRotated();
glPopMatrix();
// now any objects drawn here will not be affected by the rotation.
在现代 OpenGL 中,对于正在绘制的每个网格,您需要上传一个单独的 ModelViewProjection 矩阵作为顶点着色器统一(有几种方法可以做到这一点,要么在统一变量、统一缓冲区对象、着色器存储缓冲区或某些实例化缓冲区输入中(。
相关文章:
- 处理影响跨不同线程共享对象的定时回调的最佳方法是什么?
- 如何在 opengl 中仅旋转特定对象而不影响其他对象?
- 如何影响由 new 和强制转换为数组 od 类对象的内存?
- 隐式转换函数的返回对象时是否会影响性能?
- C++引用挥发性对象 - 原因和影响
- 使用方法影响另一个对象的字段
- 如果多个线程使用同一对象,性能是否受到影响
- 在C++中,"static initialization fiasco"是否仅影响对另一个模块中定义的对象的数据成员的引用?
- 函数对象如何影响过载分辨率
- 对象分配对二进制大小的影响是什么
- 公共和私有对对象的内存布局是否有任何影响
- 返回间接类型化对象是否会影响性能
- CV 限定符是否会影响返回对象的复制省略?
- 向上转换为基类对象而不是引用有什么不良影响
- 在不影响其他对象的情况下移动对象(使用opengl)
- 额外的继承对对象结构或实例化有影响吗?
- 什么时候删除对象?创建对象对c++的影响
- 程序运行时是否受对象在内存中的位置的影响
- 类属性的顺序会影响对象的大小吗?
- c++中的临时对象如何影响效率