博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Transform.InverseTransformPoint 反向变换点
阅读量:6862 次
发布时间:2019-06-26

本文共 2430 字,大约阅读时间需要 8 分钟。

JavaScript ⇒ public function InverseTransformPoint(position: ): ; 

C# ⇒public  InverseTransformPointposition);

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.

注意,返回位置受缩放影响。如果你是处理方向使用。

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): ; 

C# ⇒public  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.

注意,返回位置受缩放影响。如果你是处理方向使用。

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 
其实吧 就是在编辑器里把物体拽到根目录下的位置和物体在某物体内的位置之间的一个转换

 

 

 

转载于:https://www.cnblogs.com/mimime/p/6237039.html

你可能感兴趣的文章
Shiro 权限管理filterChainDefinitions过滤器配置
查看>>
我的友情链接
查看>>
Python 文件I/Oday14
查看>>
回忆Spring IOC 几个注解&简单示例
查看>>
及时更新网卡驱动可使无线网络更稳定
查看>>
在if中赋值,但在if外却提示“使用了未赋值的局部变量”
查看>>
MapReduce源码之OutputFormat
查看>>
资质申报 - 系统集成企业资质等级评定条件实施细则
查看>>
近一个月的面试总结
查看>>
eclipse安装插件
查看>>
perl 非贪婪正则匹配 mysql 导出指定字段
查看>>
Android状态栏黑色字体
查看>>
MySQL主从复制之主库宕机处理
查看>>
Spring Cloud Eureka 源码分析(二) 客户端启动过程
查看>>
LAMP
查看>>
常用的持续集成工具
查看>>
我的友情链接
查看>>
在ubuntu上面安装LAMP遇到的若干问题
查看>>
基于 Quartz 开发企业级任务调度应用
查看>>
hibernate flush 缓存
查看>>