Unity 3D--定义摄像机的投影矩阵
2013-04-11 11:27
549 查看
Camera.projectionMatrix 投影矩阵
如果你改变这个矩阵,相机的渲染不再基于它的fieldOfView更新,直到调用ResetProjectionMatrix.只有当真正需要一个非标准的投影时,才使用自定义投影。这个属性被Unity的水渲染使用来设置一个oblique projection 矩阵。使用自定义投影需要了解变换和投影矩阵。
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; } }
可以发现摄像机投影矩阵是个三行四列的矩阵;
//设置一个偏移中心的投影,这个透视的消失点没有必要在屏幕的中心 //定义近载面大小,例如相机的近裁面偏移中心多少 //改变这个值你就能看到相机视图的变化 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; } }
相关文章推荐
- Unity 3D-- 摄像机Clear Flags和Culling Mask属性用途详解
- 3d数学基础-缩放矩阵,投影矩阵-用C++实现
- 从零实现3D图像引擎:(13)把宽高比、透视投影矩阵、屏幕变换矩阵说透
- 3D中矩阵旋转、缩放及投影的公式
- Unity通过修改摄像头的投影矩阵,让画面得到镜像效果
- 介绍Unity中相机的投影矩阵与剪切图像、投影概念
- 将投影矩阵P利用QR分解分解出摄像机内外参数(Opencv)
- [3D基础]投影矩阵的推导(1)
- 写给VR手游开发小白的教程:(四)补充篇,详细介绍Unity中相机的投影矩阵
- Unity改变相机的投影矩阵来对面上的纹理进行裁切和缩放
- Unity 3D-- 摄像机Clear Flags和Culling Mask属性用途详解
- Unity 3D--摄像机平滑跟随(方法一)
- Unity 3D-- 摄像机Clear Flags和Culling Mask属性用途详解
- 摄像机、投影、3D旋转、缩放
- 【Unity 3D游戏开发学习笔记】总结摄像机和光源的使用方法
- 关于Unity中的3D数学基础知识<三>矩阵的基础知识和使用
- Unity 3D 矩阵和四元数的研究
- 转载:摄像机、投影、3D旋转、缩放
- Unity 3D--Camera摄像机组件
- Unity 3d 实现物体跟随摄像机视野运动