﻿<krpano>
	
	<!--
		Example/Tutorial - Extract a Distorted Hotspot from any kind of Pano Image (with perfect pixel alignment):
		https://krpano.com/forum/wbb/index.php?page=Thread&postID=38120#post38120
	-->

	<preview url="pool.tiles/preview.jpg" />

	<image>
		<cube url="pool.tiles/mobile_%s.jpg" />
	</image>

	<view hlookat="90" vlookat="15" fov="100" />


	<!--
		water hotspot
			hfov = 150 (values from PTGUI/Hugin)
			yaw = -90
			pitch = -4
			roll = -30
	-->
	<hotspot name="water"
	         url="pool_extract_mobile.jpg"
	         distorted="true"
	         onloaded="calc_pos_from_hfov_yaw_pitch_roll(150, -90, -4, -30); animation();"
	         enabled="false"
	         alpha="0.0"
	         animation="tween(alpha, calc(1.0 - alpha), 3.0, linear, animation());"
	         />

	<action name="calc_pos_from_hfov_yaw_pitch_roll">
		calc(deg2rad, Math.PI / 180.0);

		<!-- calc the hotspot size -->
		calc(hfov, 0.5 * (%1) * deg2rad);
		Math.tan(hfov);
		set(width, calc(hfov * 1000));
		set(height, 'prop');

		<!-- calc the ath, atv and rotate settings -->
		calc(yaw, -(%2) * deg2rad);
		calc(pitch, (%3) * deg2rad);
		calc(roll, -(%4) * deg2rad);
		Math.cos(ch, yaw);
		Math.sin(sh, yaw);
		Math.cos(ca, pitch);
		Math.sin(sa, pitch);
		Math.cos(cb, roll);
		Math.sin(sb, roll);
		Math.atan2(yaw,  calc(cb*sh - sb*sa*ch), calc(ca*ch));
		Math.atan2(roll, calc(sb*ch - cb*sa*sh), calc(cb*ca));
		Math.asin(pitch, calc(cb*sa*ch + sb*sh));
		calc(ath, yaw / deg2rad);
		calc(atv, pitch / deg2rad);
		calc(rotate, roll / deg2rad);
	</action>

</krpano>
