【发布时间】:2018-10-04 14:01:19
【问题描述】:
将位置从世界空间转换到局部空间。
但我不明白它在下面的块中是如何做到的
private Vector3 PlaceOnCircle(Vector3 position) {
Ray ray = Camera.main.ScreenPointToRay (position);
Vector3 pos = ray.GetPoint (0f);
// Making 'pos' local to... ?
pos = transform.InverseTransformPoint (pos);
float angle = Mathf.Atan2 (pos.x, pos.z) * Mathf.Rad2Deg;
pos.x = circle.radius * Mathf.Sin (angle * Mathf.Deg2Rad);
pos.z = circle.radius * Mathf.Cos (angle * Mathf.Deg2Rad);
pos.y = 0f;
return pos;
}
它是让 'pos' 本地化还是本地化到拥有这个脚本的游戏对象?
为什么 InverseTransformPoint 的参数是变量本身?
写pos = transform.InverseTransformPoint(); 会使'pos' 成为上述变换的局部变量难道不够吗?
【问题讨论】:
-
函数的参数是点,假设在世界空间坐标中,您要从中计算局部坐标(函数的结果)。应用该函数的变换是本地参考系,将从中计算新的 x、y 和 z 坐标。因此,在这种情况下,它将“pos”(世界坐标)替换为相对于该脚本所附加到的当前游戏对象的局部坐标。
标签: c# unity3d coordinates transform coordinate-systems