You are not logged in.

1

Wednesday, November 12th 2008, 12:55am

Compass code from FPP to KRP

Hi,

Well i'm using a compass code in FPP, working fine and try (with no sucess so far) to adapt it to KRP
i have a plugin with a movieclip called "compass_ring_btn",
i want it rotate accordingly to the pano pan :

in FPP i use an invisible hotspot in xml

Source code

1
2
<!-- COMPASS -->
<spot id="deltarotation" rotation="0" />

where "rotation" will be the north direction value

with this AS3 code in my plugin :

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//////////// COMPASS AS3 START CODE ///////////////////////////////////
//var movie:Sprite;///
//var hotspot:Object;///
//var pano:Object;///

var hotspots:Object;///
//
loaderInfo.addEventListener(Event.INIT, initHandler);
//
var sTimer:Timer; ///

 function initHandler (event:Event) {
	if (loaderInfo.loader!=null) {
		
		// get link to hotspots plugin object:
		hotspots = loaderInfo.loader.hotspots;	
		
		// setting refreshing timer
		sTimer = new Timer(50);
		sTimer.addEventListener("timer", updateFov);
		sTimer.start();
}
}


function updateFov (e:Event) {
//
	// get link to pano object:
	pano = hotspots.getPano();
	
	// get link to deltarotation hotspot
	deltaRotation = hotspots.getSpot('deltarotation');  // deltarotation = hotspot ID
	
	// calculating fov new rotation:  
	fovRotation = -pano.pan + deltaRotation.rotation;
	
	//compass_ring_btn
	compass_ring_btn.rotation = +fovRotation // rotate the compass accordingly to the pano pan
}

//////////// COMPASS AS3 END CODE ///////////////////////////////////


Then to adapt to KRP,
i make an invisible hotspot in xml like this :

Source code

1
<hotspot name="deltarotation" url="any.png" handcursor="false" visible="false" ath="100" atv="0" >
where "ath" will be North direction...

and in my Plugin AS3 :

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
        	// timer that reads hlookat and fov and updates the compass
			updatetimer = new Timer(1000/30,0);		// 30fps
			updatetimer.addEventListener(TimerEvent.TIMER, updateFov);
			
			updatetimer.start();

function updateFov (e:Event) {

//

	// get link to pano object:
   var view:Object = krpano.get("view");

   

	

	// get link to deltarotation hotspot
	var pluginobject:Object = krpano.get("plugin[deltarotation]");



	

	// calculating fov new rotation:  

	deltaRotation.rotation = Number( krpano.get("plugin[deltarotation].ath") );

	

	//compass_ring_btn 

	compass_ring_btn.rotation = deltaRotation.rotation // should rotate the compass accordingly to the pano pan

}


as you see, i'm pretty noob in AS3 :wacko: , because i'm designer.
so any help appreciated.


Thanks

This post has been edited 1 times, last edit by "zadda" (Nov 12th 2008, 12:03pm)


2

Friday, November 14th 2008, 9:08am

Hi,

must must calculate the delta to the current looking direction (view.hlookat):
(and you have mixed up "plugin" and "hotspot" )

e.g.

Source code

1
2
3
4
5
6
7
8
9
10
function updateFov (e:Event) 
{
    var view:Object = krpano.get("view");
    
    var hotspotobject:Object = krpano.get("hotspot[deltarotation]");

    var rotation:Number = Number( hotspotobject.ath )  -   view.hlookat;

    compass_ring_btn.rotation = rotation;   // should rotate the compass accordingly to the pano pan
}

3

Friday, November 14th 2008, 9:35pm

Hi Klaus,
Thanks a lot, it works as expected !
was a really great time saver, thanks again :thumbsup:

4

Friday, November 14th 2008, 11:18pm

a final request :
flash throw me an loop error (because of the timer)
ReferenceError: Error #1069: ath property not found on string and there no default value..

