opengl - OpenGL的LookAt函数中的UP向量到底是什么?

标签 opengl glulookat

这与The LookAt target location doesn't matter if it is z = 0 or z = 1000 or -1000?有关

我试过了

    gluLookAt(512, 384, 2000,
              512, 384, 0,
              0.0f, 1.0f, 0.0f);

一切正常,现在我将第三行(UP vector )的最后一个数字更改为0.8:
    gluLookAt(512, 384, 2000,
              512, 384, 0,
              0.0f, 1.0f, 0.8f);

完全相同...接下来,我尝试并修改了第三行,第一个数字为0.8:
    gluLookAt(512, 384, 2000,
              512, 384, 0,
              0.8f, 1.0f, 0.8f);

现在, View 就像向左旋转45度。 UP vector 如何工作?

最佳答案

向上 vector 用于在提供给gluLookAt的眼睛和中心 vector 之间创建叉积。

在iOS上的GLKit header 中,您可以看到以下实现:

static __inline__ GLKMatrix4 GLKMatrix4MakeLookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)
{
    GLKVector3 ev = { eyeX, eyeY, eyeZ };
    GLKVector3 cv = { centerX, centerY, centerZ };
    GLKVector3 uv = { upX, upY, upZ };
    GLKVector3 n = GLKVector3Normalize(GLKVector3Add(ev, GLKVector3Negate(cv)));
    GLKVector3 u = GLKVector3Normalize(GLKVector3CrossProduct(uv, n));
    GLKVector3 v = GLKVector3CrossProduct(n, u);

    GLKMatrix4 m = { u.v[0], v.v[0], n.v[0], 0.0f,
        u.v[1], v.v[1], n.v[1], 0.0f,
        u.v[2], v.v[2], n.v[2], 0.0f,
        GLKVector3DotProduct(GLKVector3Negate(u), ev),
        GLKVector3DotProduct(GLKVector3Negate(v), ev),
        GLKVector3DotProduct(GLKVector3Negate(n), ev),
        1.0f };

    return m;
}

这个问题中可接受的答案How do I use gluLookAt properly?很好地描述了上行 vector 的实际影响。

(The intuition behind the "up" vector in gluLookAt is simple: Look at anything. Now tilt your head 90 degrees. Where you are hasn't changed, the direction you're looking at hasn't changed, but the image in your retina clearly has. What's the difference? Where the top of your head is pointing to. That's the up vector.)

关于opengl - OpenGL的LookAt函数中的UP向量到底是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10635947/

相关文章:

使用 gluLookAt() 的 OpenGL FPS 相机

OpenGL - FPS 风格相机移动,物体固定在相机上

c++ - gluLookAt 中的不连续性

OpenGL gluLookAt() 未按预期工作

c++ - 从另一个应用程序获取一个应用程序的 OpenGL 输出

c++ - 如何动态跟踪 OpenGL 中的纹理单元?

java - 旧版 OpenGL 纹理

c++ - openGL - 使用 gluLookAt 在对象上方和下方旋转

opengl - 现代OpenGL : Draw a sphere and cylinder

来自模型 View 矩阵的 openGL 位置和方向