Added code to organize rays before tracing.

In theory this will allow better traversal order and thus faster trace
times, but on most of the scenes so far it actually makes things very
slightly slower.