Erain 3D
-->

3D mouse demo

In this new year of rodent I cooked this little demo showing you how to create anaglyph with Sandy.

You will need special red-cyan glasses to view this.

Demo Source code

You can download Flash CS3 sources, or read through main code clues in case you would like to re-create this yourself.

package
{
	...
	public class Mouse3D extends Sprite
	{
		...
		private var bmScreen:Bitmap = new Bitmap (new BitmapData (550, 300, true, 0));
		private var mcBuffer:Sprite = new Sprite ();
 
		// from http://en.wikipedia.org/wiki/Anaglyph_image#Anaglyphs_containing_color_information
		// "To make an anaglyph containing color information using color images, replace the red
		// channel of the right-eye image with the red channel of the left-eye image... Eye sensitivity
		// balance can be improved by selecting the green channel and reducing it using a linear curve
		// selection (e.g. reduce to 12.5%). Select the blue channel and reduce somewhat less (e.g.
		// reduce by 5%). This action compensates for the eye's lower sensitivity to red and its high
		// sensitivity to green".
		private var ctLeft:ColorTransform = new ColorTransform  (1, 0, 0);
		private var ctRight:ColorTransform = new ColorTransform  (0, 1 - 0.125, 1 - 0.05);
 
		public function Mouse3D ()
		{
			this.addChild (bmScreen);
 
			world.container = mcBuffer;
			world.camera = new Camera3D (550, 300);
			world.camera.x = -2;
			world.camera.z = -500;
			...
		}
 
		private function onEnterFrame (event:Event):void
		{
			bmScreen.bitmapData.fillRect (bmScreen.bitmapData.rect, 0);
			world.camera.moveSideways (+4); world.render ();
			bmScreen.bitmapData.draw (mcBuffer, null, ctRight, BlendMode.ADD);
			world.camera.moveSideways (-4); world.render ();
			bmScreen.bitmapData.draw (mcBuffer, null, ctLeft,  BlendMode.ADD);
			world.camera.roll++;
		}
	}
}