Created
September 17, 2016 03:16
-
-
Save SpencerCooley/20d8dde21b35f89e54179cdb55fdee8d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- new krpano 1.19 feature: Javascript actions (can be faster than xml actions, HTML5 only) --> | |
<action name="vr_menu_following" type="Javascript" devices="html5"><![CDATA[ | |
var hs1 = krpano.get("hotspot[vr_menu_bg]"); | |
var hs2 = krpano.get("hotspot[vr_menu_home]"); | |
var hs3 = krpano.get("hotspot[vr_menu_l]"); | |
var hs4 = krpano.get("hotspot[vr_menu_r]"); | |
if(!hs1.hovering && !hs2.hovering && !hs3.hovering && !hs4.hovering) | |
{ | |
var f = 0.01; // follow speed factor | |
var h = krpano.view.hlookat; | |
var v = krpano.view.vlookat; | |
var hsh = hs1.ath; | |
var hsv = hs1.atv; | |
// map to -180 to +180 | |
h = (h -(h|0)) + (((h|0) +360180)%360) - 180.0; | |
hsh = (hsh-(hsh|0)) + (((hsh|0)+360180)%360) - 180.0; | |
// get the shortest horizontal distance | |
dh = h - hsh; | |
dh += (dh>180) ? -360 : (dh<-180) ? 360 : 0 | |
// follow slowing horizontally | |
hsh += dh*f; | |
// fade out when farther away | |
var a = Math.abs(v - hs1.atv) / 90.0; | |
a = 0.5 * Math.max(1.0 - 2.0*Math.sqrt(a), 0); | |
// move up the more looking down | |
v = v + 55.0 - v*1.5; | |
hsv = hsv*(1-f) + v*f; | |
// set everything | |
hs2.alpha = hs1.alpha = a; | |
if(!hs3.hovering) hs3.alpha = a; | |
if(!hs4.hovering) hs4.alpha = a; | |
hs4.ath = hs3.ath = hs2.ath = hs1.ath = hsh; | |
hs4.atv = hs3.atv = hs2.atv = hs1.atv = hsv; | |
} | |
]]></action> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment