You are not logged in.

Dear visitor, welcome to krpano.com Forum. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Tuesday, March 17th 2009, 9:06am

Follow Mouse Plugin

Hello,

I was asked about a follow mouse control mode,
such control mode doesn't exists currently in krpano,
but it would be very easy to implement it as plugin:
  • add a ENTER_FRAME handler
  • look for the mouse coordinates
  • modify the hlookat_moveforce / vlookat_moveforce values accordingly

here is an example plugin source code:

AS3 plugin code:

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package
{
  import flash.display.Sprite;
  import flash.events.Event;

  import krpano_as3_interface;


  public class followmouse extends Sprite
  {
    private var krpano : krpano_as3_interface = null;

    public function followmouse()
    {
      if (stage == null)
        this.addEventListener(Event.ADDED_TO_STAGE, startplugin);
    }

    private function startplugin(evt:Event):void
    {
      krpano = krpano_as3_interface.getInstance();

      if ( krpano.get("version") < "1.0.7" )
      {
        krpano.call("error(followmouse plugin - wrong krpano version! 1.0.7 or higher needed);");
        return;
      }

      // disable default mouse control
      krpano.set("control.mousetype", "off");

      // add frame listener
      addEventListener(Event.ENTER_FRAME, enterFrameHandler);
    }


    private function enterFrameHandler(event:Event):void
    {
      var mx:Number = stage.mouseX;
      var my:Number = stage.mouseY;
      var sx:Number = stage.stageWidth  * 0.5;
      var sy:Number = stage.stageHeight * 0.5;

      // calc motion vectors: -1.0 to +1.0
      var vx:Number = (mx - sx) / sx;
      var vy:Number = (my - sy) / sy;

      // advance it a little bit:
      // - make moving slower in the middle
      // - and faster in the outer regions
      vx = (vx < 0 ? -1.0 : +1.0) * Math.pow(Math.abs(vx), 2.0);
      vy = (vy < 0 ? -1.0 : +1.0) * Math.pow(Math.abs(vy), 2.0);

      // stop very slow moving
      if (Math.abs(vx) < 0.01)  vx = 0;
      if (Math.abs(vy) < 0.01)  vy = 0;

      // set move forces
      krpano.set("hlookat_moveforce", vx);
      krpano.set("vlookat_moveforce", vy);
    }
  }
}



here an online example with it:
Follow Mouse Plugin Example


download the plugin and source here:
followmouse_plugin.zip
followmouse_sourcecode.zip


best regards,
Klaus

2

Tuesday, March 17th 2009, 7:27pm

wahou !!!
a great one

tx a lot Klaus *thumbsup*

3

Saturday, April 4th 2009, 12:11am

can't disable

Hi Klaus,

The plugin works great, and makes total sense.

One issue I'm having is disabling it... Here's my XML:



<plugin name="followmouse"
url="followmouse.swf"
enabled="false"
capture="false"
/>

The reason I'm doing this, is because I don't want to enable it until my initial animation sequence has finished. Have I typoed in my XML, or is there a problem with disabling this plugin? This is the first time I've tried disabling a plugin, next step will be for me to figure out how to re-enable it ;-)

Thanks for the help,
John

4

Saturday, April 4th 2009, 1:12am

Hi,

with enabled="false" only the clicking possibility of an plugin will be disabled
to enable/disable it the plugin must be extended with an option for that,

or try to remove and add it dynamically with "removeplugin() " and "addplugin() "
this could also work,

best regards,
Klaus

5

Thursday, May 21st 2009, 5:37pm

disenabled followmouse

Hi Klauss !
I don't why but addplugin() and removeplugin() can't disenabled the followmouse ...
can u help me ???? *confused*

6

Wednesday, May 27th 2009, 10:19am

Hi, that's just because this plugin doesn't listen for removing, sorry

here is an updated plugin code with a remove event,
now removeplugin() will work:

