Page 1 of 1

### Pbrt 2: How does LookAt work?

Posted: Mon Jan 19, 2015 10:13 am
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: 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?

### Re: Pbrt 2: How does LookAt work?

Posted: Tue Jan 20, 2015 2:33 pm
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.