Version: 2020.2
public static Matrix4x4 Ortho (float left, float right, float bottom, float top, float zNear, float zFar);

参数

left 左侧 x 坐标。
right 右侧 x 坐标。
bottom 下方 y 坐标。
top 上方 y 坐标。
zNear 近深度裁剪面值。
zFar 远深度裁剪面值。

返回

Matrix4x4 投影矩阵。

描述

创建正交投影矩阵。

返回矩阵在用作摄像机的投影矩阵时,会创建 处于 toptoptopbottom 之间的区域的投影,将 zNearzFar 作为一个立方体中的近和远深度裁剪面, 从 (left, bottom, near) = (-1, -1, -1) 到 (right, top, far) = (1, 1, 1)。

返回矩阵嵌入了 z 翻转操作,其用途是取消摄像机视图矩阵执行的 z 翻转。 如果视图矩阵是单位矩阵或某种不执行 z 翻转的自定义矩阵,请考虑将投影矩阵 的第三列(即 m02、m12、m22 和 m32)乘以 -1。

Unity 中的投影矩阵遵循 OpenGL 约定,即裁剪空间近平面处于 z=-1,而远平面处于 z=1

请注意,根据使用的图形 API,着色器中的投影矩阵可能会遵循不同的约定,例如 D3D 样式 裁剪空间的近平面处于 0,而远平面处于 1;“反转 Z”投影的近平面处于 1,而远平面处于 0。 若要计算适合于传递给着色器变量的投影矩阵值,请使用 GL.GetGPUProjectionMatrix

using UnityEngine;

public class ExampleScript : MonoBehaviour { void Start() { // create orthographic matrix var matrix = Matrix4x4.Ortho(-4, 4, -2, 2, 1, 100); // will print: // 0.25000 0.00000 0.00000 0.00000 // 0.00000 0.50000 0.00000 0.00000 // 0.00000 0.00000 -0.02020 -1.02020 // 0.00000 0.00000 0.00000 1.00000 Debug.Log("projection matrix\n" + matrix);

// get shader-compatible projection matrix value var shaderMatrix = GL.GetGPUProjectionMatrix(matrix, false); // on a Direct3D-like graphics API, will print: // 0.25000 0.00000 0.00000 0.00000 // 0.00000 0.50000 0.00000 0.00000 // 0.00000 0.00000 0.01010 1.01010 // 0.00000 0.00000 0.00000 1.00000 Debug.Log("shader projection matrix\n" + shaderMatrix); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961