﻿<!--
	krpano - compass example
	- it rotates images accordingly to the viewing direction
-->

<krpano>
	
	<!-- grid preview pano -->
	<preview type="grid(cube,16,16,512,0xCCCCCC,0xFFFFFF,0x999999);" />

	<!-- vignetting image -->
	<plugin name="mask" url="vignetting.png" width="100%" height="100%" safearea="false" enabled="false" zorder="0" alpha="0" onloaded="tween(alpha,1);" />
	
	<!-- enable autorotation -->
	<autorotate enabled="true" waittime="3.0" accel="0.5" speed="3" horizon="0" tofov="100" />
	

	<!-- compass with rotating pointer -->
	<layer name="compass1" url="compass_bg.png" align="lefttop" x="10" y="10" children="false" scalechildren="true" destscale="1.0" onclick="switch(destscale,1.0,0.5);tween(scale,get(destscale));">
		<layer name="compass1_plate"   url="compass_plate.png"   align="center"  zorder="1" />
		<layer name="compass1_pointer" url="compass_pointer.png" align="center"  zorder="2" />
		<layer name="compass1_ring"    url="compass_ring.png"    align="lefttop" zorder="3" />
	</layer>
	
	<!-- compass with rotating plate -->
	<layer name="compass2" url="compass_bg.png" align="righttop" x="10" y="10" children="false" scalechildren="true" destscale="1.0" onclick="switch(destscale,1.0,0.5);tween(scale,get(destscale));">
		<layer name="compass2_plate"   url="compass_plate.png"   align="center"  zorder="1" />
		<layer name="compass2_pointer" url="compass_pointer.png" align="center"  zorder="2" />
		<layer name="compass2_ring"    url="compass_ring.png"    align="lefttop" zorder="3" />
	</layer>


	<!-- view changing eeent -->
	<events name="compass_events" onviewchange="compass_update_rotate();" />

	<!-- update the rotation values -->
	<action name="compass_update_rotate">
		set(global_heading, 180);
		calc(plugin[compass1_pointer].rotate, view.hlookat - global_heading);
		calc(plugin[compass2_plate].rotate,  global_heading - view.hlookat);
	</action>


	<!-- add some hotspots -->
	<action name="add_compass_spots" autorun="onstart">
		addspot(n,  0,     0|0| 76|76, 1.0);
		addspot(no, 45,   78|0|118|76, 0.5);
		addspot(o,  90,  202|0| 71|76, 1.0);
		addspot(so, 135, 281|0|109|76, 0.5);
		addspot(s,  180, 400|0| 69|76, 1.0);
		addspot(sw, 225, 469|0|134|76, 0.5);
		addspot(w,  270, 603|0| 86|76, 1.0);
		addspot(nw, 315, 689|0|141|76, 0.5);
	</action>
	
	<action name="addspot">
		addhotspot(%1);
		set(hotspot[%1].url, '%CURRENTXML%/hotspots.png');
		set(hotspot[%1].crop, '%3');
		set(hotspot[%1].ath, %2);
		set(hotspot[%1].atv, 0);
		set(hotspot[%1].scale, %4);
		set(hotspot[%1].scale1, %4);
		calc(hotspot[%1].scale2, %4 * 2);
		set(hotspot[%1].zoom,true);
		set(hotspot[%1].onover, tween(scale,get(scale2)); );
		set(hotspot[%1].onout, tween(scale,get(scale1)); );
		set(hotspot[%1].onclick, lookto(get(ath),get(atv),90); );
	</action>

</krpano>
