简体   繁体   English

如何将世界空间变换转换为对象空间变换?

[英]how to convert world space transform to object space transform?

i'm trying to implement : 我正在尝试实现:

transform.InverseTransformPoint(Vector3) and transform.InverseTransformDirection(Vector3) using glm library in opengl. 使用opengl中的glm库进行transform.InverseTransformPoint(Vector3)transform.InverseTransformDirection(Vector3) i have view ,projection ,model matrices for each object. 我有每个对象的视图,投影,模型矩阵。

actually i don't know what i must to do with this matrices for got to that methods functionality. 实际上,我不知道要使用该方法的功能该如何处理该矩阵。

Usually, a point in local space can be transformed to NDC space by doing the following math: 通常,可以通过执行以下数学运算将局部空间中的点转换为NDC空间:

Pworld = M * Plocal;
Pview = V * Pworld;
Pndc = P * Pview;

where M = model, V = view and P = projection. 其中M =模型,V =视图,P =投影。

So, if you have a point in world coordinate system and want to get it in local coordinate system, you just have to invert the first equation: 因此,如果您在世界坐标系中有一个点并希望在局部坐标系中得到它,则只需将第一个方程式求反即可:

Plocal = inv(M) * Pworld;

This should be equivalent to transform.InverseTransformPoint(Vector3) (just add a fourth coordinate vector H = 1) 这应该等效于transform.InverseTransformPoint(Vector3) (只需添加第四个坐标向量H = 1)

To implement transform.InverseTransformDirection(Vector3) , which is not affected by scale, you must use this equation: 要实现不受比例影响的transform.InverseTransformDirection(Vector3) ,必须使用以下公式:

Plocal = transpose(inverse(M)) * Pworld

where M is the upper-left 3x3 matrix from your original Model. 其中M是原始模型的左上3x3矩阵。 To understand why you sould use this math, I invite you to look at this page: normal transformation 为了了解您为什么要使用此数学运算,我邀请您查看以下页面: 正常转换

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM