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...

No comments: