在OpenGL中围绕特定点旋转对象
Rotating object in OpenGL around specific point
我正在建模牛顿摇篮,我有电线/弦旋转的麻烦,因为它们目前围绕其中心旋转,而不是它们附着在框架上的地方。除了"翻译到旋转点,旋转,再翻译回来"这句话似乎行不通之外,网上的信息似乎很少。
std::stack<glm::mat4>model;
model.push(glm::mat4(1.0f));
model.top() = glm::translate(model.top(), glm::vec3(x, y, z));
model.top() = glm::rotate(model.top(), vx, glm::vec3(1, 0, 0)); //rotating in clockwise direction around x-axis
model.top() = glm::rotate(model.top(), vy, glm::vec3(0, 1, 0)); //rotating in clockwise direction around y-axis
model.top() = glm::rotate(model.top(), vz, glm::vec3(0, 0, 1)); //rotating in clockwise direction around z-axis
model.top() = glm::scale(model.top(), glm::vec3(scale/40, scale*5, scale/40));//scale equally in all axis
model.top() = glm::translate(model.top(), glm::vec3(-x, -y, -z));
glUniformMatrix4fv(modelID, 1, GL_FALSE, &model.top()[0][0]);
glm::mat3 normalmatrix = glm::transpose(glm::inverse(glm::mat3(View * model.top())));
glUniformMatrix3fv(normalmatrixID, 1, GL_FALSE, &normalmatrix[0][0])
这是转换和旋转的位,或者它的当前迭代,堆栈实际上什么都不做。如果我的问题是不清楚想象模拟时钟臂,它将围绕时钟中心在其末端旋转,而不是由手臂本身的中心。我知道在OpenGl
作为旁注,在OpenGL (GLSL之外)中不再有任何矩阵内容的"本地"实现。
你这里的问题是,你只设置顶部()矩阵为一个值,而不是通过将它们相乘来累积转换。
稍后您可能还会注意到一个问题,即它不会移回相同的位置(在将矩阵相乘之后)。这是因为在转换回原始位置之前,您将对象缩小了很多。转换的顺序很重要。
像这样的教程提供了对所有这些东西的深入解释,可能对您非常有用:
http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/相关文章:
- 形状对象的旋转和缩放不正确C++
- 鼠标单击 OpenGL 时无法围绕其自己的中心旋转对象
- 无法在D2D1中旋转对象
- 如何使用OpenCV从图像中检测旋转对象
- 无法从非原点的其他位置旋转对象
- 使用键旋转对象
- OpenGL C++围绕场景中心旋转对象
- 围绕另一个对象旋转对象
- 旋转对象及其'children'
- OpenGL 在屏幕上渲染之前旋转对象以设置其正确的表面
- OpenGL 平移和旋转对象
- OpenGL,如何相互独立地旋转对象
- 旋转对象时缺少像素
- 如何在opengl中旋转对象
- 在OpenGL中,在对象自己的轴上旋转对象
- 旋转对象,但保持照明固定DirectX
- 在OpenGL中围绕特定点旋转对象
- Opencv动画使用旋转矩阵旋转对象
- 如何在opengl中使用矩阵移动和旋转对象
- 围绕中心点旋转对象的函数