Sie sind nicht angemeldet.

Lieber Besucher, herzlich willkommen bei: krpano.com Forum. Falls dies Ihr erster Besuch auf dieser Seite ist, lesen Sie sich bitte die Hilfe durch. Dort wird Ihnen die Bedienung dieser Seite näher erläutert. Darüber hinaus sollten Sie sich registrieren, um alle Funktionen dieser Seite nutzen zu können. Benutzen Sie das Registrierungsformular, um sich zu registrieren oder informieren Sie sich ausführlich über den Registrierungsvorgang. Falls Sie sich bereits zu einem früheren Zeitpunkt registriert haben, können Sie sich hier anmelden.

1

Mittwoch, 12. November 2008, 00:55

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

Quellcode

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

where "rotation" will be the north direction value

with this AS3 code in my plugin :

Quellcode

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 :

Quellcode

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 :

Quellcode

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

Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »zadda« (12. November 2008, 12:03)


2

Freitag, 14. November 2008, 09:08

Hi,

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

e.g.

Quellcode

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

Freitag, 14. November 2008, 21:35

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

4

Freitag, 14. November 2008, 23:18

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

Sonntag, 16. November 2008, 10:46

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

Sonntag, 16. November 2008, 13:38

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

Dienstag, 18. November 2008, 08:05

Hi,

you mean - when running it without krpano?

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

Quellcode

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:

Quellcode

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

Dienstag, 18. November 2008, 12:06

Hi Klaus,

Zitat

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

Dienstag, 30. Dezember 2008, 17:44

one small fix needed

Hi Klaus,

i just need one more small fix ;-)

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

Quellcode

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

Mittwoch, 31. Dezember 2008, 17:45

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.

Quellcode

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

Donnerstag, 1. Januar 2009, 17:37

it works !

Hi,

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

12

Samstag, 4. April 2009, 18:25

Plugin...

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

13

Samstag, 4. April 2009, 19:42

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