標籤:ret http 方向 href rmdir evel var position 縮放
JavaScript ? public function InverseTransformPoint(position: Vector3): Vector3;
C# ?public Vector3 InverseTransformPoint(Vector3 position);
Description 描述
Transforms position from world space to local space. The opposite of Transform.TransformPoint.
變換位置從全局座標到局部座標。和Transform.TransformPoint相反。
Note that the returned position is affected by scale. Use Transform.InverseTransformDirection if you are dealing with directions.
注意,返回位置受縮放影響。如果你是處理方向使用Transform.InverseTransformDirection。
JavaScript:
// Calculate the transform‘s position relative to the camera. var cam = Camera.main.transform; var cameraRelative = cam.InverseTransformPoint(transform.position); if (cameraRelative.z > 0) print ("The object is in front of the camera"); else print ("The object is behind the camera");
C#:
using UnityEngine;using System.Collections; public class ExampleClass : MonoBehaviour { public Transform cam = Camera.main.transform; public Vector3 cameraRelative = cam.InverseTransformPoint(transform.position); void Example() { if (cameraRelative.z > 0) print("The object is in front of the camera"); else print("The object is behind the camera"); }}
JavaScript ?public function InverseTransformPoint(x: float, y: float, z: float): Vector3;
C# ?public Vector3 InverseTransformPoint(float x, float y, float z);
Description 描述
Transforms the position x, y, z from world space to local space. The opposite of Transform.TransformPoint.
變換位置 x, y, z從全局座標到局部座標。和Transform.TransformPoint相反。
Note that the returned position is affected by scale. Use Transform.InverseTransformDirection if you are dealing with directions.
注意,返回位置受縮放影響。如果你是處理方向使用Transform.InverseTransformDirection。
JavaScript:
// Calculate the world origin relative to this transform. relativePoint = transform.InverseTransformPoint(0, 0, 0); if (relativePoint.z > 0) print ("The world origin is in front of this object"); else print ("The world origin is behind of this object");
C#:
using UnityEngine;using System.Collections; public class ExampleClass : MonoBehaviour { void Example() { relativePoint = transform.InverseTransformPoint(0, 0, 0); if (relativePoint.z > 0) print("The world origin is in front of this object"); else print("The world origin is behind of this object"); }}
? Transform
transform.InverseTransformPoint 和 transform.TransformPoint 是怎麼回事
一個是變換自身座標到全局座標 一個是變換全局座標到自身座標
比如說物體a的座標內有一個3,3,3的點 你想知道這個點在全局座標的位置 就應該用TransformPoint
反之在全局座標下有一個點 你想知道這個點如果是在物體a的座標下是一個什麼位置 就應該用InverseTransformPoint
其實吧 就是在編輯器裡把物體拽到根目錄下的位置和物體在某物體內的位置之間的一個轉換
Transform.InverseTransformPoint 反向變換點