AS3 plugin code:

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package
{
    import flash.display.Sprite;
    import flash.events.Event;

    import krpano_as3_interface;


    public class followmouse extends Sprite
    {
        private var krpano : krpano_as3_interface = null;

        private var control_mousetype_backup:String = null;

        public function followmouse()
        {
            if (stage == null)
            {
                this.addEventListener(Event.ADDED_TO_STAGE, startplugin);
                this.addEventListener(Event.REMOVED_FROM_STAGE, stopplugin);
            }
        }

        private function startplugin(evt:Event):void
        {
            krpano = krpano_as3_interface.getInstance();

            if ( krpano.get("version") < "1.0.7" )
            {
                krpano.call("error(followmouse plugin - wrong krpano version! 1.0.7 or higher needed);");
                return;
            }

            // save current control mode
            control_mousetype_backup = krpano.get("control.mousetype");
            
            // disable default mouse control
            krpano.set("control.mousetype", "off");

            // add frame listener
            addEventListener(Event.ENTER_FRAME, enterFrameHandler);
        }
        
        private function stopplugin(evt:Event):void
        {
            // remove frame listener
            removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
                    
            // restore old controlmode
            krpano.set("control.mousetype", control_mousetype_backup);
        }

        private function enterFrameHandler(event:Event):void
        {
            var mx:Number = stage.mouseX;
            var my:Number = stage.mouseY;
            var sx:Number = stage.stageWidth  * 0.5;
            var sy:Number = stage.stageHeight * 0.5;

            // calc motion vectors: -1.0 to +1.0
            var vx:Number = (mx - sx) / sx;
            var vy:Number = (my - sy) / sy;

            // advance it a little bit:
            // - make moving slower in the middle
            // - and faster in the outer regions
            vx = (vx < 0 ? -1.0 : +1.0) * Math.pow(Math.abs(vx), 2.0);
            vy = (vy < 0 ? -1.0 : +1.0) * Math.pow(Math.abs(vy), 2.0);
            
            // stop very slow moving
            if (Math.abs(vx) < 0.01)    vx = 0;
            if (Math.abs(vy) < 0.01)    vy = 0;

            // set move forces
            krpano.set("hlookat_moveforce", vx);
            krpano.set("vlookat_moveforce", vy);
        }
    }
}


and here an updated swf:
followmouse_v2.zip

best regards,
Klaus

7

Tuesday, February 9th 2010, 10:31am

Hi,

here another follow mouse plugin variant:

it follows the mouse only on the outer area of the pano,
and allows normal control in the center,
and as addition in this plugin the movement stops when the mouse leaves the screen/pano,

here the as3 code:

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;

    import krpano_as3_interface;

    public class followmouse extends Sprite
    {
        private var krpano : krpano_as3_interface = null;

        public function followmouse()
        {
            if (stage == null)
            {
                this.addEventListener(Event.ADDED_TO_STAGE, startplugin);
                this.addEventListener(Event.REMOVED_FROM_STAGE, stopplugin);
            }
        }

        private function startplugin(evt:Event):void
        {
            krpano = krpano_as3_interface.getInstance();

            if ( krpano.get("version") < "1.0.7" )
            {
                krpano.call("error(followmouse plugin - wrong krpano version! 1.0.7 or higher needed);");
                return;
            }

            stage.addEventListener(Event.MOUSE_LEAVE,     mouse_out);
            stage.addEventListener(MouseEvent.MOUSE_MOVE, mouse_move);
        }

        private function stopplugin(evt:Event):void
        {
            stage.removeEventListener(Event.MOUSE_LEAVE,     mouse_out);
            stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouse_move);
        }

        private function mouse_move (event:MouseEvent):void
        {
            var mx:Number = stage.mouseX;
            var my:Number = stage.mouseY;
            var sx:Number = stage.stageWidth  * 0.5;
            var sy:Number = stage.stageHeight * 0.5;


            // calc motion vectors: -1.0 to +1.0
            var vx:Number = (mx - sx) / sx;
            var vy:Number = (my - sy) / sy;

            if ( event.buttonDown || (vx > -0.5 && vx < 0.5 && vy > -0.5 && vy < 0.5) )
            {
                // middle area - normal control

                krpano.set("hlookat_moveforce", 0);
                krpano.set("vlookat_moveforce", 0);
            }
            else
            {
                // outer area - automatic followmouse movement

                vx = 2.0 * (vx < 0 ? -1.0 : +1.0) * (Math.max(Math.abs(vx),0.5) - 0.5);
                vy = 2.0 * (vy < 0 ? -1.0 : +1.0) * (Math.max(Math.abs(vy),0.5) - 0.5);

                // stop very slow moving
                if (Math.abs(vx) < 0.01)    vx = 0;
                if (Math.abs(vy) < 0.01)    vy = 0;

                // set move forces
                krpano.set("hlookat_moveforce", vx);
                krpano.set("vlookat_moveforce", vy);
            }
        }

        private function mouse_out(event:*):void
        {
            krpano.set("hlookat_moveforce", 0);
            krpano.set("vlookat_moveforce", 0);
        }
    }
}


and here as download: (.swf and .as)
followmouse_v3.zip

best regards,
Klaus

8

Wednesday, February 24th 2010, 3:52pm

Thanks Klaus, it's great!!!

9

Friday, April 23rd 2010, 10:43pm

hovering over a map

Klaus,

I have a map that slides out from the side on hover, and I was wondering if there was a way to disable this plug in
when the mouse is hovered over the map

thanks so much for the help

