UnityAPI手册-2019.4官网版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Camera.projectionMatrix
# [Camera](https://docs.unity3d.com/cn/2019.4/ScriptReference/Camera.html).projectionMatrix public [Matrix4x4](https://docs.unity3d.com/cn/2019.4/ScriptReference/Matrix4x4.html) **projectionMatrix** ; ## 描述 设置自定义投影矩阵。 如果更改该矩阵,摄像机将不再根据其 [fieldOfView](https://docs.unity3d.com/cn/2019.4/ScriptReference/Camera-fieldOfView.html) 更新渲染。 在调用 [ResetProjectionMatrix](https://docs.unity3d.com/cn/2019.4/ScriptReference/Camera.ResetProjectionMatrix.html) 之前,该设置持续有效。 仅在您确实需要非标准投影时,才使用自定义投影。 Unity 的水渲染使用该属性设置一个 *倾斜投影*矩阵。要使用自定义投影,您必须具备良好的 变换和投影矩阵知识。 注意,可以根据平台和其他状态修改 传递给着色器的投影矩阵。如果需要从摄像机投影计算 供着色器使用的投影矩阵,请使用 [GL.GetGPUProjectionMatrix](https://docs.unity3d.com/cn/2019.4/ScriptReference/GL.GetGPUProjectionMatrix.html)。 另请参阅:[Camera.nonJitteredProjectionMatrix](https://docs.unity3d.com/cn/2019.4/ScriptReference/Camera-nonJitteredProjectionMatrix.html) ``` // Make camera wobble in a funky way! using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { public Matrix4x4 originalProjection; Camera cam; void Start() { cam = GetComponent<Camera>(); originalProjection = cam.projectionMatrix; } void Update() { Matrix4x4 p = originalProjection; p.m01 += Mathf.Sin(Time.time * 1.2F) * 0.1F; p.m10 += Mathf.Sin(Time.time * 1.5F) * 0.1F; cam.projectionMatrix = p; } } ``` ``` // Set an off-center projection, where perspective's vanishing // point is not necessarily in the center of the screen. // // left/right/top/bottom define near plane size, i.e. // how offset are corners of camera's near plane. // Tweak the values and you can see camera's frustum change. using UnityEngine; using System.Collections; [ExecuteInEditMode] public class ExampleClass : MonoBehaviour { public float left = -0.2F; public float right = 0.2F; public float top = 0.2F; public float bottom = -0.2F; void LateUpdate() { Camera cam = Camera.main; Matrix4x4 m = PerspectiveOffCenter(left, right, bottom, top, cam.nearClipPlane, cam.farClipPlane); cam.projectionMatrix = m; } static Matrix4x4 PerspectiveOffCenter(float left, float right, float bottom, float top, float near, float far) { float x = 2.0F * near / (right - left); float y = 2.0F * near / (top - bottom); float a = (right + left) / (right - left); float b = (top + bottom) / (top - bottom); float c = -(far + near) / (far - near); float d = -(2.0F * far * near) / (far - near); float e = -1.0F; Matrix4x4 m = new Matrix4x4(); m[0, 0] = x; m[0, 1] = 0; m[0, 2] = a; m[0, 3] = 0; m[1, 0] = 0; m[1, 1] = y; m[1, 2] = b; m[1, 3] = 0; m[2, 0] = 0; m[2, 1] = 0; m[2, 2] = c; m[2, 3] = d; m[3, 0] = 0; m[3, 1] = 0; m[3, 2] = e; m[3, 3] = 0; return m; } } ```
da
2022年5月24日 10:23
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码