前言:
感觉自己对这方面还是比较模糊,看下到底是个啥
1、添加Test脚本,打开编辑:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour {
private void Start()
{
Debug.Log("世界坐标:" + transform.position);
Debug.Log("自身坐标:" + transform.localPosition);
Debug.Log("世界四元数旋转:" + transform.rotation);
Debug.Log("自身四元素旋转:" + transform.localRotation);
Debug.Log("世界欧拉角旋转:" + transform.eulerAngles);
Debug.Log("自身欧拉角旋转:" + transform.localEulerAngles);
Debug.Log("世界缩放:" + transform.lossyScale);
Debug.Log("自身缩放:" + transform.localScale);
Debug.Log("自身转世界矩阵:" + transform.localToWorldMatrix);
Debug.Log("世界转自身矩阵:" + transform.worldToLocalMatrix);
}
}
2、创建Cube,点击小齿轮重置Transform

3、将Test脚本挂载到Cube身上

4、快捷键Ctrl+Shift+C打开Console窗口查看打印信息
5、运行查看打印信息

- 此时Cube在世界空间下,世界坐标和自身坐标没有区别
6、新建空物体,重置Transform

7、Cube拖到空物体下,成为子物体

8、运行,查看打印

- 当父物体重置Transform的情况下,世界坐标和自身坐标也没有区别
9、 改变父物体的Transform中的位置和旋转,运行打印

- 世界坐标变化了,自身坐标没变
10、改变子物体Cube的Transform中的位置和旋转,运行打印

- 世界坐标与自身坐标都变化了,其中自身坐标就是刚刚改变的子物体Cube刚刚修改的位置与旋转
- 子物体Cube的自身坐标就是显示在检视面板的值,而子物体Cube的世界坐标的值=自身坐标的值+父物体坐标的值
- 检视面板中的Rotation对应的是欧拉角旋转,而不是四元数旋转
- 当Cube为子物体的时候,对应的检视面板中的Transform是自身坐标的值;当Cube不是子物体的时候,对应的检视面板中的Transform是世界坐标的值
11、改变父物体的缩放,运行打印

- 世界坐标=自身坐标+父物体坐标*父物体缩放值
12、改变子物体的缩放,运行打印

- 世界缩放=自身缩放*父物体缩放
- 世界坐标不受子物体缩放印象;而是受父物体缩放影响
最后:
本来想一起测试四元数旋转和矩阵旋转这两个世界坐标和自身坐标,不过暂时没搞明白,下次吧
网友评论