Pbrt 2: How does LookAt work? back

Board: Home Board index Raytracing General Development

(L) [2015/01/19] [ost by Julian] [Pbrt 2: How does LookAt work?] Wayback!

Currently I am reading the PBRT 2 book. Now I am a bit confused about the LookAt function.
I placed a sphere at (0, 0, 0) – since I want to look at this sphere I want to place the eye point at (0, 0, -5) and want to look at (0, 0, 0). The up-vector should be (0,1,0)
I tried this:
Code: [LINK # Select all]    BoxFilter b(1,1);
    float screen[4];
    screen[0] = -1.f;
    screen[1] = 1.f;
    screen[2] = -1.f;
    screen[3] = 1.f;
    ImageFilm film(100, 100, &b, screen, "muh.exr",false);
    
    auto t = LookAt(
        Point(0, 0, -5),
        Point(0, 0, 0),
        Vector(0, 1, 0));
    AnimatedTransform cam2world(
        &t,
        0.0f,
        &t,
        10.0f
    );
    PerspectiveCamera p(cam2world, screen,
        0, 0, 0, 0, 55.0f, &film);
    CameraSample s;
    s.imageX = 50;
    s.imageY = 50;
    s.time = 0;
    s.lensU = 0;
    s.lensV = 0;
    Ray r;
    p.GenerateRay(s, &r);

The ray looks like this
r.orgin = o = {x=0.000000000 y=0.000000000 z=5.00000000 }
r.direction = d = {x=0.000000000 y=0.000000000 z=1.00000000 }

Actually I expected the ray origin at Point(0, 0, -5) and not (0, 0, 5) since in world space the ray should start at z = -5. Any ideas what I am doing wrong?
(L) [2015/01/20] [ost by sriravic] [Pbrt 2: How does LookAt work?] Wayback!

Hi

PerspectiveCamera constructor accepts a transform of the form camToWorld whereas the lookat computes worldToCam as the main transform. I guess you have to invert this transform and send it to PerspectiveCamera.

back