OpenGL c++ 中的旋转子对象
Rotating child object in OpenGL c++
我正在将一个具有多个DoG的机器人添加到我的OpenGL应用程序中(稍后我想为这个机器人实现反向运动学(,我需要移动"连接"在一起的对象。
到目前为止,我将 3 个 STL 对象添加到场景中,看起来像这样
有底座、关节1和关节2。
底座是静止的,joint1 和 joint2 现在根据键盘输入绕 Z 轴旋转,但它们都只是围绕它们的原点旋转,这对于 joint1 来说很好,但对于 joint2,我需要它们连接并相应地平移。
这是旋转后的输出。
对于对象定位和旋转,我使用常规的 MVP 矩阵和 glm。
joint1M = glm::translate(joint1M, glm::vec3(-50.0f, -10.4f, 0.0f));
joint1M = glm::rotate(joint1M, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));
joint2M = glm::translate(joint2M, glm::vec3(-50.0f, 2.85f, 0.0f));
joint2M = glm::rotate(joint2M, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));
有没有办法在OpenGL中创建父级团结关系之类的东西?还是我应该根据关节 2 的旋转以某种方式改变关节 1 的位置?
感谢评论和更多的谷歌搜索,我设法让它像这样工作:
关节 1 保持不变:
joint1M = glm::translate(joint1M, glm::vec3(-50.0f, -10.4f, 0.0f));
joint1M = glm::rotate(joint1M, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));
关节 2 移动到关节 1 的位置,旋转,移动到它应该在的位置
joint2M = glm::translate(joint2M, glm::vec3(-50.0f, -10.4f, 0.0f));
joint2M = glm::rotate(joint2M, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));
joint2M = glm::translate(joint2M, glm::vec3(0.0f, 13.25f, 0.0f));
相关文章:
- 形状对象的旋转和缩放不正确C++
- 如何在OpenGL中正确旋转和缩放对象?
- 当表示为对象的一维向量时,有效地旋转 NxM 矩阵 (C++)
- 如何围绕对象旋转相机?
- 如何在 opengl 中仅旋转特定对象而不影响其他对象?
- 将四元数旋转的游戏对象旋转另一个四元数时出现问题
- 鼠标单击 OpenGL 时无法围绕其自己的中心旋转对象
- 无法在D2D1中旋转对象
- 如何使用OpenCV从图像中检测旋转对象
- OpenCV 检测多个旋转的缩放对象
- OpenGL c++ 中的旋转子对象
- 无法从非原点的其他位置旋转对象
- 在Qt5的OpenGL绘图中通过鼠标移动计算对象旋转角度
- 围绕另一个对象旋转对象
- 矩阵乘法 opengl 围绕对象旋转
- 对象旋转/平移后重新计算AABB正确
- 围绕另一个对象旋转的物体不断加速
- 在 C++/OpenGL 中围绕另一个对象旋转投影一个对象
- 如何在OpenGL中将对象旋转一定程度?有内置的命令吗?或者我必须使用公式吗
- 如何在其他部件旋转时阻止对象旋转