Monday, 23 March 2015

Oculus Rift Side Project - Dolly zoom test

I did a test a few weeks back (quite a while now) to see how the Dolly Effect worked with cameras and their frustum. The idea was proposed by my supervisor as something that might be interesting to explore in my free time. we discussed this during one of my MSP module meeting.

I did not actively know about this 'Vertigo' effect until it was mentioned by my supervisor. Only after speaking with him did I realize that I have seen this effect in many movies. I thought it would be interesting to look into. I was specifically interested in how this would apply to the Oculus Rift and what sort of effect it would have on users when in use. 

I started by looking into the Dolly Effect on Wikipedia (Wikipedia, 2015), as it gave a good overview with examples as well as the maths that went into creating the effect. 

After this I looked at how to implement this in a prototype and hook it up to the rift. The easiest way I thought, would be to use Unity since I had other projects already set up in that engine to work with the rift. On an off chance I looked at the Unity documentation and found that they had all the code written for a dolly zoom effect! (Unity Documentation, 2015) This meant the only modifications I had to make was to convert the javascript code into C#. And after this, get the effect to apply to the Oculus Rift.

Converting the code into C# wasn't really required but I thought it would help me understand how they implemented the mathematics behind the concept better. And it did, converting the code did not take long at all. 

The next step was attempting to get the effect to work on the DK2. I couldn't simply attach my dolly effect script to each Oculus camera as this broke the cameras during runtime. I had to instead modify the OVRCamera script that came with the Unity integration package. I did this by 'merging' my script with the OVRCamera script. Most of the merging was pretty straight forward stuff. Adding variable declarations to the top etc. The only really interesting part was that I had to make use of the LateUpdate() method rather than a normal Update method. As the rift updates differently than standard Unity Update(). Once this was in place, the code worked like a charm and the effect worked awesome! The code changes can be found below, summarized:

What was even more neat was the fact that I would attach the focal object in the scene via a public variable and doing so would give a different effect. Stretching towards the door (see blow video for example). Or skewing the door when heading towards a teddybear. or bursting through the door completely.  It feels pretty trippy when this effect is used on the rift :D

Pretty fun stuff!

Wikipedia. (2015) Dolly zoom. [Online] Available from: [Accessed: 3 March 2015].
Unity Documentation. (2015) Dolly Zoom (AKA the “Trombone” Effect). [Online] Available from: [Accessed: 3 March 2015].
Youtube. (2015) Dolly Effect / Vertigo Effect on DK2 in Unity. Available from: [Accessed: 3 March 2015].

No comments:

Post a Comment