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

其实吧 就是在编辑器里把物体拽到根目录下的位置和物体在某物体内的位置之间的一个转换

Transform.InverseTransformPoint 反向变换点的更多相关文章

  1. unity 教程Tanks中的Transform.InverseTransformPoint理解

    Tanks教程中在处理摄像机缩放的时候使用了下面的函数,取两个坦克的中心点之后,根据两个坦克之间的距离,保证两个坦克都在屏幕中,然后进行缩放. private float FindRequiredSi ...

  2. 关于Unity中的transform组件(二)

    在Scene视图中的蓝色网格,每一格默认是1米 一.沿着Z轴每秒移动10米 Transform cube_trans; void start(){ this.cube_trans=this.trans ...

  3. Unity Transform常识(转)

    Variables   position: Vector3  物体在世界坐标中的位置. transform.position=Vector3(10,10,10)//把物体放到(x=10,y=10,z= ...

  4. [游戏开发-学习笔记]菜鸟慢慢飞(四)-Camera

    游戏开发中,主相机应该是最重要的GameObject之一,毕竟游戏呈现给玩家,就是通过它. 相机的使用,在不同的游戏中,有很大的不同.这里总结一下自己学到的一些相关知识. 固定位置-游戏过程中相机的T ...

  5. [转] Unity Mathf 数学运算(C#)

    Mathf.Abs 绝对值 计算并返回指定参数 f 绝对值. Mathf.Acos 反余弦 static function Acos (f : float) : float 以弧度为单位计算并返回参数 ...

  6. Unity3D NGUI刮刮卡效果

    线上效果 确保你的纹理的read/write 是勾选的,纹理格式是 RGBA32的 //代码 using UnityEngine; [RequireComponent(typeof(UITexture ...

  7. Unity3D-坐标转换笔记

    Transform.TransformPoint 作用 : 将一个点从以自身为坐标系的本地坐标转换成世界坐标 Transform.InverseTransformPoint 作用 : 将一个点从世界坐 ...

  8. UI坐标变换/转换

    InverseTransformPoint Transform.InverseTransformPoint :相对于谁的坐标.如果是相对2D UI,请使用localposition,如果是3D场景,请 ...

  9. Mesh系列文章 - 自定义Mesh

    就是在做项目的过程中,有用到三角形的,今天就写一下如何自定义三角形? 先截个图,让大家有个感性认识! //引用 using UnityEngine;        using System.Colle ...

随机推荐

  1. android开发 NDK 编译和使用静态库、动态库 (转)

    在eclipse工程目录下建立一个jni的文件夹 在jni文件夹中建立Android.mk和Application.mk文件 Android.mk文件: Android提供的一种makefile文件, ...

  2. HDU 4341 分组背包

    B - Gold miner Time Limit:2000MS      Memory Limit:32768KB     Description Homelesser likes playing ...

  3. PHP扩展开发

    安装好php,进入安装目录. zbseoag@ubuntu:/usr/local/php-5.6.28/ext$ ./ext_skel --extname=mytest zbseoag@ubuntu: ...

  4. kinect学习笔记(四)——各种数据流

    一.kinect开发的一个流程图 1.我们可以知道一个简单的框架就是几部分 (1)选择使用的kinect传感器 KinectSensor.KinectSensors[] (2)打开需要的数据流 _ki ...

  5. Session: 防止用户多次登陆

    在web开发时,有的系统要求同一个用户在同一时间只能登录一次,也就是如果一个用户已经登录了,在退出之前如果再次登录的话需要报错. 常见的处理方法是,在用户登录时,判断此用户是否已经在Applicati ...

  6. 织梦按栏目id读取banner图

    <div class="pic"> <div class="banner"> {dede:type} <div><a ...

  7. BZOJ3619 : [Zjoi2014]璀灿光华

    终于把省选时的遗憾补上了… 对于构造立方体: 首先BFS构出底层,然后再逐层构造立方体 对于计算: $O(n^6)$爆搜即可. #include<cstdio> #include<c ...

  8. HDU 3966(树链剖分+点修改+点查询)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3966 题目大意:营地的分布成树型.每个营地都有一些人,每次修改修改一条链上的所有营地的人数,每次查询单 ...

  9. BZOJ4011: [HNOI2015]落忆枫音

    Description 「恒逸,你相信灵魂的存在吗?」 郭恒逸和姚枫茜漫步在枫音乡的街道上.望着漫天飞舞的红枫,枫茜突然问出 这样一个问题.  「相信吧.不然我们是什么,一团肉吗?要不是有灵魂……我们 ...

  10. jQuery 跨域访问问题解决方法(转)

    转自:http://www.jb51.net/article/21213.htm 浏览器端跨域访问一直是个问题, 多数研发人员对待js的态度都是好了伤疤忘了疼,所以病发的时候,时不时地都要疼上一疼.记 ...