PDA

View Full Version : Creating a camera for a raytracer...

lost
01-Dec-2003, 03:37
Hi, I am making a simple raytracer and am having troubles with setting up a camera position. First, let me say that I know my intersection functions are working properly and just my algorithm for creating a "camera" is not working properly.

I am inputting the camera position, where it is looking, and up vectors from a file (much like the gluLookAt function) and adding a FOV value. For his ray tracer I am having difficulty figuring out exactly how the camera should work.

For example, in a 640x480 window, with a FOV of 90 degrees, would the resulting vertical FOV only be 67.5 degrees?

My idea for a camera is something like this:

Figure out look at direction (camPosition-camLookAt)
Rotate the vector by the distance it is from the center times the cos of half the fov
trace the resulting vector

Is this a proper way of setting up a camera in this instance? The more I think, the more I believe that x=0 should be equivalent to cos(-fov/2) and y=0 should be equal to cos(fov/2) and then each unit moving would just add to those values.

Then the code would be (value x * camX vector + value y * camY vector + look direction) I am thinking then it might need to be multiplied by the camZ vector but not sure.

Then the resultant vector should be normalized and point in the correct direction.

Blah, I am rambling, but nothing Ive tried has worked, anyone have any ideas or relevant links? Thanks

Hyp-X
01-Dec-2003, 13:07
For example, in a 640x480 window, with a FOV of 90 degrees, would the resulting vertical FOV only be 67.5 degrees?

No, it's approx. 73.74 degrees...

Hyp-X
01-Dec-2003, 13:20
Btw the code is:

cam.right * (x*(2.0/w) - 1.0) * tan(0.5 * fov) + cam.up * (1.0 - y*(2.0/h)) * tan(0.5 * fov) * aspect + cam.forward

where x/y are screen coordinates, w/h are width/height of the screen, aspect is the ratio of the screen (usually 0.75), cam.* are unit vectors.

Edit: fixed */ to /

lost
01-Dec-2003, 16:11
Thanks for the help