[csu540-f05-rpf] How to do perspective ray tracing
Robert Futrelle
futrelle at ccs.neu.edu
Tue Oct 4 14:06:00 EDT 2005
Note on perspective ray tracing for spheres
by Prof. Futrelle, 10/4/05
The trick is to get the geometry of your setup right.
I'll describe an example. Your initial tests can use
just one sphere at the origin, or in another simple
location, but with different perspectives,
to make sure things are working.
Here's a typical geometry you'd use for your final
system (larger than for a test system):
Say your solar system is 500 pixels (px) wide and 400 px
tall with a sun of R = 50 px. Assume your planets are
placed within r = 200 px of the sun and have radii
of the order of 10 to 20 px. They don't all have
to be in the xz plane.
Set your eyepoint at raye = 0,0,2000.
Have a color array 500x400.
Now comes the important part:
Set up an ViewArray in a "view plane" at z = 1000.
The ViewArray will also be 500x400.
The trick is to put the corner of the ViewArray
at x = -250, y = -200.
Now you step through i,j, for x and y.
For each i,j, you calculate the coordinates of
a vector rayd from the eyepoint as
x = -250 + i and y = -200 + j and z = 1000 - 2000 = -1000,
so that rayd is directed from the eyepoint into the
scene, along the negative z axis.
For each rayd, you solve to see if it hits any
sphere, and pick the closest hit, if any, and
the color of the planet, or sun, you hit.
The fun begins when you move the eyepoint further
away to get more of a "telephoto" view, or
move the ViewArray closer.
If you want a magnified view, so that a planet
fills your screen, you make the ViewArray smaller
but with the same number of pixels, e.g.,
a 500,400 array with spatial coordinates from
x = - 100 to +100 and y from -80 to +80.
Then the steps for your rayd positions would
be 2/5 i or j, not i or j as i and j range
over the 500x400 array.
N.B. You never actually need to construct the
ViewArray. It's just a way to organize your
computations. It's a set of parameters,
not an actual 2D array in your Java code.
If you want to construct an actual array
and store your rayd(i,j) values in it, that's OK.
Could be useful if you're using it over and
over as you change the scene - "As the World Turns".
Draw lots of pictures so you can 'see' what
I'm talking about. 2D pictures, with x coming
out of your page and y and z in the page,
should be all you need.
Go for it!
- Prof. Futrelle
More information about the csu540-f05-rpf
mailing list