如何通过自己的中心旋转所有对象,然后将它们转换到真实的位置(它不工作) [英] how to rotate all objects by their own centers and then translate them to the real position (it isn't working)

查看:195
本文介绍了如何通过自己的中心旋转所有对象,然后将它们转换到真实的位置(它不工作)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使所有不与原点中心对齐的对象(vector3(0.0f,0.0f,0.0f))的方式是什么,绕自己的中心轴旋转?



伪代码中的问题:

  vector3 vector3 objectCenter =(10,5,0); //当前对象中心
vector3 vector3 objectPosition =(40,5,0); // Place to translate the object
vector3 objectRotation; = 45.0f;

matrix.loadIdentity();
matrix.translate(objectCenter);

//应用转换
matrix.rotateX(objectRotation);

matrix.translate(-objectCenter);

//itś正常工作直到这里
//当我尝试将对象翻译到真实位置时,旋转不正确。

matrix.translate(objectPosition);

我使用C ++,glm(到矩阵管理)和OpenGL。


> M = inverse(inverse(M)* rotation_matrix);





[edit1]更多关于M和对象之间的关系的关系




What is the way to make all the objects that are not aligned with the origin center (vector3(0.0f,0.0f,0.0f)) , rotate about its own central axis?

the problem in pseudo code:

vector3 vector3 objectCenter = (10,5,0); // current object center
vector3 vector3 objectPosition = (40,5,0); // Place to translate the object
vector3 objectRotation; = 45.0f;

    matrix.loadIdentity ();
    matrix.translate (objectCenter);

    //apply transformations
    matrix.rotateX (objectRotation);

    matrix.translate (-objectCenter);

    //itś work correctly until here
    //when i try to translate the object to the real position, the rotation is incorrect.

    matrix.translate (objectPosition);

I use C++, glm (to matrix manage) and OpenGL.

解决方案

if you want to rotate object locally to its own coordinate system then do this:

M=inverse(inverse(M)*rotation_matrix);

[edit1] more about relation between M and object which coordinate system it represents

这篇关于如何通过自己的中心旋转所有对象,然后将它们转换到真实的位置(它不工作)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