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. 蒟蒻的树形dp记录

    POJ2342: 题意:某公司要举办一次晚会,但是为了使得晚会的气氛更加活跃,每个参加晚会的人都不希望在晚会中见到他的直接上司,现在已知每个人的活跃指数和上司关系(当然不可能存在环),求邀请哪些人(多 ...

  2. Codeforces Gym 100513G G. FacePalm Accounting

    G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...

  3. loadrunner解决“服务器正在运行中”方法

    问题现象: 这个问题在上家公司遇见过,今天无意中找到了解决办法: 解决方法: 打开任务管理器: 找到这个进程:ThumbProcess.exe,关掉这个进程即可解决. 今天运行lr的vugen报错 解 ...

  4. SGU326 Perspective(指派问题)

    题目简单吧,如果知道题目要干嘛的话. 每个比赛指定A赢或者B赢使它们赢得次数不超过1赢得次数.建立一个二分图模型,X部比赛,Y部队伍,用最大流求解,如果最后最大流等于比赛场数就有解. 然而我还是掉坑里 ...

  5. POJ2836 Rectangular Covering(状压DP)

    题目是平面上n个点,要用若干个矩形盖住它们,每个矩形上至少要包含2个点,问要用的矩形的面积和最少是多少. 容易反证得出每个矩形上四个角必定至少覆盖了两个点.然后就状压DP: dp[S]表示覆盖的点集为 ...

  6. 【python游戏编程之旅】第三篇---pygame事件与设备轮询

    本系列博客介绍以python+pygame库进行小游戏的开发.有写的不对之处还望各位海涵. 在上一篇博客中,我们学习了pygame中的IO.数据http://www.cnblogs.com/msxh/ ...

  7. Ada语言基础

    前天是程序员节,CodeForces上举办了一场比赛,要求必须使用ADA语言提交.顿时虐爆了我这个只知道pascal,C,BASIC这3种语系的菜.今天闲着看了看这种语言,一看才知道竟然是美国军方专用 ...

  8. BZOJ4294 : [PA2015]Fibonacci

    斐波那契数列模$10^m$的循环节为$6\times10^m$,于是从低位到高位dfs即可. #include<cstdio> #include<cstring> #defin ...

  9. BZOJ 1121 & science

    1121: [POI2008]激光发射器SZK Time Limit: 10 Sec Memory Limit: 162 MB Submit: 647 Solved: 537 [Submit][Sta ...

  10. GSS系列(1)——GSS1&&GSS3

    题意:询问一个区间内的最大连续子段和(GSS1),并且有单点修改的操作(GSS2). 思路:这个题目在老人家的大白鼠里出现过,不过那个是求两个下标,并且相同取更小值.——传的东西更多,判断也稍微繁琐一 ...