home *** CD-ROM | disk | FTP | other *** search
- package
- {
- import flash.display.*;
- import flash.events.*;
- import flash.text.*;
- import flash.utils.*;
-
- public class radar extends Sprite
- {
- private static const radarradius:int = 128;
-
- public var krpano:krpano_as3_interface = null;
-
- public var viewinterface:Object = null;
-
- public var radarinterface:Object = null;
-
- public var pluginpath:String = null;
-
- private var radarsprite:Sprite = null;
-
- private var updatetimer:Timer = null;
-
- private var startdrag:Boolean = false;
-
- private var startangle:Number = 0;
-
- private var last_hlookat:Number = 0;
-
- private var last_fov:Number = 0;
-
- public function radar()
- {
- var txt:TextField = null;
- var f:TextFormat = null;
- var resizefu:Function = null;
- super();
- if(stage == null)
- {
- this.addEventListener(Event.ADDED_TO_STAGE,this.startplugin);
- this.addEventListener(Event.UNLOAD,this.stopplugin);
- }
- else
- {
- stage.scaleMode = StageScaleMode.NO_SCALE;
- stage.align = StageAlign.TOP_LEFT;
- txt = new TextField();
- txt.textColor = 16777215;
- txt.selectable = false;
- 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" + ")" : "");
- f = new TextFormat();
- f.font = "_sans";
- f.size = 14;
- txt.autoSize = f.align = "center";
- txt.setTextFormat(f);
- addChild(txt);
- resizefu = function(param1:Event):void
- {
- txt.x = (stage.stageWidth - txt.width) / 2;
- txt.y = (stage.stageHeight - txt.height) / 2;
- };
- stage.addEventListener(Event.RESIZE,resizefu);
- resizefu(null);
- }
- }
-
- private function startplugin(param1:Event) : void
- {
- this.removeEventListener(Event.ADDED_TO_STAGE,this.startplugin);
- if(this.krpano == null)
- {
- this.krpano = krpano_as3_interface.getInstance();
- if(this.krpano.set != null)
- {
- if(this.krpano.get("version") < "1.0.8")
- {
- this.krpano.call("error(radar plugin - wrong krpano version, min. krpano 1.0.8 needed);");
- return;
- }
- this.krpano.addPluginEventListener(this,krpano_as3_interface.PLUGINEVENT_REGISTER,this.registerEvent);
- }
- }
- }
-
- private function registerEvent(param1:DataEvent) : void
- {
- this.pluginpath = param1.data;
- this.viewinterface = this.krpano.get("view");
- this.radarinterface = this.krpano.get(this.pluginpath);
- this.radarinterface.registerattribute("heading",Number(0));
- this.radarinterface.registerattribute("fillcolor",uint(16777215));
- this.radarinterface.registerattribute("fillalpha",Number(0.5));
- this.radarinterface.registerattribute("linecolor",uint(16777215));
- this.radarinterface.registerattribute("linealpha",Number(0.3));
- this.radarinterface.registerattribute("linewidth",Number(0));
- this.radarsprite = new Sprite();
- this.radarsprite.name = "radarsprite";
- this.radarsprite.tabEnabled = false;
- this.radarsprite.buttonMode = true;
- this.radarsprite.addEventListener(MouseEvent.MOUSE_DOWN,this.mouse_down);
- addChild(this.radarsprite);
- this.updatetimer = new Timer(1000 / 30,0);
- this.updatetimer.addEventListener(TimerEvent.TIMER,this.radarHandler);
- this.updatetimer.start();
- }
-
- private function stopplugin(param1:Event) : void
- {
- if(this.updatetimer)
- {
- this.updatetimer.stop();
- this.updatetimer = null;
- }
- if(this.krpano.set != null)
- {
- this.krpano.removePluginEventListener(this,krpano_as3_interface.PLUGINEVENT_REGISTER,this.registerEvent);
- }
- this.radarsprite.removeEventListener(MouseEvent.MOUSE_DOWN,this.mouse_down);
- removeChild(this.radarsprite);
- this.viewinterface = null;
- this.radarinterface = null;
- this.radarsprite = null;
- }
-
- private function mouse_down(param1:MouseEvent) : void
- {
- this.startdrag = true;
- this.mouse_move(param1);
- stage.addEventListener(MouseEvent.MOUSE_MOVE,this.mouse_move);
- stage.addEventListener(MouseEvent.MOUSE_UP,this.mouse_up);
- }
-
- private function mouse_up(param1:MouseEvent) : void
- {
- this.mouse_move(param1);
- stage.removeEventListener(MouseEvent.MOUSE_MOVE,this.mouse_move);
- stage.removeEventListener(MouseEvent.MOUSE_UP,this.mouse_up);
- }
-
- private function mouse_move(param1:MouseEvent) : void
- {
- var _loc2_:Number = NaN;
- var _loc3_:Number = NaN;
- var _loc4_:Number = NaN;
- var _loc5_:Number = Number(this.radarinterface.heading);
- if(isNaN(_loc5_))
- {
- _loc5_ = 0;
- }
- var _loc6_:Number = radarradius;
- _loc2_ = this.mouseX - _loc6_;
- _loc3_ = this.mouseY - _loc6_;
- _loc4_ = Math.atan2(_loc3_,_loc2_) * 180 / Math.PI - _loc5_;
- if(this.startdrag == true)
- {
- this.startangle = _loc4_ - Number(this.viewinterface.hlookat);
- this.startdrag = false;
- }
- else
- {
- this.viewinterface.hlookat = _loc4_ - this.startangle;
- }
- }
-
- private function radarHandler(param1:TimerEvent) : void
- {
- var _loc10_:Number = NaN;
- var _loc11_:Graphics = null;
- var _loc12_:int = 0;
- var _loc13_:int = 0;
- var _loc14_:Number = NaN;
- var _loc15_:Number = NaN;
- var _loc16_:Number = NaN;
- var _loc2_:Number = Number(this.viewinterface.hlookat);
- var _loc3_:Number = Number(this.viewinterface.hfov);
- var _loc4_:Number = Number(this.radarinterface.heading);
- var _loc5_:uint = uint(this.radarinterface.linecolor);
- var _loc6_:Number = Number(this.radarinterface.linewidth);
- var _loc7_:Number = Number(this.radarinterface.linealpha);
- var _loc8_:uint = uint(this.radarinterface.fillcolor);
- var _loc9_:Number = Number(this.radarinterface.fillalpha);
- _loc2_ += _loc4_;
- if(Math.abs(_loc2_ - this.last_hlookat) > 1 || Math.abs(_loc3_ - this.last_fov) > 2)
- {
- this.last_hlookat = _loc2_;
- this.last_fov = _loc3_;
- _loc10_ = radarradius;
- _loc11_ = this.radarsprite.graphics;
- _loc11_.clear();
- _loc11_.beginFill(_loc8_,_loc9_);
- _loc11_.lineStyle(_loc6_,_loc5_,_loc7_);
- _loc11_.moveTo(_loc10_,_loc10_);
- _loc12_ = int(1 + _loc3_ / 10);
- if(_loc12_ < 2)
- {
- _loc12_ = 2;
- }
- _loc13_ = 0;
- _loc13_ = 0;
- while(_loc13_ < _loc12_)
- {
- _loc14_ = (_loc13_ == _loc12_ - 1 ? _loc2_ + _loc3_ / 2 : _loc2_ - _loc3_ / 2 + _loc13_ * _loc3_ / _loc12_) * Math.PI / 180;
- _loc15_ = _loc10_ + _loc10_ * Math.cos(_loc14_);
- _loc16_ = _loc10_ + _loc10_ * Math.sin(_loc14_);
- _loc11_.lineTo(_loc15_,_loc16_);
- _loc13_++;
- }
- _loc11_.endFill();
- }
- }
- }
- }
-
-