Unity基础——回顾和坐标系相关

目录

1.世界坐标系

2.物体坐标系

3.屏幕坐标系

4.视口坐标系

5.坐标转换相关

 1 世界转本地

 2 本地转世界

 3 世界转屏幕

 4 屏幕转世界

 5 世界转视口

 6 视口转世界

 7 视口转屏幕

 8 屏幕转视口


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;

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Nicole Potter

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值