Sie sind nicht angemeldet.

1

Mittwoch, 1. März 2023, 14:07

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

Quellcode

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>

Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »San7« (2. März 2023, 04:29)


Tuur

Erleuchteter

Beiträge: 3 839

Wohnort: Netherlands

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

  • Nachricht senden

2

Mittwoch, 1. März 2023, 14:50

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*

3

Mittwoch, 1. März 2023, 14:55

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

Fortgeschrittener

Beiträge: 310

Wohnort: Belgium

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

  • Nachricht senden

4

Mittwoch, 1. März 2023, 14:56

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.

5

Mittwoch, 1. März 2023, 15:01

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

Fortgeschrittener

Beiträge: 310

Wohnort: Belgium

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

  • Nachricht senden

6

Mittwoch, 1. März 2023, 15:17

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".

7

Mittwoch, 1. März 2023, 15:21

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

Fortgeschrittener

Beiträge: 310

Wohnort: Belgium

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

  • Nachricht senden

8

Mittwoch, 1. März 2023, 15:26

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:

Quellcode

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

9

Mittwoch, 1. März 2023, 15:26

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

Fortgeschrittener

Beiträge: 310

Wohnort: Belgium

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

  • Nachricht senden

10

Mittwoch, 1. März 2023, 15:39

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

Quellcode

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

I get

Quellcode

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


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

11

Mittwoch, 1. März 2023, 15:57

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

Fortgeschrittener

Beiträge: 310

Wohnort: Belgium

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

  • Nachricht senden

12

Mittwoch, 1. März 2023, 16:13

Good luck!

13

Mittwoch, 1. März 2023, 18:29

Hi,

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

E.g. instead of:

Quellcode

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


try this:

Quellcode

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


Best regards,
Klaus

14

Mittwoch, 1. März 2023, 18:34

Hi,

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

E.g. instead of:

Quellcode

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


try this:

Quellcode

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*