|
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
|
04-02-2008 20:17
I'm trying to figure out the direction between two locations, ignoring the z component. And I need the direction in terms relative to the prim (or root prim -- should always be the same). This should be simple, but my brain seems to be shutting down. :-/
Thanks!
|
|
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
|
04-02-2008 22:21
Please clarify:
By "direction," do you want a vector or a rotation? Is one of the "two locations" that of the script-bearing prim itself?
|
|
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
|
04-02-2008 22:32
I want a scalar, essentially a compass direction in rads or degrees. One of the locations is indeed that of the object containing the script. The other is that of a linked member. My mind cleared a bit; it's something like this: vec = p2 - p1; vec.z = 0.0; vec = llVecNorm(vec); dir = llAcos(vec.x); if (vec.y < 0) dir = TWO_PI - dir;
The problem I'm having now should be simple: i need it relative, but it's absolute. So, I guess I just need to get the object's rotation, convert to euler, convert that to direction, and subtract. Seems to me there should be a better way, though.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
04-03-2008 00:12
float heading(vector origin, vector destination) { vector delta = destination-origin; return llAtan2(delta.y, delta.x); }
...returns an angle in radians, with 0.0 being due East, pi/2 North, pi West, and 3/2 pi South.
|
|
Kaluura Boa
Polygon Project
Join date: 27 Mar 2007
Posts: 194
|
04-03-2008 19:48
This untested function should do what you want:
float ooRelativeAngle(vector reference, vector other) { vector angle = llRot2Euler(llRotBetween(llVecNorm(other), ZERO_VECTOR)) - llRot2Euler(llRotBetween(llVecNorm(reference), ZERO_VECTOR)); // if (angle.z < 0.0) { angle.z += TWO_PI; } return angle.z; }
In plain English: This function calculates the headings of 2 prims relative to an origin and substracts them to obtain a relative value.
It works 2 ways: You can either provide to this function 2 local positions to calculate the heading of one child prim relative to another or 2 absolute positions.
Note that since the function returns a relative angle, it's normal to have negative values sometimes. If that bothers you, uncomment the line I inserted before the "return". This is however useless, you can use directly any result in any further calculation.
|
|
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
|
04-04-2008 10:38
Thanks Hewee, Kaluura.
Hewee, I like the simplicity of your suggestion.
The only problem now would be getting local positions rather than absolute ones, since the prims in question are unscripted. Doing the math (either way, correcting the angle afterwards or correcting the position beforehand) wouldn't be good because there are a lot of prims to handle. So, I'm using a different method that doesn't depend on relative position.
Actually, it might be a little trickier than just getting local positions. If I understand it, local positions are offsets from the root position, but using the global axes, not the local ones. I could be wrong about that, but it doesn't matter since I can't find a way to get local positions for other pims anyway.
Thanks for the help in any case!
Jeff
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
04-04-2008 11:01
I guess maybe the question is: what do YOU mean by "relative?" Let's drop that word for now and simply ask what it is you need for your application. How are you going to use it?
|
|
Kaluura Boa
Polygon Project
Join date: 27 Mar 2007
Posts: 194
|
Position of an unscripted child prim in one line
04-04-2008 20:05
vector ooChildPos(integer link_number) { return llList2Vector( llGetObjectDetails(llGetLinkKey(link_number), [OBJECT_POS]), 0 ); } Since the routine I gave to you works with absolute positions, that should be enough. To convert into a relative position: (ooChildPos(link_number) - llGetRootPosition()) / llGetRootRotation(); There is always a solution... 
|