you truly are the pano king

-K

10

Thursday, May 13th 2010, 7:09pm

Nice plugin! Tried it with the area-tag, but that doesn't work. Any ideas how to get that working?

11

Wednesday, May 19th 2010, 12:05pm

var mx:Number = stage.mouseX;
var my:Number = stage.mouseY;
var sx:Number = stage.stageWidth * 0.5;
var sy:Number = stage.stageHeight * 0.5;

Maybe 'stage' must be something else when using an area. area instead of stage? Don't think so?

Tuur

Sage

Posts: 3,173

Location: Netherlands

Occupation: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Send private message

12

Wednesday, May 19th 2010, 2:33pm

maybe stupid but did you try parent="area" ?
if that's possible in the first place..


Tuur *thumbsup*
http://www.virtualtuur.com
Skype:studiotuur

13

Wednesday, May 19th 2010, 3:03pm

parent area not found (ofzoiets). Doesn't work :(.

14

Thursday, May 20th 2010, 1:22pm

Hi,
var mx:Number = stage.mouseX;
var my:Number = stage.mouseY;
var sx:Number = stage.stageWidth * 0.5;
var sy:Number = stage.stageHeight * 0.5;

Maybe 'stage' must be something else when using an area. area instead of stage? Don't think so?
right, to get it working with area you need to use also the area size and position,

e.g.

Source code

1
2
3
4
5
6
var area:Object = krpano.get("area");

var mx:Number = stage.mouseX - area.pixelx;
var my:Number = stage.mouseY - area.pixely;
var sx:Number = area.pixelwidth  * 0.5;
var sy:Number = area.pixelheight * 0.5;


best regards,
Klaus

15

Thursday, May 20th 2010, 1:35pm

Thank you. Does this also work with a non-fixed pixelheight/width? So with percentages?

I'll try later @ home. Thanks!

16

Thursday, May 20th 2010, 1:49pm

Hi,

yes, the area.pixel* values are the calculated pixels values,

best regards,
Klaus

17

Sunday, June 13th 2010, 8:19am

klaus, danke nochmals für die hilfe!
funktioniert jetzt und ich kann im panorma nur durch kopfbewegung navigieren (mittels track-ir und diodenkappe).
allerdings ist die bewegung sehr schnell.kann man die geschwinkdigkeit, trägheit etc. auf einfachen weg gut einstellen, ansonsten dreht es viel zu schnell, wenn ich nur ein bißchen denkopf bewege. stelle es mir so vor, wie beim ms-flight-simulator, da funktionioerts perfekt mit der kopfdrehung/bilddrehung (aussicht aus dem flugzeug z.b.).
danke
lg pauli

Tuur

Sage

Posts: 3,173

Location: Netherlands

Occupation: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Send private message

18

Sunday, June 13th 2010, 11:55am

He Pauli,

do you use those virtual goggles??

Which ones? i'm looking forward to use those as well..

can you provide some info??

I think you can probably change the turning with the settings with the plugin where you also can see the lookto etc ..
have a play with that..

I think it's the options plugin.. else the editor..

Cheers

Tuur *thumbsup*
http://www.virtualtuur.com
Skype:studiotuur

milotimbol

Intermediate

Posts: 220

Location: Philippines

Occupation: Software Developer

  • Send private message

19

Thursday, July 8th 2010, 2:02am

Nice plugin! I'm trying to create a toggle on/off mouse follow option on my tour. However when I do this

Source code

1
2
3
	<action name="mouseFollowOff">
		removeplugin(mousefollow);
	</action>


the player wont stop looking at the sky. The plugin is disabled but when I try to drag the view back to the center, it would go back looking at the sky.

Here's how i declared the plugin.

Source code

1
2
3
4
5
	<plugin name="mousefollow" 
		url="%SWFPATH%/plugins/followmouse.swf" 
		keep="true"
		enabled="true"
	/>


Here's how i am removing it, just removed the unnecessary middle section like alpha, blendmode, etc.

Source code

1
plugin name="mouseFollowOffBtn" url="mouse-follow-off.png" alpha="0.9"  y="-4" x="695" onclick="action(mouseFollowOff);"/>


Is there a way to fix this?

thanks,
Milo

Zephyr

Professional

Posts: 994

Location: Netherlands

Occupation: Web developer

  • Send private message

20

Friday, July 9th 2010, 9:10am

try resetting the moveforce

Source code

1
2
set(hlookat_moveforce, 0);
set(vlookat_moveforce, 0);
3d childrens game using krpano Game
Minify your xml with my krpano XML Compressor
Krpano XML Parsing Error Checklist
Available for hire (krpano xml, javascript, actionscript, flash, php and ipad plugins).

Similar threads