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

fly

unfinished
Get Adobe Flash player
by 3dash 30 Jun 2012
    Embed
/**
 * Copyright 3dash ( http://wonderfl.net/user/3dash )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/xchb
 */

// forked from ll_koba_ll's PaperVision3D Cube Anime
package
{
    import flash.display.*;
    import flash.events.*;
    import org.papervision3d.lights.PointLight3D;
    import org.papervision3d.materials.utils.MaterialsList;
    import org.papervision3d.objects.*;
    import org.papervision3d.objects.primitives.*;
    import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
    import org.papervision3d.view.BasicView;
    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.objects.primitives.Plane;

    import flash.events.KeyboardEvent;

    [SWF(backgroundColor="0x000000", frameRate="60")]
    public class PV3DTest02 extends BasicView
    {
        private var up:Boolean = false;
        private var down:Boolean = false;
        private var left:Boolean = false;
        private var right:Boolean = false;
        private var mousedown:Boolean = false;
        
        private var field:DisplayObject3D;      
        
        
        
        public function PV3DTest02()
        {
            
            super();

            var light:PointLight3D = new PointLight3D();
            light.y = 5000;
            
            field = new DisplayObject3D();
            scene.addChild(field);
            
            camera.target = null;
            camera.y = 400;
            
            var material:FlatShadeMaterial = new FlatShadeMaterial(light, 0xFFFFFF, 0x000000); 
            
            
            
            // 地面
            var jimenColor:ColorMaterial = new ColorMaterial(0x00FF00);
            jimenColor.doubleSided = true;
            var jimen:Plane = new Plane(jimenColor,2000, 2000);
            jimen.rotationX = 90;
            jimen.x = 0;
            jimen.y = -10;
            field.addChild(jimen);
            
            // 四角
            for(var i:Number = 0; i<10; i++){
                var cube:Cube = new Cube(new MaterialsList({all:material}), 100 ,100, 500, 1);
                cube.x = 100 + Math.random() *2000-1000;
                cube.y = 250;
                cube.z = 100 + Math.random() *2000-1000;
                field.addChild(cube);
            }
            
            startRendering();
            
            // イベント
            stage.addEventListener(Event.ENTER_FRAME, _enterframeAct);
            stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
            stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
            stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
            stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
            stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
        }
        
        
        
        
        
        
        
        // エンターフレーム
        private function _enterframeAct(e:Event):void
        {
            if (left) camera.rotationY    -= 2;
            if (right) camera.rotationY   += 2;
            if (up) camera.rotationX -= 2;
            if (down) camera.rotationX += 2;
            if(mousedown)camera.moveForward(10);
            
        }
        
        // マウスムーブ
        private function onMouseMove(e:MouseEvent):void{
            camera.rotationY = (stage.mouseX - stage.stageWidth/2) /stage.stageWidth * 270;
            camera.rotationX = (stage.mouseY - stage.stageHeight/2) /stage.stageHeight * 270;
        }

        
        
        
        
        
    
        // キーボードイベント
        private function onKeyUp(event:KeyboardEvent):void{
            switch (event.keyCode){
                case 65:
                {
                    left = false;
                    break;
                }
                case 87:
                {
                    up = false;
                    break;
                }
                case 68:
                {
                    right = false;
                    break;
                }
                case 83:
                {
                    down = false;
                    break;
                }
            }
        }
        
        private function onKeyDown(event:KeyboardEvent):void{
            switch (event.keyCode){
                case 65:
                {
                    left = true;
                    break;
                }
                case 87:
                {
                    up = true;
                    break;
                }
                case 68:
                {
                    right = true;
                    break;
                }
                case 83:
                {
                    down = true;
                    break;
                }
            }
        }
        
        // クリックイベント
        private function onMouseDown(event:MouseEvent):void{
            mousedown = true;
        }
        private function onMouseUp(event:MouseEvent):void{
            mousedown = false;
        }
        

    }
}