Unity3D圣典3.3版本-中文版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Camera.projectionMatrix 投影矩阵
# [Camera](Camera.html).projectionMatrix 投影矩阵 var *projectionMatrix* : [Matrix4x4](../Matrix4x4/Matrix4x4.html) *Description* 描述 Set a custom projection matrix. 设置自定义的投影矩阵。 If you change this matrix, the camera no longer updates its rendering based on its [fieldOfView](Camera.fieldOfView.html). This lasts until you call [ResetProjectionMatrix](Camera.ResetProjectionMatrix.html). 如果你改变这个矩阵,相机的渲染不再基于它的 [fieldOfView](Camera.fieldOfView.html) 更新,直到调用 [ResetProjectionMatrix](Camera.ResetProjectionMatrix.html). Use a custom projection only if you really need a non-standard projection. This property is used by Unity's water rendering to setup an oblique projection matrix. Using custom projections requires good knowledge of transformation and projection matrices. 只有当真正需要一个非标准的投影时,才使用自定义投影。这个属性被 Unity 的水渲染使用来设置一个 oblique projection 矩阵。使用自定义投影需要了解变换和投影矩阵。 * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : MonoBehaviour { public Matrix4x4 originalProjection; 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; camera.projectionMatrix = p; } public void Awake() { originalProjection = camera.projectionMatrix; } } ``` ``` // Make camera wobble in a funky way! //让相机以流行的方式晃动 var originalProjection : Matrix4x4; originalProjection = camera.projectionMatrix; function Update () { var p : Matrix4x4 = originalProjection; // change some values from the original matrix //改变原始矩阵的某些值 p.m01 += Mathf.Sin (Time.time * 1.2) * 0.1; p.m10 += Mathf.Sin (Time.time * 1.5) * 0.1; camera.projectionMatrix = p; } ``` * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : 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; 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; 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; } } ``` ``` // 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. //改变这个值你就能看到相机视图的变化 @script ExecuteInEditMode var left : float = -0.2; var right : float = 0.2; var top : float = 0.2; var bottom : float = -0.2; function LateUpdate () { var cam : Camera = camera; var m : Matrix4x4 = PerspectiveOffCenter( left, right, bottom, top, cam.nearClipPlane, cam.farClipPlane ); cam.projectionMatrix = m; } static function PerspectiveOffCenter( left : float, right : float, bottom : float, top : float, near : float, far : float ) : Matrix4x4 { var x : float = (2.0 * near) / (right - left); var y : float = (2.0 * near) / (top - bottom); var a : float = (right + left) / (right - left); var b : float = (top + bottom) / (top - bottom); var c : float = -(far + near) / (far - near); var d : float = -(2.0 * far * near) / (far - near); var e : float = -1.0; var m : 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月17日 13:30
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码