In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: forked from: SpringCamera [Alternativa3D 7.5 TIPS]

/**
 * Copyright gaziya ( http://wonderfl.net/user/gaziya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/oj4s
 */

package {
    import alternativ7.engine3d.controllers.SimpleObjectController;
    import alternativ7.engine3d.core.Object3DContainer;
    import alternativ7.engine3d.core.Camera3D;
    import alternativ7.engine3d.core.View;
    import alternativ7.engine3d.materials.FillMaterial;
    import alternativ7.engine3d.primitives.Sphere;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.geom.Vector3D;

    public class Test extends Sprite {
        public function Test():void {
            stage.frameRate = 60
            opaqueBackground = 0x05
            var container:Object3DContainer = new Object3DContainer
            var camera:Camera3D = new Camera3D
            camera.view = new View(stage.stageWidth,stage.stageHeight)
            container.addChild(camera)
            addChild(camera.view)
            addChild(camera.diagram)
            var radius:int = 3000
            var theta:Number
            var sphere:Sphere
            for(var i:int=0; i<100; i++) {
                sphere = container.addChild(new Sphere(100,4,2,false)) as Sphere
                theta = (i/100)*2*Math.PI
                with (sphere) {
                    setMaterialToAllFaces(new FillMaterial(0xFFFFFF,0,0,0xFF0000));
                    x = radius*Math.cos(theta)
                    y = radius*Math.sin(2*theta)
                    z = 0.2*radius*Math.sin(theta)
                }
            }
            for(i=0; i<100; i++) {
                sphere = container.addChild(new Sphere(100,4,2,false)) as Sphere
                with (sphere) {
                    setMaterialToAllFaces(new FillMaterial(0x00FF00,0,0,0x666666))
                    x = 5*radius*(Math.random()-0.5)
                    y = 5*radius*(Math.random()-0.5)
                    z = 5*radius*(Math.random()-0.5)
                }
            }            
            var rabbit:Sphere = container.addChild(new Sphere(100,6,2,false)) as Sphere
            rabbit.setMaterialToAllFaces(new FillMaterial(0x1000000*Math.random(),1,0,0xffffff))
            
            var camera_contoller:SimpleObjectController =new SimpleObjectController(stage,camera,100)
            theta = 0
            addEventListener(Event.ENTER_FRAME, function(e:Event):void{
                with (rabbit) {
                    x = radius*Math.cos(theta)
                    y = radius*Math.sin(2*theta)
                    z = 0.3*radius*Math.sin(theta) + 200
                }
                var theta2:Number = theta - 0.3
                var eye:Vector3D = new Vector3D(
                    radius*Math.cos(theta2),
                    radius*Math.sin(2*theta2),
                    0.1*radius* Math.sin(theta2) + 1000 
                )
                camera_contoller.lookAt(new Vector3D(rabbit.x,rabbit.y,rabbit.z))
                camera_contoller.setObjectPos(eye);
                camera.render()
                theta = (theta+0.005)%(2*Math.PI)
            })    
        }    
    }
}