Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How to detect relative position

Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
02-07-2007 08:54
There are two objects. One scans another and I'd like it to know where another is relatively. It is possible that the scanning object rotates around z-axis. Presume if the regeon coordinate and the local were exact same, A<10, 10, 10> would detect B<20, 20, 20> as <10, 10, 10>. But if A turned back 180 digrees, it should be detected as <-10, -10, -10>. What can I do for it?
When the scanning object looks at the north, llDetectedPos(0) - llGetPos() works. But if it looks at the south, it should be llGetPos() - llDetectedPos(0). Should I know which direction it faces in advance or is there better way?

Thanks.
_____________________
:) Seagel Neville :)
Artemis Cain
Take it or Leave it
Join date: 11 Apr 2005
Posts: 116
02-07-2007 09:31
How about this?

You could have object 1 detect its position and save it as a vector.
You could then have it detect object 2's position
subtract object 1's position from object 2's position, and you should get the relative position.

seems like it would work.
I could be wrong, wouldn't be the first time :)

-Artemis
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
Untested answer
02-07-2007 09:33
Thus, the magic of quaternions...

If you have a vector in world coordinates, you can convert it to a vector in local coordinates by dividing it (I think) by the rotation. (A SL rotation is a "quaternion".)

In theory

world vector = local vector * llGetRot()

So, if the local vector is <1,0,0> one meter exactly ahead of the way an object is pointing (x axis), then

world = <1,0,0> * llGetRot()

will give you the equivalent vector in region coordinates.

Likewise

world/llGetRot() = local*llGetRot()/llGetRot = local

Note that I am just trying to help out. i am not actually good at this stuff.

lee
Tiarnalalon Sismondi
Registered User
Join date: 1 Jun 2006
Posts: 402
02-07-2007 09:55
I'm assuming these objects are unlinked, but I would ask if the scenario is feasible to link the 2 objects, if even just to determine the local coords?

If it's feasible to leave them linked at all times, you could just have the child prim call for it's local position directly.

If it's not feasible to leave them linked at all times, but it is feasible to have them link just to calculate, you could script it to link to the parent object, poll it's location, and then unlink to continue on its merry way.

Would probably make the math a little easier :)
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
02-08-2007 07:43
Thank you guys. Especially Lee, your math telling was fantastic. :) I report it works perfectly.
_____________________
:) Seagel Neville :)
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
02-08-2007 09:50
From: Seagel Neville
Thank you guys. Especially Lee, your math telling was fantastic. :) I report it works perfectly.


I am so glad. I was afraid it was wrong 8-)
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
02-08-2007 18:19
Yeah, it works. But it is possible that the scanner objects sometimes turns upside down. Oops, it is probablly problem that I have it detect in perfect comparison. :D Am I too picky? Quaternions always annoy me. :(
_____________________
:) Seagel Neville :)