Perspective的矩阵计算方法

本文详细介绍了高通VR系统中通用透视矩阵的计算方法,包括关键参数的设定与矩阵元素的计算公式。通过具体代码示例,展示了如何根据左、右、上、下、近、远平面设置透视矩阵,并调整输出图像的分辨率比率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

高通VR里面的通用透视矩阵计算方法

 static public Matrix4x4 Perspective(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;
 }
 float baseLen = 0.06f;//一般设为0.05~0.08之间
Frustums = new ViewFrustum[2];
Frustums[0].left = -baseLen;
Frustums[0].right = baseLen;
Frustums[0].top = baseLen;
Frustums[0].bottom = -baseLen;
Frustums[0].near = 0.061f;
Frustums[0].far = 1000f;

 _projection = Perspective(frustum.left, frustum.right, frustum.bottom, frustum.top, frustum.near, _camera.farClipPlane);
 public void OnPreCull()
        {
            if (_camera != null)
            {
                //_camera.fieldOfView = 30f;
            _camera.projectionMatrix = _projection;

                //_camera.aspect = 1440/2560f;
            }
        }

此处的值和输出的单眼分辨率比率有关,通常是成正比,因为现在输出的是1:1的图像,所以现在需要将left,right和top,bottom保持一致,否则left/bottom=aspect=width/height;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值