Transform.InverseTransformPoint 反向变换点
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.InverseTransformPoint 和 transform.TransformPoint 是怎么回事
一个是变换自身坐标到世界坐标 一个是变换世界坐标到自身坐标
比如说物体a的坐标内有一个3,3,3的点 你想知道这个点在世界坐标的位置 就应该用TransformPoint
反之在世界坐标下有一个点 你想知道这个点如果是在物体a的坐标下是一个什么位置 就应该用InverseTransformPoint
其实吧 就是在编辑器里把物体拽到根目录下的位置和物体在某物体内的位置之间的一个转换
Transform.InverseTransformPoint 反向变换点的更多相关文章
- unity 教程Tanks中的Transform.InverseTransformPoint理解
Tanks教程中在处理摄像机缩放的时候使用了下面的函数,取两个坦克的中心点之后,根据两个坦克之间的距离,保证两个坦克都在屏幕中,然后进行缩放. private float FindRequiredSi ...
- 关于Unity中的transform组件(二)
在Scene视图中的蓝色网格,每一格默认是1米 一.沿着Z轴每秒移动10米 Transform cube_trans; void start(){ this.cube_trans=this.trans ...
- Unity Transform常识(转)
Variables position: Vector3 物体在世界坐标中的位置. transform.position=Vector3(10,10,10)//把物体放到(x=10,y=10,z= ...
- [游戏开发-学习笔记]菜鸟慢慢飞(四)-Camera
游戏开发中,主相机应该是最重要的GameObject之一,毕竟游戏呈现给玩家,就是通过它. 相机的使用,在不同的游戏中,有很大的不同.这里总结一下自己学到的一些相关知识. 固定位置-游戏过程中相机的T ...
- [转] Unity Mathf 数学运算(C#)
Mathf.Abs 绝对值 计算并返回指定参数 f 绝对值. Mathf.Acos 反余弦 static function Acos (f : float) : float 以弧度为单位计算并返回参数 ...
- Unity3D NGUI刮刮卡效果
线上效果 确保你的纹理的read/write 是勾选的,纹理格式是 RGBA32的 //代码 using UnityEngine; [RequireComponent(typeof(UITexture ...
- Unity3D-坐标转换笔记
Transform.TransformPoint 作用 : 将一个点从以自身为坐标系的本地坐标转换成世界坐标 Transform.InverseTransformPoint 作用 : 将一个点从世界坐 ...
- UI坐标变换/转换
InverseTransformPoint Transform.InverseTransformPoint :相对于谁的坐标.如果是相对2D UI,请使用localposition,如果是3D场景,请 ...
- Mesh系列文章 - 自定义Mesh
就是在做项目的过程中,有用到三角形的,今天就写一下如何自定义三角形? 先截个图,让大家有个感性认识! //引用 using UnityEngine; using System.Colle ...
随机推荐
- SQL事务的使用
在 SQL Server 中数据库事务处理是个重要的概念,也稍微有些不容易理解,很多 SQL 初学者编写的事务处理代码存往往存在漏洞,本文介绍了三种不同的方法,举例说明了如何在存储过程事务处理中编写正 ...
- Hark的数据结构与算法练习之堆排序
前言 堆排序我是看了好半天别人的博客才有了理解,然后又费了九牛二虎之力才把代码写出来,我发现我的基础真的很差劲啊……不过自己选的路一定要坚持走下去.我试着把我的理解描述出来,如有不妥之处希望大家可以指 ...
- hdu 1455 Sticks
Sticks Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- 在JavaScript中,this关键字指什么?
指向对象.window.方法. 例子1 function a(){//当前调用栈是a,因此a的调用位置是全局作用域 console.log('a'); b();// b的调用位置 } function ...
- TODO:C# Socket
http://www.cnblogs.com/licongjie/archive/2006/10/26/540640.html http://blog.csdn.net/ZOU_SEAFARER/ar ...
- ZOJ 3603 DP LCS
已经5年没有做OJ了, 曾经沧海难为水,除去巫山不是云" 准备每周刷1-2题! 题目大意:给出N个字符串,且各个字符串都包含唯一的字母,即不存在"ABCA"(A重复了), ...
- Linux redirect the stdout to a file
1: int save_out = dup(fileno(stdout));//backup stdout 2: int out = open("cout.log", O_RD ...
- 8.0 Qweb 报表编写步骤
8.0 采用的是Qweb报表,摒弃了7.0中的RML报表. 1.首先在xml文件中注册一个报表: <report id="qweb_test_report" model=&q ...
- php如何把文件上传到服务器上
conn.php: <?php $id=mysql_connect('localhost','root','root'); mysql_select_db("db_database12 ...
- [转].net 缩略图方法
本文转自:http://www.cnblogs.com/promic/archive/2010/04/21/1717190.html private static string strConnect ...