Transform.InverseTransformPoint 反向變換點


JavaScript ⇒ public function InverseTransformPoint(positionVector3): 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 

其實吧 就是在編輯器里把物體拽到根目錄下的位置和物體在某物體內的位置之間的一個轉換

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM