webvr_autozoom.xml 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <krpano>
  2. <!--
  3. webvr_autozoom.xml
  4. krpano 1.20
  5. A helper script for zooming in VR.
  6. After ~2 seconds staring at one point, the view start zooming,
  7. it stops and slowly zooms-out back again when looking around.
  8. -->
  9. <events name="webvr_autozoom" keep="true"
  10. onnewpano="webvr_autozoom_calc_maxzoom();"
  11. webvr_onentervr="webvr_autozoom_start();"
  12. webvr_onexitvr="webvr_autozoom_stop();"
  13. />
  14. <!-- some settings -->
  15. <action name="webvr_autozoom_init" scope="private:webvr_autozoom" autorun="onstart">
  16. set(zoom_delay, 2.0);
  17. set(movement_tolerance, 0.01);
  18. set(zoom_speed, 1.0);
  19. set(max_zoom, 10);
  20. </action>
  21. <!-- calc maxzoom depending onthe current pano image -->
  22. <action name="webvr_autozoom_calc_maxzoom" scope="private:webvr_autozoom">
  23. set(maxwidth, get(global.image.hres));
  24. if(tolower(global.image.type) == 'cube',
  25. calc(maxwidth, maxwidth * Math.PI);
  26. ,tolower(global.image.type) == 'flat',
  27. calc(maxwidth, maxwidth * 360 / 90);
  28. ,
  29. calc(maxwidth, maxwidth * 360 / global.image.hfov);
  30. );
  31. calc(max_zoom, maxwidth / 4000);
  32. </action>
  33. <action name="webvr_autozoom_stop" scope="private:webvr_autozoom">
  34. clearinterval(webvr_autozoom);
  35. </action>
  36. <action name="webvr_autozoom_start" scope="private:webvr_autozoom">
  37. copy(last_tick, global.timertick);
  38. copy(last_movement_tick, last_tick);
  39. copy(last_view_hlookat, global.view.hlookat);
  40. copy(last_view_vlookat, global.view.vlookat);
  41. setinterval(webvr_autozoom, 0.1,
  42. copy(cur_tick, global.timertick);
  43. if(global.webvr.isenabled,
  44. getlooktodistance(move_distance, last_view_hlookat, last_view_vlookat);
  45. calc(movespeed, move_distance / (cur_tick-last_tick));
  46. calc(movement_tolerance, 0.01 / (global.webvr.zoom^0.5));
  47. if(movespeed GT movement_tolerance,
  48. copy(last_movement_tick, cur_tick);
  49. tween(zoom_speed, 1.0, 0);
  50. Math.pow(movespeed, 0.5);
  51. );
  52. if((cur_tick - last_movement_tick) GT (zoom_delay*1000),
  53. tween(zoom_speed, 1.04);
  54. );
  55. calc(new_zoom, global.webvr.zoom * (zoom_speed * (1.0 - movespeed)) );
  56. clamp(new_zoom, 1, get(max_zoom));
  57. tween(global.webvr.zoom, get(new_zoom), 0.1, linear);
  58. calc(global.webvr.friction, new_zoom GT 2.0 ? (new_zoom - 2.0) / 100.0 : 0);
  59. ,
  60. copy(last_movement_tick, cur_tick);
  61. );
  62. copy(last_tick, cur_tick);
  63. copy(last_view_hlookat, global.view.hlookat);
  64. copy(last_view_vlookat, global.view.vlookat);
  65. );
  66. </action>
  67. </krpano>