zoukankan      html  css  js  c++  java
  • Transform.InverseTransformPoint 反向变换点

    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 

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

  • 相关阅读:
    tornado+websocket+mongodb实现在线视屏文字聊天
    mongoexport 导出需要授权数据库中的集合 报错 Authentication failed.
    nginx日志中添加请求的response日志
    SSE(Server-sent events)技术在web端消息推送和实时聊天中的使用
    RESTful接口设计原则和优点
    一次请求中,经过 nginx+uWSGI+flask应用程序搭建服务的执行过程
    项目中记录影响性能的缓慢数据库查询
    macos Item2 添加 Shell Integration (ftp传输)
    windows安装 阿里云的Fun工具
    windows10安装docker[含百度网盘docker安装包]
  • 原文地址:https://www.cnblogs.com/mimime/p/6237039.html
Copyright © 2011-2022 走看看