目录
1.世界坐标系
原点:世界的中心点
轴向:世界坐标系的三个轴固定
和世界坐标系相关的代码:(修改它们会产生相对于世界坐标系的变化)
this.transform.position;
this.transform.rotation;
this.transform.eulerAngles;
this.transform.lossyScale;
2.物体坐标系
原点:物体的中心点(建模时决定)
轴向:物体右方为x轴正方向
物体上方为y轴正方向
物体前方为z轴正方向
物体坐标系的相关代码:
this.transform.localPosition;
this.transform.localEulerAngles;
this.transform.localRotation;
this.transform.localScale;
//修改它们变化的是相对于父对象物体坐标系的变化
3.屏幕坐标系
原点:屏幕左下角
轴向:向右为x轴正方向
向上为y轴正方向
最大宽高:
Screen.width
Screen.height
屏幕坐标系的代码相关:
Input.mousePosition;
Screen.width;
Screen.height;
4.视口坐标系
原点:屏幕左下角
轴向:向右为x轴正方向
向上为y轴正方向
特点:左下角为(0,0)
右上角为(1,1)
和屏幕类似,将坐标单位化。在Unity中可以在Viewport Rect中修改宽高大小。
5.坐标转换相关
1 世界转本地
this,transform.InverseTransformDirection;
this.transform.InverseTransformPoint;
this.transform.InverseTransformVector
2 本地转世界
this.transform.TransformDirection
this.transform.TransformPoint;
this.transform.TransformVector;
3 世界转屏幕
Camera.main.WorldToScreenPoint;
4 屏幕转世界
Camera.main.ScreenToWorldPoint;
5 世界转视口
Camera.main.WorldToViewportPoint;
6 视口转世界
Camera.main.ViewportToWorldPoint;
7 视口转屏幕
Camera.main.ViewportToScreenPoint;
8 屏幕转视口
Camera.main.ScreenToViewportPoint;