Insights

Google Cardboard - My Week in Virtual Reality

I came across the google cardboard project a while ago and initially thought it was just a mock VR gadget that google made as there was lots of buzz around the oculus rift at the time. It was only a couple of weeks ago that I actually stuck my nexus 5 in one and had my mind blown. The non descript cardboard box had been sat on a colleagues desk since I joined ustwo at the beginning of September. I was playing with it before going to lunch one day and was told to get the Cardboard app off the store, still sceptical, I strapped in my Nexus 5, and was instantly impressed with how well it fit (I found out later the cardboard was designed for the Nexus 5) I pressed it up against my face, and I was in, just navigating around the menu, this hunk of cardboard had exceeded my expectations.

I fired up the ‘Windy day’ demo, and was soon spinning around in a swivel chair like a six year old in a sweet shop. The head tracking was so smooth the apparent depth of things was spot on, it was a very immersive experience. I just want to point out that I’ve not used any VR system before this either, so my opinion is slightly skewed somewhat. I have since managed to grab one of these myself and have been showing it off to who ever I can, seeing that sense of child like wonderment on peoples faces as they zip their head back and forth while staring into a cardboard box brings a smile to mine.

As soon as I got my hands on my own one to play with I delved into the Cardboard library and started downloading the sample project.

I quickly realised that I was going to need to know OpenGL if I wanted to do an anything with the library classes provided.

I was hoping for a simple 2D system where I could set the depths of things. Imagine Sonic with different depths for the foreground and parallax scrolling background elements, similar to some Nintendo DS games, the 3D remake of the original Streets of Rage game is the best thing I’ve seen on that platform.

This feature didn’t exist, so I set about making it myself.

I created a class that has 2 canvases, one for each eye which then get drawn together on to a single canvas. It’s quite simple. It has one method at the moment for drawing a bitmap with a depth. Bitmaps are moved inwards towards the centre of the phones screen, the closer the object is supposed to be the more it does this. The diagram below may help to explain this.

And it works! Although I’m not sure how well this will scale with a more complex scene, I don’t imagine drawing everything twice is very efficient. Feel free to use the code here.

I read up on people doing this with Unity also, there’s a package you can use to handle the drawing of the two scenes, or you could create something yourself with a camera for each eye. This is probably the way you want to go for any sort of game unless you’re an OpenGL whizz then get stuck in with the Cardboard Library!