home *** CD-ROM | disk | FTP | other *** search
/ 360 Degrees of: Mammoth Cave National Park / 360 Degrees of: Mammoth Cave National Park.iso / pc / data / krpano / radar.swf / scripts / radar.as < prev   
Encoding:
Text File  |  2011-01-17  |  7.7 KB  |  214 lines

  1. package
  2. {
  3.    import flash.display.*;
  4.    import flash.events.*;
  5.    import flash.text.*;
  6.    import flash.utils.*;
  7.    
  8.    public class radar extends Sprite
  9.    {
  10.       private static const radarradius:int = 128;
  11.       
  12.       public var krpano:krpano_as3_interface = null;
  13.       
  14.       public var viewinterface:Object = null;
  15.       
  16.       public var radarinterface:Object = null;
  17.       
  18.       public var pluginpath:String = null;
  19.       
  20.       private var radarsprite:Sprite = null;
  21.       
  22.       private var updatetimer:Timer = null;
  23.       
  24.       private var startdrag:Boolean = false;
  25.       
  26.       private var startangle:Number = 0;
  27.       
  28.       private var last_hlookat:Number = 0;
  29.       
  30.       private var last_fov:Number = 0;
  31.       
  32.       public function radar()
  33.       {
  34.          var txt:TextField = null;
  35.          var f:TextFormat = null;
  36.          var resizefu:Function = null;
  37.          super();
  38.          if(stage == null)
  39.          {
  40.             this.addEventListener(Event.ADDED_TO_STAGE,this.startplugin);
  41.             this.addEventListener(Event.UNLOAD,this.stopplugin);
  42.          }
  43.          else
  44.          {
  45.             stage.scaleMode = StageScaleMode.NO_SCALE;
  46.             stage.align = StageAlign.TOP_LEFT;
  47.             txt = new TextField();
  48.             txt.textColor = 16777215;
  49.             txt.selectable = false;
  50.             txt.htmlText = "krpano " + "1.0.8.12" + "\n\n" + "<b>radar plugin</b>" + (String("1.0.8.12").length > 5 ? "\n\n(build " + "2010-11-24" + ")" : "");
  51.             f = new TextFormat();
  52.             f.font = "_sans";
  53.             f.size = 14;
  54.             txt.autoSize = f.align = "center";
  55.             txt.setTextFormat(f);
  56.             addChild(txt);
  57.             resizefu = function(param1:Event):void
  58.             {
  59.                txt.x = (stage.stageWidth - txt.width) / 2;
  60.                txt.y = (stage.stageHeight - txt.height) / 2;
  61.             };
  62.             stage.addEventListener(Event.RESIZE,resizefu);
  63.             resizefu(null);
  64.          }
  65.       }
  66.       
  67.       private function startplugin(param1:Event) : void
  68.       {
  69.          this.removeEventListener(Event.ADDED_TO_STAGE,this.startplugin);
  70.          if(this.krpano == null)
  71.          {
  72.             this.krpano = krpano_as3_interface.getInstance();
  73.             if(this.krpano.set != null)
  74.             {
  75.                if(this.krpano.get("version") < "1.0.8")
  76.                {
  77.                   this.krpano.call("error(radar plugin - wrong krpano version, min. krpano 1.0.8 needed);");
  78.                   return;
  79.                }
  80.                this.krpano.addPluginEventListener(this,krpano_as3_interface.PLUGINEVENT_REGISTER,this.registerEvent);
  81.             }
  82.          }
  83.       }
  84.       
  85.       private function registerEvent(param1:DataEvent) : void
  86.       {
  87.          this.pluginpath = param1.data;
  88.          this.viewinterface = this.krpano.get("view");
  89.          this.radarinterface = this.krpano.get(this.pluginpath);
  90.          this.radarinterface.registerattribute("heading",Number(0));
  91.          this.radarinterface.registerattribute("fillcolor",uint(16777215));
  92.          this.radarinterface.registerattribute("fillalpha",Number(0.5));
  93.          this.radarinterface.registerattribute("linecolor",uint(16777215));
  94.          this.radarinterface.registerattribute("linealpha",Number(0.3));
  95.          this.radarinterface.registerattribute("linewidth",Number(0));
  96.          this.radarsprite = new Sprite();
  97.          this.radarsprite.name = "radarsprite";
  98.          this.radarsprite.tabEnabled = false;
  99.          this.radarsprite.buttonMode = true;
  100.          this.radarsprite.addEventListener(MouseEvent.MOUSE_DOWN,this.mouse_down);
  101.          addChild(this.radarsprite);
  102.          this.updatetimer = new Timer(1000 / 30,0);
  103.          this.updatetimer.addEventListener(TimerEvent.TIMER,this.radarHandler);
  104.          this.updatetimer.start();
  105.       }
  106.       
  107.       private function stopplugin(param1:Event) : void
  108.       {
  109.          if(this.updatetimer)
  110.          {
  111.             this.updatetimer.stop();
  112.             this.updatetimer = null;
  113.          }
  114.          if(this.krpano.set != null)
  115.          {
  116.             this.krpano.removePluginEventListener(this,krpano_as3_interface.PLUGINEVENT_REGISTER,this.registerEvent);
  117.          }
  118.          this.radarsprite.removeEventListener(MouseEvent.MOUSE_DOWN,this.mouse_down);
  119.          removeChild(this.radarsprite);
  120.          this.viewinterface = null;
  121.          this.radarinterface = null;
  122.          this.radarsprite = null;
  123.       }
  124.       
  125.       private function mouse_down(param1:MouseEvent) : void
  126.       {
  127.          this.startdrag = true;
  128.          this.mouse_move(param1);
  129.          stage.addEventListener(MouseEvent.MOUSE_MOVE,this.mouse_move);
  130.          stage.addEventListener(MouseEvent.MOUSE_UP,this.mouse_up);
  131.       }
  132.       
  133.       private function mouse_up(param1:MouseEvent) : void
  134.       {
  135.          this.mouse_move(param1);
  136.          stage.removeEventListener(MouseEvent.MOUSE_MOVE,this.mouse_move);
  137.          stage.removeEventListener(MouseEvent.MOUSE_UP,this.mouse_up);
  138.       }
  139.       
  140.       private function mouse_move(param1:MouseEvent) : void
  141.       {
  142.          var _loc2_:Number = NaN;
  143.          var _loc3_:Number = NaN;
  144.          var _loc4_:Number = NaN;
  145.          var _loc5_:Number = Number(this.radarinterface.heading);
  146.          if(isNaN(_loc5_))
  147.          {
  148.             _loc5_ = 0;
  149.          }
  150.          var _loc6_:Number = radarradius;
  151.          _loc2_ = this.mouseX - _loc6_;
  152.          _loc3_ = this.mouseY - _loc6_;
  153.          _loc4_ = Math.atan2(_loc3_,_loc2_) * 180 / Math.PI - _loc5_;
  154.          if(this.startdrag == true)
  155.          {
  156.             this.startangle = _loc4_ - Number(this.viewinterface.hlookat);
  157.             this.startdrag = false;
  158.          }
  159.          else
  160.          {
  161.             this.viewinterface.hlookat = _loc4_ - this.startangle;
  162.          }
  163.       }
  164.       
  165.       private function radarHandler(param1:TimerEvent) : void
  166.       {
  167.          var _loc10_:Number = NaN;
  168.          var _loc11_:Graphics = null;
  169.          var _loc12_:int = 0;
  170.          var _loc13_:int = 0;
  171.          var _loc14_:Number = NaN;
  172.          var _loc15_:Number = NaN;
  173.          var _loc16_:Number = NaN;
  174.          var _loc2_:Number = Number(this.viewinterface.hlookat);
  175.          var _loc3_:Number = Number(this.viewinterface.hfov);
  176.          var _loc4_:Number = Number(this.radarinterface.heading);
  177.          var _loc5_:uint = uint(this.radarinterface.linecolor);
  178.          var _loc6_:Number = Number(this.radarinterface.linewidth);
  179.          var _loc7_:Number = Number(this.radarinterface.linealpha);
  180.          var _loc8_:uint = uint(this.radarinterface.fillcolor);
  181.          var _loc9_:Number = Number(this.radarinterface.fillalpha);
  182.          _loc2_ += _loc4_;
  183.          if(Math.abs(_loc2_ - this.last_hlookat) > 1 || Math.abs(_loc3_ - this.last_fov) > 2)
  184.          {
  185.             this.last_hlookat = _loc2_;
  186.             this.last_fov = _loc3_;
  187.             _loc10_ = radarradius;
  188.             _loc11_ = this.radarsprite.graphics;
  189.             _loc11_.clear();
  190.             _loc11_.beginFill(_loc8_,_loc9_);
  191.             _loc11_.lineStyle(_loc6_,_loc5_,_loc7_);
  192.             _loc11_.moveTo(_loc10_,_loc10_);
  193.             _loc12_ = int(1 + _loc3_ / 10);
  194.             if(_loc12_ < 2)
  195.             {
  196.                _loc12_ = 2;
  197.             }
  198.             _loc13_ = 0;
  199.             _loc13_ = 0;
  200.             while(_loc13_ < _loc12_)
  201.             {
  202.                _loc14_ = (_loc13_ == _loc12_ - 1 ? _loc2_ + _loc3_ / 2 : _loc2_ - _loc3_ / 2 + _loc13_ * _loc3_ / _loc12_) * Math.PI / 180;
  203.                _loc15_ = _loc10_ + _loc10_ * Math.cos(_loc14_);
  204.                _loc16_ = _loc10_ + _loc10_ * Math.sin(_loc14_);
  205.                _loc11_.lineTo(_loc15_,_loc16_);
  206.                _loc13_++;
  207.             }
  208.             _loc11_.endFill();
  209.          }
  210.       }
  211.    }
  212. }
  213.  
  214.