You are not logged in.

Tuur

Sage

  • "Tuur" started this thread

Posts: 3,839

Location: Netherlands

Occupation: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Send private message

1

Monday, May 9th 2022, 4:38pm

Hotspot visible in screen

Hi,

I was wondering if there is an 'easy' way to 'know' if a hotspot is in the range of the screen and so visible.
Imagine when ath = 0 and we look to 170 the hotspot is invisible.
Is there a way to know or check if a hotspot is in the 'viewing range' ? Taking in mind the view.fov etc..
Obviously I could make an uneducated guess in degrees.. but I am out for a better way.
yes.. I am aware of the getlooktodistance thing.. but I like to have a better 'guess' on the angle/degrees
I might be confused .. as usual.


EDIT:
never mind.
Found a nice way *cool*



Tuur *thumbsup*

This post has been edited 1 times, last edit by "Tuur" (May 10th 2022, 1:59pm)


San7

Professional

Posts: 626

Occupation: coding in krpano

  • Send private message

2

Wednesday, May 11th 2022, 7:40pm

Hi,Tuur,
if so ?

Source code

1
2
3
4
5
6
7
8
9
10
11
12
<events name="test" keep="true" 
        onviewchange="test()"
/>
<action name="test"> 
	copy(hs, hotspot[link]);
	spheretoscreen(hs.ath, hs.atv, x,y );
	if(x GT 0 AND x LT stagewidth AND y GT 0 AND y LT stageheight,
		trace(YES);
		,
		trace(NO);
	);
</action>	

Tuur

Sage

  • "Tuur" started this thread

Posts: 3,839

Location: Netherlands

Occupation: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Send private message

3

Wednesday, May 11th 2022, 10:08pm

Hi San,

Yes! Same idea indeed.
I have more functionality connected and made in js action, but yes basicly like that.

Tuur *thumbsup*

4

Wednesday, May 11th 2022, 11:25pm

on top you can define a pixel with for the border and start fading out hotspots when they get closer to the screen edge.
this is used in zflare.js

Tuur

Sage

  • "Tuur" started this thread

Posts: 3,839

Location: Netherlands

Occupation: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Send private message

5

Wednesday, May 11th 2022, 11:56pm

yeahh.. also nice idea, but I think not useful for what I am doing atm.
I'll have a sleep on it anyway.

Tuur *thumbsup*

6

Thursday, May 12th 2022, 12:52am

this method is not perfect tough...
it can only detect if a hotspot origin is in the visible stage
but a large hotspot may be partially visible, even if its origin is outside the visible stage

Fernando

Intermediate

Posts: 330

Location: Habana, Cuba

Occupation: Architect, Photographer.

  • Send private message

7

Thursday, May 12th 2022, 6:01pm

Any suggestions?

this method is not perfect tough...
it can only detect if a hotspot origin is in the visible stage
but a large hotspot may be partially visible, even if its origin is outside the visible stage
Perhaps by establishing a circumference with a radius equal to the distance between the center and the farthest point of the hotspot and then calculate if that point is inside the screen... Not perfect either, but it would be closer to the solution.


Edit: To many false positive *sad*

Fernando has attached the following images:
  • 20220512_120024.jpg
  • 20220512_121049.jpg

This post has been edited 1 times, last edit by "Fernando" (May 12th 2022, 6:13pm)


San7

Professional

Posts: 626

Occupation: coding in krpano

  • Send private message

8

Thursday, May 12th 2022, 6:11pm

A smooth change in the transparency of the hotspot is already on the forum, I can’t remember the link, but here is the code.
at a deviation of 45 degrees, the transparency is smoothly equal to zero

Source code

1
2
3
4
5
6
7
8
9
10
  <settings transparent_angle="45"/>
  
  <events name="transparent_active" keep="true" onviewchanged="transparent_active"/>
  
 <action name="transparent_active" scope="local">
        getlooktodistance(current_angle, hotspot[logo].ath, hotspot[logo].atv); 
	calc(alpha_hs, 1 -  current_angle /settings.transparent_angle );
	clamp(alpha_hs, 0, get(settings.transparent_angle));
	copy(hotspot[logo].alpha, alpha_hs);    
  </action>

San7

Professional

Posts: 626

Occupation: coding in krpano

  • Send private message

9

Thursday, May 12th 2022, 6:44pm

Perhaps by establishing a circumference with a radius equal to the distance between the center and the farthest point of the hotspot and then calculate if that point is inside the screen... Not perfect either, but it would be closer to the solution.



