You are not logged in.

Fernando

Intermediate

  • "Fernando" started this thread

Posts: 330

Location: Habana, Cuba

Occupation: Architect, Photographer.

  • Send private message

1

Saturday, January 1st 2022, 11:24pm

[solved] How to rotate hotspot for dragging?

Hi,
Solved from adapting the Klaus solution to rotate layer: (Thanks Klaus! *thumbup* )

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<action name="dragrotation_hs">
		<!-- backup current align/edge settings -->
		copy(backup_align, align);
		copy(backup_edge, edge);
		
		<!-- change the origin to lefttop to get coordinates relative to the mouse -->
		changeorigin(lefttop,center);

//adapting code for hotspots...

copy(hsath, hotspot[get(name)].ath);
copy(hsatv, hotspot[get(name)].atv);

spheretoscreen(hsath,hsatv,xath,yatv);

copy(mx, xath);
copy(my, yatv);

// end adapting
		
		<!-- restore the align/edge settings -->
		changeorigin(get(backup_align),get(backup_edge));
		
		<!-- calc the start rotation -->
		sub(dx, mx, mouse.stagex);
		sub(dy, my, mouse.stagey);
		Math.atan2(r, dx, dy);
		div(r, Math.PI);
		mul(r, 180.0);
		add(sr, rotate, r);
		
		<!-- loop as long as the mouse button is pressed and rotate the image -->
		asyncloop(pressed,
			sub(dx, mx, mouse.stagex);
			sub(dy, my, mouse.stagey);
			Math.atan2(r, dx, dy);
			div(r, Math.PI);
			mul(r, 180.0);
			sub(rotate, sr, r);
		  );
	</action>


Example of use:

Source code

1
<hotspot name="hs_spot1" sedge="center"  align="center" rotate="0"  ath="0.175" atv="0.072" ondown="dragrotation_hs"/>


Original Klaus solution for rotate layer: https://krpano.com/forum/wbb/index.php?p…49139#post49139

Best regards,
Fernando

This post has been edited 1 times, last edit by "Fernando" (Jan 3rd 2022, 3:04am) with the following reason: solved