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:
Code
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);
}
}
}
Display More
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