You are not logged in.

San7

Professional

  • "San7" started this thread

Posts: 626

Occupation: coding in krpano

  • Send private message

1

Wednesday, March 1st 2023, 2:07pm

get distance to model (wall, floor, ceiling)

RESOLVED!
I'm trying to get the distance to the model (wall, floor, ceiling) along a line from viewpoint to hotspot.
I made a test, next to the mouse cursor, the distance to the model is shown at the location of the screentodepth ( mouse.x, mouse.y, hit);

I placed the hotspots further than the model and when clicking on the hotspot, the distance to the partitions on the hotspot should be displayed (on the line from the viewpoint to the hotspot)
raycastdepth(view.tx, view.ty, view.tz, caller.tx, caller.ty, caller.tz, hit);

when view.tx, view.ty, view.tz are zero, then the distances are the same, but if I start moving, then when I click on the hotspots, other numbers are displayed.

What could be wrong? *confused*

Here is an example and code

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<layer name="inf_l" type="text" keep="true" edge="bottom" oy="-20" enabled="false" bgalpha="0.3"
	onloaded="show_distance(); delayedcall(0.01, onloaded());"   />
	
<action name="show_distance" scope="local" > 
	screentodepth( mouse.x, mouse.y, hit); 
	copy(caller.x, mouse.x);
	copy(caller.y, mouse.y);
	calc(caller.html, 'mouse hit.d=' + roundval(hit.d, 1));
</action>
	
<style name="hs" type="text" keep="true" distorted="false" depth="0" depthbuffer="false" rotationorder="zxy"  
	bg="true" padding="2 5 2 5"  html="hs" onclick="show_distance2()" />	
	
<hotspot name="hs1" style="hs" tx="-100" ty="300" tz="300" />	
<hotspot name="hs2" style="hs" tx="-300" ty="0"   tz="200" />

<action name="show_distance2" scope="local"   >
	raycastdepth(view.tx, view.ty, view.tz, caller.tx, caller.ty, caller.tz, hit );
	calc(caller.html,'hit.d='+ roundval(hit.d, 1));
	trace(caller.html);
</action>

This post has been edited 1 times, last edit by "San7" (Mar 2nd 2023, 4:29am)


Tuur

Sage

Posts: 3,839

Location: Netherlands

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

  • Send private message

2

Wednesday, March 1st 2023, 2:50pm

Strange indeed..
Not sure if understand completely what you want to do.
I was wondering..
don't you need the caller.hit in the show_distance2 action instead of hit (??)
Or perhaps the raycastdepth call is not the right one.
Fully unsure though..

*wacko*

Tuur *thumbsup*

San7

Professional

  • "San7" started this thread

Posts: 626

Occupation: coding in krpano

  • Send private message

3

Wednesday, March 1st 2023, 2:55pm

Hi Tuur!
I'm trying to determine if the access point is further away from the wall or closer to line of sight. To do this, I need to know the distance to the wall and the hotspot in one line.
But so far it's not working out very well for me)

kme

Intermediate

Posts: 310

Location: Belgium

Occupation: Long time coder, product manager and 3D enthousiast

  • Send private message

4

Wednesday, March 1st 2023, 2:56pm

Been looking at it a bit and no idea yet but i noticed 2 things:

- when starting from the origin and moving UP ONLY, the distance on hs1 stays the same, while it does change on hs2
- when starting form the origin and moving BACK ONLY, the distance on hs2 changes, but not on hs2

Something to do with ty/tz values somewhere, but still puzzling, but wanted to share this finding, maybe it gives someone else a hint.

San7

Professional

  • "San7" started this thread

Posts: 626

Occupation: coding in krpano

  • Send private message

5

Wednesday, March 1st 2023, 3:01pm

Been looking at it a bit and no idea yet but i noticed 2 things:

- when starting from the origin and moving UP ONLY, the distance on hs1 stays the same, while it does change on hs2
- when starting form the origin and moving BACK ONLY, the distance on hs2 changes, but not on hs2

Something to do with ty/tz values somewhere, but still puzzling, but wanted to share this finding, maybe it gives someone else a hint.


