package study

{

    import game.FacebookAP;

    import com.facebook.data.users.FacebookUser;

   

    import flash.display.Bitmap;

    import flash.display.Loader;

    import flash.display.LoaderInfo;

    import flash.events.Event;

    import flash.events.MouseEvent;

    import flash.filters.BlurFilter;

    import flash.net.URLRequest;

    import flash.system.LoaderContext;

       

    import org.papervision3d.core.effects.view.ReflectionView;

    import org.papervision3d.core.math.Quaternion;

    import org.papervision3d.cameras.CameraType;

    import org.papervision3d.materials.BitmapMaterial;

    import org.papervision3d.objects.DisplayObject3D;

    import org.papervision3d.objects.primitives.Plane;

    public class study21 extends ReflectionView

    {

        private var currentQuat:Quaternion = new Quaternion();

        private var targetQuat:Quaternion = new Quaternion();

        private var slerp:Number = 0;

        private var fbRadius:Number;

        private var carousel:DisplayObject3D = new DisplayObject3D();

        private var isMouseDown:Boolean;

        private var fb:FacebookAP;

        private var save_mouseX:Number;

        private var save_rotationY:Number;

        private static var planeWidth:Number = 50;

        private static var planeHeight:Number = 50;

       

        public function study21()

        {

            super(0,0,true,false,CameraType.FREE);

            this.addEventListener(Event.ADDED_TO_STAGE, init0);

        }

       

        private function init0( event:Event ):void

        {

            this.removeEventListener(Event.ADDED_TO_STAGE, init0);

            fb = new FacebookAP();

            fb.addEventListener( Event.COMPLETE, init1 );

            fb.init();

        }


   private function init1( event:Event ):void

        {

            fb.removeEventListener( Event.COMPLETE, init1 );

           

             opaqueBackground=0;

            surfaceHeight = -5;

            viewport.interactive=true;

            viewportReflection.filters = [new BlurFilter(3,3,3)];

            setReflectionColor(.7, .7, .7);

            fbRadius = ( fb.friends.length * (planeWidth+planeWidth/2) )/(2*Math.PI);

             camera.target = carousel;

            camera.position = carousel.position;

            camera.y = planeHeight/2;

             camera.moveBackward( fbRadius+150 );

           

             for( var i:int=0; i

             {

                  var user:FacebookUser = fb.friends.getItemAt(i) as FacebookUser;

                var lc:LoaderContext = new LoaderContext(true);       

                var loader:Loader = new Loader();

                loader.contentLoaderInfo.addEventListener( Event.COMPLETE, onLoadBitmap );

                if( user.pic_square == "" )

                    loader.load(new URLRequest( "images/q_silhouette.gif" ), lc );

                else

                    loader.load(new URLRequest( user.pic_square ), lc);

            }

            scene.addChild(carousel);

            this.addEventListener(Event.ENTER_FRAME, onENTER_FRAME );

            this.stage.addEventListener( MouseEvent.MOUSE_DOWN, onMOUSE_DOWN );

            this.stage.addEventListener( MouseEvent.MOUSE_UP, onMOUSE_UP );

        }

        private function onLoadBitmap( event:Event ):void

        {

            var bodyMaterial:BitmapMaterial = new BitmapMaterial( Bitmap(LoaderInfo(event.target).content).bitmapData );

            bodyMaterial.interactive=true;

            bodyMaterial.doubleSided=true

           

            var plane:DisplayObject3D = new Plane( bodyMaterial,planeWidth,planeHeight,1,1 );

           

            plane.rotationY = ( 360 / fb.friends.length ) * carousel.numChildren;

            plane.moveForward( fbRadius );

            plane.y = planeHeight/2;

           

            carousel.addChild(plane);

        }      

        private function onMOUSE_DOWN(e:Event):void

        {

            isMouseDown = true;

            save_mouseX = this.stage.mouseX;

            save_rotationY = carousel.rotationY;

        }

       

        private function onMOUSE_UP(e:Event):void

        {

            isMouseDown = false;

        }

       

        private function onENTER_FRAME(e:Event):void

        {

            if( isMouseDown )

            {

                carousel.rotationY = save_rotationY + (180/Math.PI)*Math.atan((save_mouseX-this.stage.mouseX)/(fbRadius+150));

            } else {

                carousel.rotationY -= ( this.stage.mouseX – this.stage.stageWidth/2 )/200;

                slerp += (1 – slerp) * .05;

                var quat:Quaternion = Quaternion.slerp( currentQuat, targetQuat, slerp );

                carousel.transform = quat.matrix;

             }

        

            singleRender();

        }

    }

}

創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()