VR Zero - VR on the RaspberryPi, in Python

A long time ago, at a CamJam not too far away, the organisers (Mike and Tim) let me show'n'tell a Oculus Rift demo that I had created for the Raspberry Pi.

The demo was just under 1000 lines of Python and used the 'pyopengles' 3D library (and some custom libraries) to create a very simple Minecraft-esque island ('Blockworld') that you could navigate and look around with a Oculus Rift DK1 headset on.

It looked a bit like this:

The 'Blockworld' demo

The 'Blockworld' demo

Although it worked, and was physically portable too (using a USB battery pack), the performance was far from ok.  I had also wanted to make experimenting with VR easy enough such that children learning to code might be able to experiment with VR in Python on a Pi.

But, dealing with OpenGL ES 2.0 at such a low-level was not exactly fun, for anyone. The 3D library pi3d was in early development but I wasn't able to get it to do my bidding in the time I had available.

I had planned to one of those fabled 'great re-writes' but life, work and the world moved on, so the that didn't happen... until now...

Because I had recently celebrated a 'milestone' birthday and because I needed a short break from the low level development that I've being working on for the last few months; I decided to treat myself to working on something a bit flashy, colourful and gave instant gratification... that turned out to be VR on the Pi, again :)

Since the first (and only) public demo at the CamJam a number of things have happened:

  • the Pi 3 was released.
  • the Oculus DK2 (and CV1) have been release.
  • The pi3d library has moved on, in leaps and bounds.
  • The 'zero' ethos to make API's 'frictionless' has garnered favour.

So, I started playing... I recreated the old 'Blockworld' demo using the pi3d library and used the knowledge I gained previously, together with some new info, to configure a Pi 3 to work with an Oculus DK2.

After that was up and running I refactored the common parts (e.g. input event handling and player/camera setup and movement) out of the new 'Blockworld' code into it's own Python module.  The resulting 'Blockworld' demo is now just under 80 lines of code (a lot less than the 1000 lines of the original!)

I called the new development VR Zero and the Python module 'vrzero'.

VR Zero is (hopefully) a frictionless way to get started creating your own virtual reality worlds in Python on a Raspberry Pi with an Oculus Rift.

VR Zero adds a number of features on top of pi3d and solves the headaches of configuring a Pi 3 for VR development in Python.
 

VR Zero includes:

  1. Default input event handling for Keyboard, Mouse, Joypad and the Rift for moving, and altering the view, of the player avatar.
  2. Known good HDMI configuration settings for the Oculus Rift DK1 and DK2.
  3. An OpenHMD Debian package, OpenHMD is used to read the rotational sensor reading from the Rift.
  4. Python bindings for the native OpenHMD library with supporting udev config for non-root access to USB device
  5. An OpenGL ES barrel shader for correcting lens distortion (as can be found in official Oculus SDK's)
  6. XBox Joypad configuration.
  7. A handful of VR demos (screenshots and a video of the demos can be found below)

VR Zero is for fun and learning, so don't expect huge gaming PC frame rates, although some of the demos do peak at around 25-30 FPS on a Pi 3.

I hope that some people find it fun and learn something from it. I would be delighted to hear any feedback you may have in the comments below.

You can find the source code on GitHub.

Below are some screenshots and a video of the demos.

The OpenGL Tea Pot demo, in VR and Raspberry Pi style.

The OpenGL Tea Pot demo, in VR and Raspberry Pi style.

The Abbey demo.

The Abbey demo.

Here is a video showing off some of the demos, the video capture is not the best, but the video does give you a good idea of the framerate you can expect: