返回介绍

Camera.ViewportToWorldPoint 视窗转世界位置

发布于 2019-12-18 15:37:29 字数 1791 浏览 951 评论 0 收藏 0

JavaScript => ViewportToWorldPoint(position: Vector3): Vector3;
C# => Vector3 ViewportToWorldPoint(Vector3 position);

Description 描述

Transforms position from viewport space into world space.

从视窗空间到世界空间的变换位置。

Viewport space is normalized and relative to the camera. The bottom-left of the camera is (0,0); the top-right is (1,1). The z position is in world units from the camera.

视窗空间是归一化的并相对于相机的,相机的左下为(0,0);右上是(1,1);Z的位置是以世界单位衡量的到相机的距离。

Note that it transforms a x-y screen position, into a x-y-z position in 3D space.

请注意它是变换一个x-y屏幕位置到一个3D空间的x-y-z位置。

You provide the function with a vector where the x-y components of the vector are the screen coordinates and the z component is the distance of the resulting plane from the camera.

这个函数带有在屏幕坐标的x-y组件向量,并且z组件是在从相机产生的平面的距离。

JavaScript:

	// Draw a yellow sphere at top-right corner of the near plane
	// for the selected camera in the scene view.
	function OnDrawGizmosSelected () {
		var p : Vector3 = camera.ViewportToWorldPoint (Vector3 (1,1, camera.nearClipPlane));
		Gizmos.color = Color.yellow;
		Gizmos.DrawSphere (p, 0.1);
	}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void OnDrawGizmosSelected() {
        Vector3 p = camera.ViewportToWorldPoint(new Vector3(1, 1, camera.nearClipPlane));
        Gizmos.color = Color.yellow;
        Gizmos.DrawSphere(p, 0.1F);
    }
}

Camera

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文