Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

Panorama

Panorama

Code

package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.ui.ContextMenu;

    import org.papervision3d.cameras.Camera3D;
    import org.papervision3d.materials.BitmapMaterial;
    import org.papervision3d.objects.primitives.Sphere;
    import org.papervision3d.render.BasicRenderEngine;
    import org.papervision3d.scenes.Scene3D;
    import org.papervision3d.view.Viewport3D;

    public class Papervision3DPanorama extends Sprite
    {
        [Embed(source="Panorama.jpg")]
        private var Asset :Class;

        private var scene    :Scene3D;
        private var camera   :Camera3D;
        private var viewport :Viewport3D;
        private var renderer :BasicRenderEngine;

        public function Papervision3DPanorama()
        {
            var menu :ContextMenu = new ContextMenu();
            menu.hideBuiltInItems();
            contextMenu = menu;

            scene = new Scene3D();

            camera           = new Camera3D();
            camera.focus     = 300;
            camera.rotationY = 30;
            camera.zoom      = 2;

            viewport                  = new Viewport3D();
            viewport.autoScaleToStage = true;
            addChild(viewport);

            renderer = new BasicRenderEngine();

            var material :BitmapMaterial = new BitmapMaterial(new Asset().bitmapData);
            material.opposite = true;
            material.smooth   = true;

            var object :Sphere = new Sphere(material, 30000, 30, 30);
            scene.addChild(object);

            addEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown);
            addEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
            addEventListener(MouseEvent.MOUSE_OUT, handleMouseOut);

            stage.addEventListener(Event.RESIZE, handleResize);

            render();
        }

        private function handleEnterFrame(e:Event):void
        {
            camera.rotationX += (mouseY - (stage.height * 0.5)) * 0.02;
            camera.rotationY += (mouseX - (stage.width  * 0.5)) * 0.02;

            if (camera.rotationX <= -90) {
                camera.rotationX = -90;
            } else if (camera.rotationX >= 90) {
                camera.rotationX = 90;
            }

            render();
        }

        private function handleResize(e:Event):void
        {
            render();
        }

        private function handleMouseDown(e:MouseEvent):void
        {
            addEventListener(Event.ENTER_FRAME, handleEnterFrame);
        }

        private function handleMouseUp(e:MouseEvent):void
        {
            removeEventListener(Event.ENTER_FRAME, handleEnterFrame);
        }

        private function handleMouseOut(e:MouseEvent):void
        {
            removeEventListener(Event.ENTER_FRAME, handleEnterFrame);
        }

        private function render():void
        {
            renderer.renderScene(scene, camera, viewport);
        }
    }
}

Download

HomeMenu