Skip to main content

Something that’s really interested me for a bit is 3D. Not just in any particular platform but the ability it gives us to perceive depth on screen. Video games most notably use 3D environments, but the way we move through them isn’t as natural as it could be. Today I put together a little demo in Processing that mixes a few technologies to experiment with an alternative way of viewing a 3D environment.

OpenGl was used to create a simple 3D cube. A more complex environment could be used but this seems to do the trick. A camera was then placed in the scene to orbit around the cube and view it from different sides. The camera was controlled by the position of my mouse on screen. If I moved the mouse right it turned right, etc. This is pretty similar to how we move through video games and online environments.

The next step was to eliminate the mouse. I did this using Face Detection. The camera on my computer first recognized if a face was present, and then tracked my faces position up and down, left and right. The next part was simple. I replaced the mouses X and Y position with that of my faces position. Now as I moved my head left the cube would turn left.

The problem here is that if I was trying to look around a corner to view the side of the cube I would see the side of the cube instead of the cube’s front surface turning to the left as well. This was solved by reversing the camera’s Z position which was set to orbit the cube. By multiplying the Z position by negative 1 I was able to get a realistic view of the cube. Now when I moved my head to the left I was looking around the cube.

This concept could make for some pretty cool interfaces online and especially on mobile phones with front facing cameras. If you’re up for trying it out I’ve attached the source below.

Download FaceCubePerspective.pde

Note: You’ll need the openGL library to create the cube and the Open CV library for face detection.

Get Open CV here