简介
基本API用法以及一些注意事项
世界坐标-->本地坐标
- InverseTransformPoint:转换点,受到缩放影响
- InverseTransformDirection:转换方向,带有大小和方向,不受缩放影响
- InverseTransformVector:转换向量,受到缩放影响
var result2Self = this.transform.InverseTransformPoint(spacePoint);
var result2Self = this.transform.InverseTransformDirection(spacePoint);
var result2Self = this.transform.InverseTransformVector(spacePoint);
本地坐标-->世界坐标
- TransformPoint:转换点,受到缩放影响
- TransformDirection:转换方向,带有大小和方向,不受缩放影响
- TransformVector:转换向量,受到缩放影响
var result2World = this.transform.TransformPoint(selfPoint);
var result2World = this.transform.TransformDirection(selfPoint);
var result2World = this.transform.TransformVector(selfPoint);
屏幕坐标-->世界坐标
- ScreenToWorldPoint:传入的坐标要注意传入z值,代表相对相机的纵深深度
var result2World = Camera.main.ScreenToWorldPoint(screenPoint);
世界坐标-->屏幕坐标
- WorldToScreenPoint:屏幕坐标左下角是原点
var result2Screen = Camera.main.WorldToScreenPoint(spacePoint);
视口坐标
- 一般情况下,视口坐标(x,y) = 屏幕坐标(x,y) / 屏幕分辨率宽高,所以值通常在(0,1)之间,但是当物体不在摄像机视野中时也会有负值
- 相对的,世界坐标和视口坐标的转换也是一样
var result2Viewport = Camera.main.ScreenToViewportPoint(screenPoint);
var result2Screen = Camera.main.ViewportToScreenPoint(viewportPoint);
var result2Viewport = Camera.main.WorldToViewportPoint(spacePoint);
var result2World = Camera.main.ViewportToWorldPoint(viewportPoint);
网友评论