Yes, I can’t catch the connection, in theory it should change, because I specify all the values of raycastdepth(view.tx, view.ty, view.tz ...

kme

Intermediate

Posts: 310

Location: Belgium

Occupation: Long time coder, product manager and 3D enthousiast

  • Send private message

6

Wednesday, March 1st 2023, 3:17pm

Been debugging it a bit, the only thing I can think of is that the raycastdepth is not requesting a LOCATION for the distance, but a DIRECTION.

See documentation: https://krpano.com/docu/actions/#raycastdepth
mentions: 3D direction vector of the ray.

Not sure how to translate the "current view to hotspot location" to "current view to view direction".

San7

Professional

  • "San7" started this thread

Posts: 626

Occupation: coding in krpano

  • Send private message

7

Wednesday, March 1st 2023, 3:21pm

There is an example below that states
raycastdepth(view.tx, view.ty, view.tz, view.dir.x, view.dir.y, view.dir.z, hit);
This means we can determine the distance from any point in the view, in this example in the forward direction

kme

Intermediate

Posts: 310

Location: Belgium

Occupation: Long time coder, product manager and 3D enthousiast

  • Send private message

8

Wednesday, March 1st 2023, 3:26pm

There is an example below that states
raycastdepth(view.tx, view.ty, view.tz, view.dir.x, view.dir.y, view.dir.z, hit);
This means we can determine the distance from any point in the view, in this example in the forward direction


I altered your example with the following action:

Source code

1
2
3
4
5
6
7
8
9
	<action name="show_distance2" scope="local"   >
		raycastdepth(view.tx, view.ty, view.tz, caller.tx, caller.ty, caller.tz, hit );
		raycastdepth(view.tx, view.ty, view.tz, view.dir.x, view.dir.y, view.dir.z, hitv);
		
		trace(caller.name);
		trace(caller.tx, "|", caller.ty, "|", caller.tz);
		calc(caller.html,'hit.d='+ roundval(hit.d, 1) + '|' + roundval(hitv.d, 1));
		trace(caller.html);
	</action>


When I use that and put the hotspots EXACTLY (using a game crosshair overlay) in the center of my screen, I get the same values for the hittest of the mouse.

So my conclusion is that direction <> location

San7

Professional

  • "San7" started this thread

Posts: 626

Occupation: coding in krpano

  • Send private message

9

Wednesday, March 1st 2023, 3:26pm

Been debugging it a bit, the only thing I can think of is that the raycastdepth is not requesting a LOCATION for the distance, but a DIRECTION.

See documentation: https://krpano.com/docu/actions/#raycastdepth
mentions: 3D direction vector of the ray.

Not sure how to translate the "current view to hotspot location" to "current view to view direction".

Or do you mean that you need to specify the delta dx dy dz ?

kme

Intermediate

Posts: 310

Location: Belgium

Occupation: Long time coder, product manager and 3D enthousiast

  • Send private message

10

Wednesday, March 1st 2023, 3:39pm

Or do you mean that you need to specify the delta dx dy dz ?


I assume something like that, yes.

When I trace the values of

Source code

1
2
3
trace(view.dir.x);
trace(view.dir.y);
trace(view.dir.z);

I get

Source code

1
2
3
INFO: -0.9417157173156738
INFO: 0.02299703285098076
INFO: 0.3356228470802307


Which seem far from 3D coordinates (but more like rotation values ?)

San7

Professional

  • "San7" started this thread

Posts: 626

Occupation: coding in krpano

  • Send private message

11

Wednesday, March 1st 2023, 3:57pm

caller.tx, caller.ty, caller.tz, relative to the zero coordinate. Perhaps they need to be calculated relative to view.tx, view.ty, view.tz
I will test

kme

Intermediate

Posts: 310

Location: Belgium

Occupation: Long time coder, product manager and 3D enthousiast

  • Send private message

12

Wednesday, March 1st 2023, 4:13pm

Good luck!

13

Wednesday, March 1st 2023, 6:29pm

Hi,

right, you need a direction vector, e.g. between the hotspot and the view.

E.g. instead of:

Source code

1
raycastdepth(view.tx, view.ty, view.tz, caller.tx, caller.ty, caller.tz, hit );


try this:

Source code

1
raycastdepth(view.tx, view.ty, view.tz, (caller.tx - view.tx), (caller.ty - view.ty), (caller.tz - view.tz), hit );


Best regards,
Klaus

San7

Professional

  • "San7" started this thread

Posts: 626

Occupation: coding in krpano

  • Send private message

14

Wednesday, March 1st 2023, 6:34pm

Hi,

right, you need a direction vector, e.g. between the hotspot and the view.

E.g. instead of:

Source code

1
raycastdepth(view.tx, view.ty, view.tz, caller.tx, caller.ty, caller.tz, hit );


try this:

Source code

1
raycastdepth(view.tx, view.ty, view.tz, (caller.tx - view.tx), (caller.ty - view.ty), (caller.tz - view.tz), hit );


Best regards,
Klaus

It works!!! Klaus, thank you very much for the hint !!! *thumbsup*