Programmatic Design

The staircase in the background image heading this page doesn’t exist.

Well, that’s nothing new; we’ve all become used to seeing fabulous rooms and fabulous places in cinema that have been created entirely by clever computer graphics.

But what makes this scene special is that it wasn’t created in CAD software either: the whole scene was programmed. It was, in effect, created as maths!

The grand staircase splitting into two upper flights – a style known as an Imperial Staircase – its steps, its handrails, the huge tall double nine-pane sash window on the main landing – were all created directly in a computer program (as always I use US spelling for the things that run on computers).

Only the final rendering was done using off-the-shelf software, though I could have had a stab at that too!

It was programmed in C# primarily, although the whole project in which this was done also included a C++ portal to OpenGL, but I didn’t use that to render this image as I wanted richer texturing features that needed a fully-featured rendering system.

You can see samples of the code below:

  • The first shows part of my code for meshes, which are the main 3D elements used in the model, notwithstanding its “NURBSy” look. You will note that my rotor objects are called Q because I always prefer to use quaternion logic for rotation, although this code also includes fast rotations about the X, Y and Z axes which can be done more quickly using ordinary complex algebra (all that complicated trigonometry stuff we were all taught in school using sin and cos). You can see this code here.
  • The second bit of code is that for a generic sash window, which you can see here.