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 ...
随机推荐
- Grunt上手指南<转>
原文链接:http://www.hulufei.com/post/grunt-introduction 安装 如果之前有装过grunt,卸载之 npm uninstall -g grunt 安装gru ...
- 使用java自带的定时任务ScheduledThreadPoolExecutor
ScheduledThreadPoolExecutor是ThreadPoolExecutor的子类: JDK api里是这么说的: ThreadPoolExecutor,它可另行安排在给定的延迟后运行 ...
- jquery概要--基础01
jquery对象,DOM对象 var $cr = $('#cr'); var cr = $cr[0]; /var cr = $cr.get(0); var cr = document ...
- js:数据结构笔记2---列表
列表: 定义:一组有序的数据: function List() { this.listSize = 0; this.pos = 0; this.dataStore = []; this.find = ...
- json学习系列(1)-使用json所要用到的jar包下载
内容来源于互联网. json是个非常重要的数据结构,在web开发中应用十分广泛.每个开发者都应该好好的去研究一下json的底层实现.在使用json之前首先要明白需要哪些jar文件,初次使用的时候很容易 ...
- LightOJ1032 Fast Bit Calculations(数位DP)
显然数位DP. dp[i][j]表示所有末尾为j的i位二进制数相邻位的数量和 初始状态dp[2][1]=1 从长度i-1转移到长度i就是在i-1位的末尾添上0或1,转移方程就是: dp[i][0]=d ...
- BZOJ1508 : [NOI2003]Game
a[i][j]:i移动一根变成j是否可能 b[i][j]:i增加一根变成j是否可能 枚举在一个数字中移动的情况以及在两个数字中移动的情况 #include<cstdio> #include ...
- HDU 2222(AC自动机模板题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2222 题目大意:多个模式串.问匹配串中含有多少个模式串.注意模式串有重复,所以要累计重复结果. 解题 ...
- JAVA计算文件大小
File f = new File(save_path+File.separator + resouce_id+".zip"); FileInputStream fis = new ...
- FFMPEG解码流程
FFMPEG解码流程: 1. 注册所有容器格式和CODEC: av_register_all() 2. 打开文件: av_open_input_file() 3. 从文件中提取流信息: av_f ...