簡介
基本API用法以及一些注意事項
世界坐標-->本地坐標
- InverseTransformPoint:轉(zhuǎn)換點,受到縮放影響
- InverseTransformDirection:轉(zhuǎn)換方向愁茁,帶有大小和方向蚕钦,不受縮放影響
- InverseTransformVector:轉(zhuǎn)換向量,受到縮放影響
var result2Self = this.transform.InverseTransformPoint(spacePoint);
var result2Self = this.transform.InverseTransformDirection(spacePoint);
var result2Self = this.transform.InverseTransformVector(spacePoint);
本地坐標-->世界坐標
- TransformPoint:轉(zhuǎn)換點鹅很,受到縮放影響
- TransformDirection:轉(zhuǎn)換方向嘶居,帶有大小和方向,不受縮放影響
- TransformVector:轉(zhuǎn)換向量促煮,受到縮放影響
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)之間佑吝,但是當物體不在攝像機視野中時也會有負值
- 相對的,世界坐標和視口坐標的轉(zhuǎn)換也是一樣
var result2Viewport = Camera.main.ScreenToViewportPoint(screenPoint);
var result2Screen = Camera.main.ViewportToScreenPoint(viewportPoint);
var result2Viewport = Camera.main.WorldToViewportPoint(spacePoint);
var result2World = Camera.main.ViewportToWorldPoint(viewportPoint);