Depends on the problem statement, I think it is enough to make adjustments in width and height, for example

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<action name="test2"> 
	copy(hs, hotspot[link]);
	spheretoscreen(hs.ath, hs.atv, x,y );
	calc(xw,  hs.pixelwidth / 2 );  
	calc(stw, stagewidth - xw ); 
	calc(yh, hs.pixelheight / 2); 
	calc(sth, stageheight - yh ); 
 
	if(x GT xw AND x LT stw AND y GT yh AND y LT sth,
		trace(YES);
		,
		trace(NO);
	);
</action>

In this case, the signal as soon as the picture reaches the edge

Fernando

Intermediate

Posts: 330

Location: Habana, Cuba

Occupation: Architect, Photographer.

  • Send private message

10

Thursday, May 12th 2022, 10:23pm

Hi, San7, I'am very interesting in your example,
In this case, the signal as soon as the picture reaches the edge
Ok, but how do you make it work if you see a part of the hotspot? (view attachment 2)
Thanks for your help!
Fernando has attached the following images:
  • 1.jpg
  • 2.jpg

San7

Professional

Posts: 626

Occupation: coding in krpano

  • Send private message

11

Friday, May 13th 2022, 6:28am

Hi, San7, I'am very interesting in your example,
In this case, the signal as soon as the picture reaches the edge
Ok, but how do you make it work if you see a part of the hotspot? (view attachment 2)
Thanks for your help!
If super accuracy is not needed, then you can enter a coefficient with a rough correction for fov. This is if the hotspot is distorted. Just pick the right number that satisfies.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<action name="test2"> 
	calc(coeff, 100 / view.fov );
	copy(hs, hotspot[link]);
	spheretoscreen(hs.ath, hs.atv, x,y );
	calc(xw,  (hs.pixelwidth / 2) * coeff );  
	calc(stw, stagewidth - xw ); 
	calc(yh, (hs.pixelheight / 2) * coeff ); 
	calc(sth, stageheight - yh ); 
	if(x GT xw AND x LT stw AND y GT yh AND y LT sth,
		set( hs.alpha,1);  
		,
		set( hs.alpha,0);  
	);
</action>

Fernando

Intermediate

Posts: 330

Location: Habana, Cuba

Occupation: Architect, Photographer.

  • Send private message

12

Friday, May 13th 2022, 10:51am

Hi, San7. Testing with many coeff values (from 0.9 to 5), the result is "NO" -or hide- despite that hotspot is 50% inside screen. Is not useful for my specific case, but it is very interesting code for when the hotspot should look complete up to a certain range.
Thanks for sharing *thumbup*
Fernando has attached the following image:
  • 3.jpg

San7

Professional

Posts: 626

Occupation: coding in krpano

  • Send private message

13

Friday, May 13th 2022, 11:32am

Hi, San7. Testing with many coeff values (from 0.9 to 5), t

Hello, you need to change the number 100 in my code.
calc(coeff, 100 / view.fov );
hotspot - distorted="true"
Works for me.

This post has been edited 1 times, last edit by "San7" (May 13th 2022, 12:47pm)


Fernando

Intermediate

Posts: 330

Location: Habana, Cuba

Occupation: Architect, Photographer.

  • Send private message

14

Saturday, May 14th 2022, 3:12pm

Hi, San7 I testing with coeff, 100 and others values, but not work in my project:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
<hotspotname="mezaninepcchino"
url="%VIEWER%/meza/central_chino+.png"
alpha="0"
keep="true"
zoom="true"
scale="0.000715"
rotate="-70"
ondown="draghotspot();"
ath="-0.013641" atv="0.123258"
enabled="false"
visible="false"
distorted="true"
/>

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<events name="test" keep="true" 
    	onviewchange="test2()"
/>

<action name="test2"> 
	calc(coeff, 100 / view.fov );
	copy(hs, hotspot[mezaninepcchino]);
	spheretoscreen(hs.ath, hs.atv, x,y );
	calc(xw,  (hs.pixelwidth / 2) * coeff );  
	calc(stw, stagewidth - xw ); 
	calc(yh, (hs.pixelheight / 2) * coeff ); 
	calc(sth, stageheight - yh ); 
	if(x GT xw AND x LT stw AND y GT yh AND y LT sth,
		set( hs.alpha,1); trace(YES);  
		,
		set( hs.alpha,0.5); trace(NO); 
	);
</action>
Fernando has attached the following image:
  • 4.jpg

San7

Professional

Posts: 626

Occupation: coding in krpano

  • Send private message

15

Saturday, May 14th 2022, 7:49pm

This is an exampleof how this code works:
calc(coeff, 150 / view.fov );


scale="0.000715" - this is your problem, you change the correction for this size. use setting width and height