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 ...
随机推荐
- 对学长所谓“改变世界的游戏”《shield star》的运行感想-毛宇部分(完整版本请参考团队博客)
对于学长项目<shield star>的思考和看法: Ryan Mao ((毛宇) 110616-11061171 试用了一下学长黄杨等人开发的<shield star>游戏 ...
- 属性动画PropertyAnimation
xml实现 <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="h ...
- jq验证插件validate
博客: http://www.cnblogs.com/linjiqin/p/3433635.html http://blog.csdn.net/windxxf/article/details/7520 ...
- COGS731 [网络流24题] 最长递增子序列(最大流)
给定正整数序列x1,..., xn (n<=500).(1)计算其最长递增子序列的长度s.(2)计算从给定的序列中最多可取出多少个长度为s的递增子序列.(3)如果允许在取出的序列中多次使用x1和 ...
- Sql 字符串替换
(1) 字符串替换 Update SongADD_EMH0055 SET songno = REPLACE(songno, '231', '233') where songno like '%1022 ...
- BZOJ2757 : [SCOI2012]Blinker的仰慕者
BZOJ AC900题纪念~~ 若K>0,则 设f[i][j]表示i位数字,积为j的数字的个数 g[i][j]表示i位数字,积为j的数字的和 DP+Hash预处理 查询时枚举LCP然后统计贡献 ...
- Session赋值(备注)
Session赋值也是在后台赋,不是在前台赋 追问 不好意思 那还真能在AJAX中赋值 我已经解决了 加一个接口IRequiresSessionState 就OK 提问者评价 太感谢了,真心有用
- TYVJ P1093 验证数独 Label:none
背景 XX学校风靡一款智力游戏,也就是数独(九宫格),先给你一个数独,并需要你验证是否符合规则. 描述 具体规则如下:每一行都用到1,2,3,4,5,6,7,8,9,位置不限,每一列都用到1,2,3, ...
- 【BZOJ】1901: Zju2112 Dynamic Rankings(区间第k小+树状数组套主席树)
http://www.lydsy.com/JudgeOnline/problem.php?id=1901 首先还是吐槽时间,我在zoj交无限tle啊!!!!!!!!我一直以为是程序错了啊啊啊啊啊啊. ...
- jstl fn标签
JSTL使用表达式来简化页面的代码,这对一些标准的方法,例如bean的getter/setter方法,请 求参数或者context以及session中的数据的访问非常方便,但是我们在实际应用中经常需要 ...