AnaglyphScene3D
From Flare3D - WIKI
This example shows how to create an stereo/anaglyph render extending the basic functionality of the Scene3D.
Usage:
package { import flare.basic.*; import flare.core.*; import flare.system.*; import flare.utils.*; import flash.display.*; import flash.events.*; import flash.utils.*; [SWF(frameRate = 60, width = 800, height = 450, backgroundColor = 0x000000)] /** * Anaglyph test. * * @author Ariel Nehmad */ public class AnaglyphTest extends Sprite { private var scene:AnaglyphScene3D; public function AnaglyphTest() { scene = new AnaglyphScene3D( this ); scene.addChildFromFile( "../resources/vaca.f3d" ); scene.addEventListener( Scene3D.UPDATE_EVENT, updateEvent ); } private function updateEvent(e:Event):void { scene.camera.translateZ( Math.cos( getTimer() / 400 ) * 60 ); } } }
AnaglyphScene3D Class
package flare.basic { import flare.basic.*; import flare.core.*; import flash.display.*; import flash.display3D.*; import flash.events.*; import flash.geom.*; /** * AnaglyphScene3D * * @author Ariel Nehmad. */ public class AnaglyphScene3D extends Scene3D { private var _transform:Matrix3D = new Matrix3D(); private var _depthReference:Vector3D = new Vector3D(); // The distance between the eyes. public var eyeDistance:Number = 5; // The distance of the reference point. This is the point where the eyes intersect. public var depthDistance:Number = 1000; public function AnaglyphScene3D( container:Sprite ) { super( container ); } override public function render( camera:Camera3D = null, clearDepth:Boolean = false ):void { if ( !camera ) camera = scene.camera; // store the source camera position and rotation. _transform.copyFrom( camera.world ); // the cameras should not be parallel, so we create a point of reference // where the cameras will look. that's the point where the two cameras intersect each other. // taking the depth distance, transforms from local camera to global point. _depthReference.setTo( 0, 0, depthDistance ); camera.localToGlobal( _depthReference, _depthReference ); // translates the camera and orientates the first camera. camera.translateX( -eyeDistance ); camera.lookAt( _depthReference.x, _depthReference.y, _depthReference.z, camera.getUp(false) ); // the first render. super.context.clear(); super.context.setColorMask( true, false, false, false ); super.render( camera ); // transform the second camera. camera.world.copyFrom( _transform ); camera.translateX( eyeDistance ); camera.lookAt( _depthReference.x, _depthReference.y, _depthReference.z, camera.getUp(false) ); //the second render. here we just render without clear the depth buffer. super.context.setColorMask( false, true, true, false ); super.render( camera, true ); // restore the original camera transform. camera.world.copyFrom( _transform ); } } }