简体   繁体   English

OpenGL 立体视图——如何使用 GLM 数学库进行水平偏移

[英]OpenGL Stereo View -- How to use GLM Math library for horizontal offset

I'm trying to use the GLM mathematics library to warp the projection matrix such that multiple cameras (eg a left eye and a right eye) are viewing the same view, but the camera frustum is distorted.我正在尝试使用 GLM 数学库来扭曲投影矩阵,以便多个相机(例如左眼和右眼)正在查看相同的视图,但相机视锥被扭曲。

This is what I am trying to do with my cameras using GLM:这就是我尝试使用 GLM 对我的相机做的事情:

image图片在此处输入图片说明

Note: One of the challenges I have for my camera, is that I only have in my OpenGL Graphics API a read-only view matrix and projection matrix.注意:我的相机面临的挑战之一是我的 OpenGL 图形 API 中只有一个只读视图矩阵和投影矩阵。 So even once I have the view and projection matrix, I can only move my camera using x,y,z for eye position, and then yaw,pitch,roll for view direction.因此,即使有了视图和投影矩阵,我也只能使用 x、y、z 来移动我的相机作为眼睛位置,然后使用偏航、俯仰、滚动作为视图方向。 Then I have standard OpenGL calls, but I am not sure how to shift or warp the projection matrix as shown below.然后我有标准的 OpenGL 调用,但我不确定如何移动或扭曲投影矩阵,如下所示。

I think this second picture also accurately shows what I am trying to achieve with OpenGL.我认为第二张图片也准确地显示了我试图用 OpenGL 实现的目标。

Any tips on how to approach this problem?有关如何解决此问题的任何提示? Do I need to implement a special lookAt function, or is there something built into GLM that can help me compute the right view?我是否需要实现一个特殊的 lookAt 函数,或者 GLM 中是否有内置的东西可以帮助我计算正确的视图?

在此处输入图片说明

A possible way to do this is:一种可能的方法是:

  • Assume that X is the position of the "nose" (the half point between the 2 eyes).假设 X 是“鼻子”的位置(两只眼睛之间的半点)。

  • Let V be the direction orthogonal to the left eye - right eye line.令 V 为与左眼-右眼线正交的方向。

  • The function X + t * V describes the "line of sight" in your last picture.函数 X + t * V 描述了您最后一张图片中的“视线”。

  • Take t > 0 and set that as your look at point P/取 t > 0 并将其设置为点 P/

  • Create 2 cameras with centers at the eyes, both with the exact same up direction, then use glm::lookat to look at P.创建 2 个以眼睛为中心的相机,两者的向上方向完全相同,然后使用 glm::lookat 看 P。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM