绕摄影机旋转opengl c++/设置旋转中心
Rotate around camera opengl c++ / Set center for rotation
Opengl始终围绕(0,0,0)旋转 但我需要绕着相机旋转 我知道在GL中没有相机, 但如果我翻译回(0,0,-6.0) ,它会围绕(0,0,0)旋转,而不是围绕(0,0,6.0)旋转
所以我的问题是:如何在opengl和c++中设置旋转中心
我已经找到了这个帖子:OpenGL围绕一个点旋转相机
显示此解决方案的位置:
旋转函数通常绕原点旋转。旋转在另一点P附近,您必须:平移(-P)旋转平移(P)
我现在不知道如何实现
翻译(p)
因为旋转后平移相对于旋转
示例:我想绕(1,1,1)旋转。我翻译(-1,-1,-1)。现在我把它绕x轴旋转90度。没错。但现在我必须把它翻译回来。如果我平移(1,1,1),它不会起作用,因为它现在是旋转的,并且移动是相对于旋转的矩阵的
PS:我不想使用gluLookAt()
所以我的代码是:
//set rotation to zero
glRotatef(-yr,0.0f,1.0f,0.0f);
glRotatef(-xr,1.0f,0.0f,0.0f);
//set points relative to camera
glTranslatef(cam_pos[0],cam_pos[1],cam_pos[2]);
//rotate back
glRotatef(yr,0.0f,1.0f,0.0f);
glRotatef(xr,1.0f,0.0f,0.0f);
//rotate
glRotatef(angley,0.0f,1.0f,0.0f);
glRotatef(anglex,1.0f,0.0f,0.0f);
//and now, how to translate back,
//movement is relative to the cam ?
//I would simply use :
//glTranslatef(-cam_pos[0],-cam_pos[1],-cam_pos[2]);
//which wont work because its relative to the new rotation.
非常感谢您的帮助!
所以,我实际上发现运动与旋转无关,这让一切都很容易实现。代码:
glTranslatef(point_to_rotate_around_x,point_to_rotate_around_y,point_to_rotate_around_z);
glRotatef(anglex,1,0,0);
glRotatef(angley,0,1,0);
glTranslatef(-point_to_rotate_around_x,-point_to_rotate_around_y,-point_to_rotate_around_z);
谢谢@derhass,他告诉我这是倒退的。
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 在C++/Linux中设置单调时钟的一些技巧
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 嵌套在类中时无法设置成员数据
- 需要帮助设置在C++中使用的Potrace
- 与互斥锁相比,旋转锁可以保证上下文切换
- 如何在自删除后将对象设置为nullptr
- 将指针设置为"nullptr"并不能防止双重删除?
- 如何在Ubuntu中使用cmake设置qt4
- ld:bind_at_load和-bitcode_bundle(Xcode设置ENABLE_bitcode=YES)不能
- 如何在boost beast http请求中设置http头
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- 如何将这个C++哈希表转换为动态扩展和收缩,而不是使用硬设置的最大值
- 将骨旋转设置为在本地空间中的可容纳网眼
- 当先前调用Remove_All_Sinks()时,提升日志设置旋转和最大文件大小导致添加第二个接收器
- 绕摄影机旋转opengl c++/设置旋转中心
- OpenGL 在屏幕上渲染之前旋转对象以设置其正确的表面
- Qt5 C++:为特定表列设置旋转框委托
- opencv:使用旋转和平移向量设置模型位置
- 使用“度”设置4x4旋转矩阵