Friday, February 8, 2008

Knowing Your Left From Your Right

Many people have noticed that models they have designed themselves end up incorrectly orientated when loaded into Rule the Rail. The same is true if original RtR models (.x files) are opened using the DirectX Viewer (DXViewer.exe) from the Microsoft DirectX SDK - they using end up facing nose down! For example, here is the initial rendering of Engine03 (mozda.x) when opened in DXViewer.exe:

mozda.x in DXViewer.exe: nose down and underside facing the viewer.

Being the kind of developer who needs to know how stuff works I tend to RTFM to work out why things like this are happening (here is the slightly painful to read entry from the DirectX SDK). The "problem" it seems is all down to choice of coordinate system.

RtR uses Microsoft DirectX to render its 3-D world. By default Microsoft has chosen the left-handed coordinate system with a vertical y-axis.

I suspect however that Brainbombers use modelling software that uses a different orientation as its default (but they don't say what software) and that they have coded RtR to use this orientation when rendering models. It looks as though they are using a right-handed vertical z-axis. I have tested this by performing a translation of the 2,708 mesh vertices in mozda.x from v0, v1, v2 to v1, v2, v0. The modified mozda.x looks like this when opened in DXViewer.exe:

Modified mozda.x in DXViewer.exe

The model is now correctly orientated. The reason it's black is because I didn't translate the mesh for the light source and the model is effectively being lit from the underside.

As I've never done any 3-D modelling I don't know how this all works when saving/exporting your work to the .x file format. I have seen many posts concerning which modelling software creates .x files that are compatible with RtR and re-orientating your model before saving so that it ends the right-way-up when loaded into RtR.

More 3-D findings to follow allow with an interesting discovery I have made concerning the usr.xli file...

The New Obsession Begins

My four year old son and I share a passion for trains which was probably all caused by living just a quarter of a mile across a field from the local station. From our cottage we can hear the trains coming and going. On a clear day with the wind in the right direction the alarm can be heard on the crossing. On very special occasions even real steam engines come through.

This passion has inevitably led to an interest in model trains. My Dad built me a simple Hornby layout when I was a child and now that my son is old enough he is moving from simple Brio wooden trains and Tomy Motor Road & Rail into the world of Hornby with Thomas & Friends.

Being a software engineer and web developer means there are plenty of computers in the house and we all enjoy spending time playing Lemmings, having fun at the CBeebies website and chatting with friends on Windows Live Messenger.

A while ago I picked up a second-hand copy of Hornby Virtual Railway on a charity stall. Although this kept us entertained for several months it is definately showing the signs of age. My son finds it fiddly to build new tracks and the 3D rendering engine is nearly a decade old.

Then, on a recent trip to Woolworths, we found Create Your Own MODEL RAILWAY Deluxe (Simply Trains gave it 9/10) in the bargain software bin. My son nearly wet himself with excitement when he saw it action for the first time! I was going to upgrade to HVR2 but it doesn't stand a chance now.

After a while though I started to wonder about the inner-workings of CyoMR and started poking around the installation directory. A quick search on Google turned up Having Fun with RTR and this is where I found out that CyoMR is a re-branded version of Rule the Rail! by Brainbombers. It wasn't long before I'd downloaded the free trial. Then I had to have the expansion packs - all 11 even of them - which meant I paid for registration even though I had a full working copy of CyoMR. In fact my son and I like it so much and the USD $15.00 price is so reasonable I registered another copy for each of us.

But my lust for all things code-based and a desire to know how stuff works has driven me to the Dark Side of virtual model railwaying...