【问题标题】:how to convert world space transform to object space transform?如何将世界空间变换转换为对象空间变换?
【发布时间】:2017-03-12 13:07:08
【问题描述】:

我正在尝试实现:

transform.InverseTransformPoint(Vector3)transform.InverseTransformDirection(Vector3) 在 opengl 中使用 glm 库。 我有每个对象的视图、投影、模型矩阵。

实际上我不知道我必须如何处理这些矩阵才能获得该方法的功能。

【问题讨论】:

  • 只需在单词空间中使用vector3位置对象来转换到本地空间。为什么要使用矩阵?
  • 嗨 V. Borodinov,我的对象已被旋转和平移,因此,我需要在新坐标系中计算新位置和旋转。
  • 只需要改变基矩阵

标签: opengl unity3d matrix gl-matrix


【解决方案1】:

通常,可以通过以下数学运算将局部空间中的一个点转换为 NDC 空间:

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

其中 M = 模型,V = 视图,P = 投影。

所以,如果你在世界坐标系中有一个点并且想在本地坐标系中得到它,你只需要反转第一个方程:

Plocal = inv(M) * Pworld;

这应该等价于transform.InverseTransformPoint(Vector3)(只需添加第四个坐标向量H = 1)

要实现不受规模影响的transform.InverseTransformDirection(Vector3),您必须使用以下等式:

Plocal = transpose(inverse(M)) * Pworld

其中 M 是原始模型的左上角 3x3 矩阵。为了理解你为什么要使用这个数学,我邀请你看看这个页面:normal transformation

【讨论】:

  • @Amadeus 剪辑空间不是视图和 ndc 之间的中间步骤吗?
猜你喜欢
  • 2016-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-28
  • 1970-01-01
  • 2013-04-22
  • 1970-01-01
相关资源
最近更新 更多