Transform.InverseTransformPoint 反向變換點

來源:互聯網
上載者:User

標籤: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 反向變換點

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.