stereo test
/**
* Copyright yonatan ( http://wonderfl.net/user/yonatan )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/qSQQ
*/
// forked from yonatan2's forked from: forked from: flash on 2009-4-28
// forked from yonatan's forked from: flash on 2009-4-28
// forked from yonatan's flash on 2009-4-28
package {
import flash.events.*;
import flash.utils.*;
import flash.display.*;
import org.papervision3d.materials.*;
import org.papervision3d.materials.utils.*;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.objects.*;
import org.papervision3d.objects.primitives.*
import org.papervision3d.view.*;
import org.papervision3d.core.math.Number3D;
import org.papervision3d.core.geom.renderables.*;
[SWF(backgroundColor="0x000000", frameRate="30")]
public class Main extends Sprite {
private var do3d:DisplayObject3D;
private var materials :MaterialsList;
private var mat :FlatShadeMaterial;
private var light:PointLight3D;
private var updateNormals:Boolean
private var time:uint;
private var world1:BasicView;
private var world2:BasicView;
public function Main() {
stage.quality = "medium";
world1 = new BasicView(230, 230, false, true);
world2 = new BasicView(230, 230, false, true);
light = new PointLight3D(false);
light.x = 0;
light.y = 0;
light.z = -1000;
mat = new FlatShadeMaterial(light, 0xD7261C );
mat.fillAlpha = 0.9;
do3d = new Sphere( mat, 100, 40, 32 );
world1.scene.addChild( do3d );
world2.scene.addChild( do3d );
addChild(world1.viewport);
addChild(world2.viewport);
world2.viewport.x = 465/2;
world1.viewport.y = world2.viewport.y = 465/4;
world1.camera.x = 20;
world2.camera.x = -20;
world1.camera.z = world2.camera.z = -2000;
addEventListener( Event.ENTER_FRAME, onEnterFrame );
}
public function onEnterFrame(e:Event): void {
var vertices:Array = do3d.geometry.vertices;
var x:Number, y:Number, z:Number, len:Number;
time = getTimer();
var i:Number = 0;
for each( var v:Vertex3D in vertices ) {
x = v.x; y = v.y; z = v.z;
len = Math.sqrt(x*x+y*y+z*z) / 300 * (1.5+ Math.sin(time/1000 * i/vertices.length*3.14));
x /= len;
y /= len;
z /= len;
v.x = x ;
v.y = y;
v.z = z;
i++;
}
for each( var face:Triangle3D in do3d.geometry.faces ) {
var fn:Number3D = new Number3D(0,0,0);
fn.plusEq(face.v0.toNumber3D());
fn.plusEq(face.v1.toNumber3D());
fn.plusEq(face.v2.toNumber3D());
fn.normalize();
face.faceNormal = fn;
//Tweener.addTween( face.faceNormal, {x: fn.x, y: fn.y, z: fn.z, time: 4, transition: "linear"} );
}
do3d.rotationY++;
do3d.rotationX++;
world1.renderer.renderScene(
world1.scene,
world1.camera,
world1.viewport );
world2.renderer.renderScene(
world2.scene,
world2.camera,
world2.viewport );
}
}
}