Ray Tracer
by Richard Pawson
View or download the C# workbook
Download a zip of the C# solution
View or download the VB workbook
Download a zip of the VB solution
![](raytracer.png)
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 produces 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 - 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 used 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 was 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 trouble some years ago!
Part II is devoted to explanations and test questions about vector operations. The program also 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.
If you want to explore the whole source code (of my version), it is available on GitHub here: https://github.com/MetalUp/RayTracing.