The first rule is don't write two versions. It's tempting to write the desktop version of your 3D program and then write a second VR version. I used to do so myself. If, and only if, you intend to write one VR program which will only ever run on one particular system, this can be a bit quicker.
This is hardly ever true. Once you've written a desktop 3D program and begin working on the VR version, there will be bugs to fix, changes to make, improvements to add. Can you just apply these to the VR version and leave the desktop code unchanged? Probably not, especially for bug fixes, which means you have to keep the two versions in synch.
And if your VR program is any good, you'll eventually be asked to make it run on another VR system. Some use a single active shutter screen, some use dual polarized screens, some use headsets. The different versions quickly become impossible to manage.
The better approach is to have just one VR capable version. Redesign your program assuming that there may be more than one screen, that stereo (of two different kinds) may be used, and there may be a headtracker. Then treat the desktop as a single screen, non-stereo, non-headtracked VR display.
The second rule is runtime, user specified, configuration. In theory your VR program could probe the system to detect the number of screens, whether they are stereo capable, etc. In practice, you will want to be able to override such behaviour. Two examples: you may want to run the VR program on only one screen of a dual screen system with the other displaying a second application; or you may want to run your VR program in mono rather than stereo so that a photographer can get a clean image. Neither of these is an unusual requirement, and both are impossible if your program relies on the operating system rather than the user for configuration.
My VR programs start by reading a simple text file that looks like:
[visual] numscreens = 2 stereo=1 near=0.1 eyesep = 0.05 head=0.5 # Dimensions size[0] = (2.94,2.2) size[1] = (2.94,2.2) hpr[0] = (45,0,0) hpr[1] = (-45,0,0) # Distance is directly facing screen, not angular distance # from origin dist[0] = 1.47 dist[1] = 1.47
Users can move the program to a different VR display just by editing the text instead of having to recompile. If there isn't a VR config file present at runtime, the program assumes it is running on a desktop and creates the simplest one screen non-stereo configuration.
Next:View calculations for VR displays
Back to 3D Graphics