Brandon Eleuterio

Articles

Learning Rust – Part 11: Positionable Camera

Brandon Eleuterio

In the previous post, we rendered a glass sphere. In this part, we venture into the world of camera positions.

Simple Code

We added several key parameters to our Camera struct to manage positions:

  1. look_from – the point from which the camera looks.
  2. look_at – the point the camera is pointing towards.
  3. vert_up – the roll or sideways tilt of the camera around the look_fromlook_at axis.
  4. vert_field_of_view – the vertical aspect ratio.

We also consolidated the remainder of the camera code and moved it from main.rs into the camera.rs file. Check out a few of the options this code gives us:

Wide Angle

Wide Angle Camera
Wide Angle

Rotation at a Distance

Rotation at a Distance
Rotation at a Distance

Zooming In

Zoom In
Zooming In

Up Next, Defocusing

Now that we’ve tightened up our camera code, there’s one more piece to address – defocus blur, otherwise known as depth of field. That’s next time. Until then, feel free to peek at the code and follow along with the online book I’m using for this project, Ray Tracing In One Weekend.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top