Skip to main content

Ray Tracing

Downloaded: 28

Last edit: 10 December 2021

English Key Stage 16-18 Years (KS5)
Resource Type Worksheets and Activities, Lessons
Curriculum Topic Programming

This resource forms part of the Computer Science from the Metal Up series.

I like to use case studies in programming - getting pupils to explore well-written existing programs to see what they can learn from them. I even think there is merit in getting them to explore programs that they probably aren't going to fully understand - to get the idea that they can understand some of it, enough even to be able to modify it.

This one uses a program that does Ray Tracing graphics - a far from a trivial challenge. I did not write the original version of this program (that was Luke Hoban, acknowledged at the start of the resource), but I have modified his original somewhat for the purposes of creating a teaching resource.

The program is principally written in the OOP paradigm, and is a good advertisement for the benefits of OOP. Part I of the resource, therefore, explores the program to revise and reinforce understanding of OOP, both with explanations and questions for the pupil to answer.

The program also relies heavily on vector operations. Luke's original version uses the in-built Microsoft Vector3D type. I changed this to my own class (Vector3) for several reasons:

  • The pupil can see the source code readily.
  • My Vector3 is a class not a struct. (I feel it would be confusing in the context of reinforcing OOP to explain why Vector3D was a struct and exactly what the difference between a struct and class is.
  • The Microsoft Vector3D is mutable! This is a surprising decision by Microsoft since the general rule is that structs should be immutable. As I have related elsewhere, this actually caused me a huge amount of troublesome years ago!

Part II is therefore devoted to explanations and test questions about vector operations. The program makes a small amount of use of Functional Programming techniques, and these are explored in Part III. This resource may be used for revision/reinforcement of all three topics. It is not suitable as an introduction to any of them, however.

This resource is available in both C# and VB versions, and, in each case, as a separate Student and Teacher version (the latter having the model answers to exercises and additional notes). There is also a simple EAD for capturing answers to exercises. .zipped up versions of the program are attached. If you want to explore the whole source code (of my version), it is available on GitHub here: https://github.com/MetalUp/RayTracing.

There is also a version where I have separated the solution into four projects, adopting the 'separation of concerns' principle. That is my preferred style, but I felt that it added unnecessary complexity to this case study for the teaching resource.