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: [PV3D] サンプル4 (3Dの視点制御にイージングを付ける)

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

// forked from clockmaker's [PV3D] サンプル4 (3Dの視点制御にイージングを付ける)
package {
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.events.KeyboardEvent;
    import org.papervision3d.materials.*;
    import org.papervision3d.objects.primitives.*;
    import org.papervision3d.view.*;
    
    public class Sample4 extends BasicView {
        
        private var sphere1:Sphere;
        private var isMouseDown:Boolean = false
        private var isKeyboardDown:Boolean = false
        private var Keyboard:Vector.<Boolean> = new Vector.<Boolean>(255);       
        private var sphere2:Sphere;
        
        public function Sample4():void 
        {
            // マテリアルを作成
            var material:WireframeMaterial = new WireframeMaterial(0x000080);
            
            // 3Dオブジェクトを作成
             sphere1 = new Sphere(material, 300, 10, 10);
             sphere2 = new Sphere(material, 300, 10, 10);
            
            // 座標を設定
            sphere1.x =  500;
            sphere2.x = -500;
            
            // 3Dシーンに追加して、表示させる
            scene.addChild(sphere1);
            scene.addChild(sphere2);
            
            // レンダリングを開始
            startRendering();
            
            // エンターフレームを設定
            addEventListener(Event.ENTER_FRAME, loop);
            stage.addEventListener(MouseEvent.MOUSE_DOWN, downHandler);
            stage.addEventListener(MouseEvent.MOUSE_UP, upHandler);
            stage.addEventListener(MouseEvent.MOUSE_DOWN, downHandler);
            stage.addEventListener(MouseEvent.MOUSE_UP, upHandler);
            
        }
        
        // エンターフレーム
        private function loop(e:Event):void {
            // カメラの位置を変える
            var rateX:Number = mouseX / stage.stageWidth;
            var targetX:Number = -5000 * (rateX - 0.5);
            camera.x += (targetX - camera.x) * 0.2;
            
            var rateY:Number = mouseY / stage.stageHeight;
            var targetY:Number = 5000 * (rateY - 0.5);
            camera.y += (targetY - camera.y) * 0.2;
            
            //球面をx軸方向に開店
            //sphere1.rotationX += 10;
           // sphere1.rotationY += 10;
            sphere1.rotationZ += 10;
            
            //sphere2.rotationX += 10;
            //sphere2.rotationY -= 10;
            sphere2.rotationZ += 20;
           
           // if(isMouseDown)
           //{
           //sphere1.x = mouseX - viewport.width / 2 ;
          // sphere1.y = -(mouseY - viewport.height / 2);
         // }
          
           //if(keyboard[37]) {
             //   sphere.x -= 50;
            //}
            
            //if(keyboard[39]) {
             //   sphere.x += 50;
            //}
            
           // if(keyboard[38]) {  //上
              //  camera.x += 50;
             //    sphere.y += 50;
            //}
            
           // if(keyboard[40]) { //下
            //     camera.x -= 50;
           //      sphere.y -= 50;          
          //  }
        
            
        
        }
         private function upHandler(e:MouseEvent):void {
           isMouseDown = false;
         }

         private function downHandler(e:MouseEvent):void {
           isMouseDown = true;
       }    
        
        //  public function kD(e:KeyboardEvent):void {
         //   if(e.keyCode < 255) {
          //      keyboard[e.keyCode] = true;
           // }
        //}
        
        //public function kU(e:KeyboardEvent):void {
         //   if(e.keyCode < 255) {
           //     keyboard[e.keyCode] = false;
            //}
        //}     
    //}