Ray Tracer Camera

Started by
2 comments, last by MJP 16 years ago
I've implemented a basic ray tracer just for kicks and so far everything is working as expected. It's an interesting process. I am enjoying it. Anyway... Right now, I have a camera class, a buffer class, and a scene class, among others. The camera holds the position of the "eye" and thus the origin of the rays it shoots. The buffer holds the imaginary plane (or quad in this case as it isn't endless) that represents each pixel on the screen. This accepts a pixel and then determines the scene coordinates for later calculation. For example, my screen is 800 by 600 pixels. The plane is 8.0 units by 6.0 units and therefore the top-left most pixel is (-4, 3) and the bottom-right most pixel is (4, -3); it is centered at (0, 0, 0). (I do this so that I can position elements in the scene by a standard coordinate as opposed to using pixels values. Maybe my methodology is faulty?) Now I want to add another feature; the ability to move the camera (pre-render, not real-time of course). I'd like to give the camera location and the focal point (maybe an up vector a la gluLookAt()) and then have the buffer plane adjust its coordinates accordingly. Right now, by default, it sits on the xy plane (z = 0) with the camera positioned at (0, 0, -5) and looking down the z-axis. What if I want the camera to look down an arbitrary line, and not the z-axis? The numbers aren't as nice anymore. I've read about matrices and if I'm not mistaken, they can be used here. How do I represent my "plane" so I can easily adjust it? My initial thoughts were to take the camera position and subtract the focal point to get a "normal vector" for the screen plane. Then I could make up a quad perpendicular to said vector of X width and Y height. Sorry for being long-winded. It's difficult to convey a visual situation with words. I know it's clear in my head, but it probably isn't for someone who might be trying to understand me. Thanks in advance.
James
Advertisement
What you want is a "view transform", which is typically a 4x4 matrix that is the result of one or more rotations and translations. Typically this matrix is then applied to all the objects you're rendering, which "brings them" to the camera's position and orientation.

If you want to create a view matrix in the same manner as gluLookAt, the docs show you how the matrix is constructed from the parameters.
Quote:Original post by MJP
What you want is a "view transform", which is typically a 4x4 matrix that is the result of one or more rotations and translations. Typically this matrix is then applied to all the objects you're rendering, which "brings them" to the camera's position and orientation.

If you want to create a view matrix in the same manner as gluLookAt, the docs show you how the matrix is constructed from the parameters.


Thanks for the response.

Would I then multiply the view transform matrix with the position vectors?
James
Quote:Original post by JBS103
Quote:Original post by MJP
What you want is a "view transform", which is typically a 4x4 matrix that is the result of one or more rotations and translations. Typically this matrix is then applied to all the objects you're rendering, which "brings them" to the camera's position and orientation.

If you want to create a view matrix in the same manner as gluLookAt, the docs show you how the matrix is constructed from the parameters.


Thanks for the response.

Would I then multiply the view transform matrix with the position vectors?


Yup, using standard matrix multiplication (matrix * vector). That will give you an objects position relative to the camera's position and orientation, so you can proceed to ray-trace just like you did before.

This topic is closed to new replies.

Advertisement