flash on 2009-3-19
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextFormat;
import gs.TweenMax;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
[SWF(width="800", height="300", backgroundColor="#000000", frameRate="60")]
public class FreeCameraVSTargetCamera extends Sprite
{
private var leftViewport:Viewport3D;
private var leftCamera:Camera3D;
private var rightViewport:Viewport3D;
private var rightCamera:Camera3D;
private var scene:Scene3D;
private var renderer:BasicRenderEngine;
public function FreeCameraVSTargetCamera()
{
leftViewport = new Viewport3D(400, 300);
leftCamera = new Camera3D();
leftCamera.y = 100;
leftCamera.z = -2000;
rightViewport = new Viewport3D(400, 300);
rightCamera = new Camera3D();
rightCamera.target = DisplayObject3D.ZERO;//x:0, y:0, z:0
rightCamera.y = 100;
rightCamera.z = -2000;
addChild(leftViewport);
rightViewport.x = 400;
rightViewport.opaqueBackground = 0xffffff;
addChild(rightViewport);
scene= new Scene3D();
renderer = new BasicRenderEngine();
for(var i:int = 0; i < 5; i++)
{
for(var j:int = 0; j < 5; j++)
{
var randColor:Number = Math.random() * 0xffffff;
var material:WireframeMaterial = new WireframeMaterial(randColor, 1, 2);
var sphere:Sphere = new Sphere(material);
sphere.x = 1000 * i - 2000;
sphere.z = 1000 * j - 2000;
scene.addChild(sphere);
}
}
var floor:Plane = new Plane(new WireframeMaterial(0x00cc00, 1, 2), 5000, 5000, 10, 10);
floor.pitch(90);
floor.y = -100;
scene.addChild(floor);
//Set both cameras along the same circular motion
var bezierThrough:Array = [{x:2000, z:0}, {x:0, z:2000}, {x:-2000, z:0}];
TweenMax.to(leftCamera, 10, {x:0, z:-2000, bezierThrough:bezierThrough, yoyo:true});
TweenMax.to(rightCamera, 10, {x:0, z:-2000, bezierThrough:bezierThrough, yoyo:true});
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
private function enterFrameHandler(event:Event):void
{
renderer.renderScene(scene, leftCamera, leftViewport);
renderer.renderScene(scene, rightCamera, rightViewport);
}
}
}