在光线跟踪器中设置相机设置中的向上矢量 [英] Setting the up vector in the camera setup in a ray tracer

查看:303
本文介绍了在光线跟踪器中设置相机设置中的向上矢量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读计算机图形的基础知识,并尝试设置自己的光线跟踪器。该书说构建相机框架的最常见的方法是从视点,其变为e,视图方向,其是-w和向上向量,其用于构造具有v和w在平面由视图方向和上方向定义

I'm reading fundamentals of computer graphics and trying to set up my own ray tracer. the book says "The most common way to construct the camera frame is from the viewpoint, which becomes e, the view direction, which is−w, and the up vector, which is used to construct a basis that has v and w in the plane defined by the view direction and the up direction"

但是我遇到了 Ray-Tracing照相机,其说我们需要通过执行与照相机方向(w)的叉积来校正(斜率?)的向上矢量。为什么呢?

but then I came across Ray-Tracing Camera which says that we need to correct the up vector for the (slope?) by performing a cross product with the camera direction (w). Why is that?

我用lookAt(0,0,0)和向上(0,1,0)呼叫我的相机设置

I'm calling my camera setup with lookAt(0,0,0) and up(0,1,0)

// a camera can be constructed using a position, direction and an up vector
Camera::Camera(Vector position, Vector lookAt, Vector up) {
    this->position = position;
    this->lookAt = lookAt;

    // the difference between camera position and where we want
    // to look at is the direction of the camera
    Vector direction = lookAt.diff(position);

    // camera frame
    w = direction.normalize();
    v = up.cross(w).normalize(); // right vector


    // which is the correct up?
    u = up.normalize();
    printf("%.2f %.2f %.2f\n", u.getX(), u.getY(), u.getZ()); // prints 0 1 0

    u = v.cross(w).normalize(); // the up vector
    printf("%.2f %.2f %.2f\n", u.getX(), u.getY(), u.getZ()); // prints 0.31 -0.86 -0.41
}


推荐答案

p>你最终需要的是一对矢量,形成一个正交基准的图像平面。其中一个将指向相对于相机的方向的右侧。

What you need in the end is a pair of vectors that forms an orthonormal basis for the image plane. One of those is going to point to the right relative to the orientation of the camera. The other is going to point up relative to the orientation of the camera.

如果向上向量是一般的天空就是这样,如果你的相机是不水平,则向上向量和相机向上向量将略有不同。向上向量是一个提示你想要的方向,但它不是完全正确的向量。在这种情况下,您可以使用方向向量交叉右向量,这将给出一个位于图像平面中并垂直于右向量的向量。

If the up vector is a general "the sky is that way," and if your camera is not level, then the up vector and the camera-up vector will be slightly different. The up vector is a hint as to the orientation you want, but it's not exactly the right vector. In this case, you can cross the right vector with the direction vector, and that'll give you a vector that lies in the image plane and is perpendicular to the right vector. That's what you want.

如果向上向量是一般的天空就是这样,如果你的相机向上向量和camera_up向量将完全相同。额外的交叉乘积将是不必要的,但如果你想让代码一般来处理第一种情况,则没有什么危害。

If the up vector is a general "the sky is that way," and if your camera is level, then the up vector and the camera_up vector will be exactly the same. The extra cross product would be unnecessary, but there's no harm in it if you want the code to be general enough to handle the first case.

也许一些ASCII艺术可以帮助澄清...

Perhaps some ASCII art can help clarify...

^                                        * look-at point
| "up"        "camera up"
|                  \ 
|       image plane \
                     \
                 "camera down"

是直的。查看点高于摄像机,因此摄像机必须向后倾斜一点。在图中,我们看到图像平面的边缘。 右向量在该平面中并从图中指出。方向向量(您的代码称为 w )垂直于图像,并直接指向查找点。

The up vector is straight up. The look-at point is higher than the camera, so the camera must tilt back a little bit. In the diagram, we see the edge of the image plane. The "right" vector is in that plane and pointed out of the diagram. The direction vector (which your code called w) is perpendicular to the image and points directly at the look-at point.

摄影机向上向量(代码中的 u )必须位于图像平面中,因此我们不能使用向上。它必须垂直于右向量。最简单的方法就是交叉这两个向量。

The camera-up vector (u in your code) must lie in the image plane, so we can't just use "up". And it must be perpendicular to the "right" vector. The easiest way to get that is to cross those two vectors.

因为我们用原来的向量生成了右向量,它给了我们方向。

Since we generated the "right" vector in terms of the original up vector, that gives us the orientation.

这篇关于在光线跟踪器中设置相机设置中的向上矢量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