【问题标题】:Retrieve center point the viewer is looking at from view/perspective matrix从视图/透视矩阵中检索查看者正在查看的中心点
【发布时间】:2018-04-04 12:52:13
【问题描述】:

我使用 glMatrix 的方法:mat4.lookAt(out, eye, center, up) 在 WebGL 模型渲染时设置相机视图。

模型渲染后,我需要从视图/透视矩阵中检索center 属性。我知道如何检索eye 属性,但我不知道如何获得center 属性。我该怎么做?

这是我使用的mat4.lookAt 方法: http://glmatrix.net/docs/mat4.js.html#line1366

【问题讨论】:

  • 这不是 100%,但对于矩阵 M,它不应该是 M*(0,0,0)-M*(0,0,1) 吗?在任何情况下,您都无法获得用作输入的中心,因为 if 已转换为 forward = normalized(center-eye),这意味着距离将永远丢失。不知道你在找什么。

标签: gl-matrix


【解决方案1】:

您无法获得实际的中心,因为它已标准化。您可以获得一个中心位置,该位置将产生相同的外观。我想应该是这个。

camera = mat4.inverse(mat4.create(), view);
up = camera.slice(4, 7);
eye = camera.slice(12, 15);
negativeZ = camera.slice(8, 11);
center = vec3.scaleAndAdd(vec3.create(), eye, negativeZ, -1);

该中心将是眼前的一个单位。将-1 更改为-1 * units 使其远离眼睛。换句话说,-2 是前面两个单位,-3 是前面三个单位,以此类推。

这是一个测试

const eye = [1, 2, 3];
const center = [4, 5, 6];
const up = [0, 1, 0];
const view = mat4.lookAt(mat4.create(), eye, center, up);

const camera = mat4.invert(mat4.create(), view);
const newUp = camera.slice(4, 7);
const newEye = camera.slice(12, 15);
const negativeZ = camera.slice(8, 11);
const newCenter = vec3.scaleAndAdd(vec3.create(), newEye, negativeZ, -1);

const newView = mat4.lookAt(mat4.create(), newEye, newCenter, newUp);

// show difference between view and newView
console.log(view.map((v, i) => (v - newView[i]).toFixed(6)));
<script src="https://cdnjs.cloudflare.com/ajax/libs/gl-matrix/2.4.0/gl-matrix-min.js"></script>

This article explains the parts of a camera matrix and what a view matrix is.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多