then how i set up a default value for ath,
i've tried with no success :
if (isNaN(ath)) {
ath = 0;
}
(sorry again my poor coding ?( )

however it works fine over KRP, but i would like to make the thing bugless.

Thanks

(by the way , little planet view is great ! congrats ! )

5

Sunday, November 16th 2008, 10:46am

Hi,

when did you get this error?
always? only when loading a new pano?

please also be sure that "version" in the xml files is set to "1.0.7" or higher,
for example - if it was set to "1.0.5" krpano didn't return a "Object", it returns only a "String",
this could be also the problem...

best regards,
Klaus

6

Sunday, November 16th 2008, 1:38pm

Hi,

this error come ONLY in the output panel in Flash CS3 IDE,
but i don't see in browser using Flash Player 10 (there no debugger installed yet),
i supose it works fine because "ath" has a number value while the compass is playing over krpano 1.07,

in the AS3 code , we just have to give a default value to "ath" if nothing is found (if ath ==null) then ath = 100..
but i do'nt know exactly the syntax of this...

Thanks

7

Tuesday, November 18th 2008, 8:05am

Hi,

you mean - when running it without krpano?

you can check if the plugin runs in krpano by using a ADDED_TO_STAGE event:

Source code

1
2
3
4
5
6
this.addEventListener(Event.ADDED_TO_STAGE, startup_in_krpano);

function startup_in_krpano (evt:Event):void
{
  // e.g. - set here anything to note you're running on krpano
}


or check if the "krpano.get" function from the interface was set,
e.g:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function updateFov (e:Event) 
{
  var rotation:Number = 0;   // default value

  if (krpano.get != null)
  {
    var view:Object = krpano.get("view");
    
    var hotspotobject:Object = krpano.get("hotspot[deltarotation]");

    // real value
    rotation = Number( hotspotobject.ath )  -   view.hlookat;
  }

  compass_ring_btn.rotation = rotation;   // should rotate the compass accordingly to the pano pan
}


best regards,
Klaus

8

Tuesday, November 18th 2008, 12:06pm

Hi Klaus,

Quoted

you mean - when running it without krpano?
Yes, exactly,
the Output Panel of FLASH CS3 is looping this error, stressing my CPU (i guess) and myself (i sure :D )

But Fixed now !

Thanks Klaus, Great support ! :thumbup:
(and support is the key of success)

9

Tuesday, December 30th 2008, 5:44pm

one small fix needed

Hi Klaus,

i just need one more small fix ;-)

so,
i'm using successfully the compass code in my plugin,

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
this.addEventListener(Event.ADDED_TO_STAGE, startup_in_krpano);
//}
function startup_in_krpano (evt:Event):void
{

// timer that reads hlookat and fov and updates the compass
			updatetimer = new Timer(1000/30,0);		// 30fps
			updatetimer.addEventListener(TimerEvent.TIMER, updateFov);
			updatetimer.start();

//
function updateFov (e:Event) 
{
	 
 var rotation:Number = 0;   // default value
 //
 	if (krpano.get != null)
  {
    var view:Object = krpano.get("view");
    
    var hotspotobject:Object = krpano.get("hotspot[deltarotation]");

    // real value
    rotation = Number( hotspotobject.ath )  -   view.hlookat;
  }
  //

  compass_ring_btn.rotation = rotation;   // rotate the compass accordingly to the pano pan
}


}

but when i load a new pano (throught an hotspot in .xml with the following action :
onclick="loadpano(pano2.xml,qtvr=pano2.mov,KEEPALL,BLEND(2));" )
--
the Flash 10 Debugger version throw me an error :

// TypeError: Error #1009:Cannot access a property or method of a null object reference.
// at compass_AS3_fla:MainTimeline/startup_in_krpano/compass_AS3_fla:updateFov()[compass_AS3_fla.MainTimeline::frame1:329]
// at flash.utils::Timer/_timerDispatch()
// at flash.utils::Timer/tick()
--
the compass find his new orientation after loading the new pano.
so everything works as expected but the error while pano transition..

then, i think i have to setup a conditional , because when loading a new pano,
there no more stage or no pano or something like that...
so i have to stop the timer or something similar,
forgive my ignorance as i'm not really a coder guy :-)

i think , it will be obvious for you and just matter of minutes,
for my part i've tried many solution without success so far...


So any help welcome :-)

and an happy (successful) new year (of course) *thumbup*

10

Wednesday, December 31st 2008, 5:45pm

Hi,

I think the problem is, that when loading a new pano, all hotspots without keep="true"
are removed,

you can fix this, by adding keep="true" to your hotspot,
or if in the new xml a new hotspot with the name "deltarotation" is defined,
the hotspot doesn't exists only for a short time,
so just check if the hotspot object is not null, and do nothing in the meanwhile,

e.g.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function updateFov (e:Event) 
{
  var rotation:Number = 0;   // default value

  if (krpano.get != null)
  {
	var view:Object = krpano.get("view");
    
	var hotspotobject:Object = krpano.get("hotspot[deltarotation]");

	if (hotspotobject == null)   	// <= NEW - check if hotspot object exsits
    	return;

	// real value
	rotation = Number( hotspotobject.ath )  -   view.hlookat;
  }
}


wish you a happy new year too
Klaus

11

Thursday, January 1st 2009, 5:37pm

it works !

Hi,

Thanks, it works smoothly now *thumbsup*
2009 start very well ;-)

12

Saturday, April 4th 2009, 6:25pm

Plugin...

Hi Klaus.
Can you make a plugin with the Compass?
Thank you.

13

Saturday, April 4th 2009, 7:42pm

Hi, for a compass a dedicated plugin wouldn't be necessary anymore,
now it can be done only with simple images and some xml code,
have a look at this example:
COMPASS EXAMPLE