返回介绍

Camera.ViewportToScreenPoint 视窗转屏幕位置

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

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

Description 描述

Transforms position from viewport space into screen 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的位置是以世界单位衡量的到相机的距离。

Screenspace is defined in pixels. The bottom-left of the screen is (0,0); the right-top is (pixelWidth,pixelHeight). The z position is in world units from the camera.

屏幕空间以像素定义。屏幕的左下为(0,0);右上是(pixelWidth,pixelHeight),Z的位置是以世界单位衡量的到相机的距离。

JavaScript:

	// Draw an image based on normalized view coordinates
	// rather than pixel positions.
	var bottomPanel: Texture2D;
 
	function VPToScreenPtExample() {
		var origin = Camera.main.ViewportToScreenPoint(new Vector3(0.25, 0.1, 0));
		var extent = Camera.main.ViewportToScreenPoint(new Vector3(0.5, 0.2, 0));
 
		GUI.DrawTexture(new Rect(origin.x, origin.y, extent.x, extent.y), bottomPanel);
	}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    public Texture2D bottomPanel;
    void VPToScreenPtExample() {
        Vector3 origin = Camera.main.ViewportToScreenPoint(new Vector3(0.25F, 0.1F, 0));
        Vector3 extent = Camera.main.ViewportToScreenPoint(new Vector3(0.5F, 0.2F, 0));
        GUI.DrawTexture(new Rect(origin.x, origin.y, extent.x, extent.y), bottomPanel);
    }
}

Camera

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

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

发布评论

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