Friday, November 16, 2012

DevLog: 3D Live Wallpaper in Progress

We are working on a new 3D live wallpaper for Android devices. This one is a christmas themed wallpaper with some interactive bits, just in time for the holidays! Here is a shot of our basic scene.

I'm happy with how the models turned out.  You can see two of the cameras in the scene from this shot, camera0 and camera4.  When you swipe your homescreen to go to another virtual desktop, we translate the camera to match the rotation and position of one of these preset cameras.

Here is a close-up shot of the bridge. All of the blue widgets are particle emitters, they're our christmas lights.  When the user taps on the bridge, each emitter emits a single short-lived particle that changes colors and then turns off .

There are some other places we use particle emitters, one major one is our particle based christmas trees.

I'm pretty proud of the trees and they are quite the joy to look at.  They just boil down to some simple trig.  To calculate the path of a christmas tree whose origin is at y = 0 you do:
--x, y, z is the ground location of the center of the tree
--height is how high you want the tree to be
--yFreq is y axis frequency, a good value is 2
--xzFreq is x/z axis frequency, a good value is 100
local fy = y + math.abs ( math.sin ( 2 * math.kPi * yFreq * dt ) ) * height
local fx = x + math.sin ( 2 * math.kPi * xzFreq * dt ) * 17 * (1 - fy/height) 
local fz = z + math.cos ( 2 * math.kPi * xzFreq * dt ) * 17 * (1 - fy/height)

object.setTranslation ( this.getObject ( ), fx, fy, fz, object.kGlobalSpace )

There are some optimizations you could do to reduce redundant calculations but that will be left as an exercise for the reader.  You can see a video of them in action below.

Each tree has 2 particle emitters that have a different set of colors (you can't change particle emitter colors in Shiva during runtime), so tapping a tree toggles the active emitter to change between 2 sets of colors.  The last thing to add is a flying santa and then next week we release.