llGetLocalPos... Having a problem
|
|
Jon Brendel
Registered User
Join date: 13 Oct 2006
Posts: 7
|
11-03-2006 16:45
I'm trying to convert world coordinates to local coordinates but i've run into some problems..
I have a child prim in a linkset. The child prim has a simple script that uses llSay to say its GetLocalPos(). I've noticed that while it is a child in a lik set, that it returns the offset from the root prim. This is expected. However, the GetLocalPos return a different vector depending on how the root prim (or rather the entire linked object) is rotated. How can I convert world coordinates to local ones, taking into account the rotation of the object I'm going to be linking to?
I have tried vector parentPos - vector childPosBeforeUnlinking. This should = the offset the child will be when linked - and it does as long as the rotation of the root of the prim set is set to 0,0,0. How do I take these rotations into account?
thanks
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
11-03-2006 17:58
Did you try rotating that vector by the rotation of the root prim? You can do newVector = oldVector * desiredRotation in LSL. As long as the vector comes before the * and the rotation comes after it, the result will be the vector rotated by that amount. So that might give you what you need.
|
|
Jon Brendel
Registered User
Join date: 13 Oct 2006
Posts: 7
|
11-03-2006 18:54
Thanks Ziggy - i will look into it when I get off of work.. I tried somethign similar, but was unable to multiply a position vector by a rotation... (type mismatch).. Should I convert the quaternion rotation to a euller then try to multiply the position by it?
thanks again,
Jon
|
|
Jon Brendel
Registered User
Join date: 13 Oct 2006
Posts: 7
|
11-03-2006 18:58
also, if you could help with a short code snippet - what i'm picturing you saying is:\
vector unlinkedPosition=llGetLocalPos(); //then i link the object to a primset vector linkedPosition=(llGetRootPosition-unlinkedPosition) * llGetRootRotation();
is this what you are saying?
thanks again, Jon
|
|
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
|
11-03-2006 20:58
From: Jon Brendel I have a child prim in a linkset. The child prim has a simple script that uses llSay to say its GetLocalPos(). I've noticed that while it is a child in a lik set, that it returns the offset from the root prim. This is expected. However, the GetLocalPos return a different vector depending on how the root prim (or rather the entire linked object) is rotated. How can I convert world coordinates to local ones, taking into account the rotation of the object I'm going to be linking to I don't quite understand what you're trying to achieve. The llGetLocalPos() returns the same vector for child in the linkset once the child is actually linked, no matter what the rotation of root prim is, so what you describe (results of llGetLocalPos() in linkset varying depending on rotation of root) sounds strange, at least..? ^^;;
|
|
Jon Brendel
Registered User
Join date: 13 Oct 2006
Posts: 7
|
11-03-2006 21:39
I can show you how to reproduce this.. I'm not sure if its a bug myself
First, make a "house" (a cube prim sized to 10x10x10) In the house prim, ceate the script:
default(){ touch_start(integer totalNum){ llSay(0,"House region coords: " + (string) llGetLocalPos());
}
}
Next, Make a door prim out of a cube and size it to somewhat resemble a door. Put the above script into this door prim also.
Now, touch the house, it will show its regional coords.. Then touch the door, it will show its regional coords... Now, link the door to the house (so that the house is the root prim) Now, touch the door again - it will llSay its local offset from root.
You will notice that the unlinked door vector, minus the house vector will equal the linked door vector (as it should.
Now, unlink the door and house. Rotate the house to <0,270,180> link the door again touch the door you will notice that the local offset for the door has changed from when the house was not rotated.
This implies that either 1) there is a bug, or 2) the rotation of the root prim is supposed to effect thelocal position offset of the child prims.
If the case is 1 - that sucks I really need this to work if the case is 2 - I guess I need to learn how to effectively convert a child prims local offset coords to regional coords.
thanks for any help!
|
|
Seifert Surface
Mathematician
Join date: 14 Jun 2005
Posts: 912
|
11-04-2006 02:02
child_global_pos = child_local_pos * root_rotation;
so:
child_local_pos = child_global_pos / root_rotation;
I think you may have been trying to multiply in the wrong order.
_____________________
-Seifert Surface 2G!tGLf 2nLt9cG
|
|
Jon Brendel
Registered User
Join date: 13 Oct 2006
Posts: 7
|
11-04-2006 04:08
thanks, but that didn't work either 
|
|
Jon Brendel
Registered User
Join date: 13 Oct 2006
Posts: 7
|
11-04-2006 05:19
Ok, after 2 days of trial and error, I made the following functions which work correctly! Maybe it will help somebody else. //------------------------------------------------------- //GLOBAL TO LOCAL AND LOCAL TO GLOBAL POSITION TRANSFORMS //-------------------------------------------------------
//This function returns a position vector of a linked //prim in global coordinates using the below formula: //GlobalPos=(childPos*rootRot)+rootPos vector GlobalPosFromLocalPos(vector childPos, vector rootPos, rotation rootRot){ return (childPos*rootRot)+rootPos; }
//This function returns the theoretical position an unlinked object // would be in local coordinates if it were linked to a linkset. //WouldBeLocalPos=unlinkedObjPos-(rootPosOfLinkSet/rootRotOfLinkSet) vector LocalPosFromGlobalPos(vector unlinkedObjPos, vector linksetRootPos, rotation linksetRootRot){
return unlinkedObjPos-(linksetRootPos/linksetRootRot); }
|
|
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
|
11-04-2006 08:29
From: Jon Brendel You will notice that the unlinked door vector, minus the house vector will equal the linked door vector (as it should.
Now, unlink the door and house. Rotate the house to <0,270,180> link the door again touch the door you will notice that the local offset for the door has changed from when the house was not rotated.
This implies that either 1) there is a bug, or 2) the rotation of the root prim is supposed to effect thelocal position offset of the child prims. Ahh this is quite normal, then. The local offsets are provided in local coordinate system of the root prim. So what you describe is, simplifying it, a difference between say the door being linked to front of house (when the root is not rotated) and the same door being linked to side of house (when the root is rotated) ... quite obviously this results in two different local offsets, but each of these offsets will remain consistent once the door is actually linked with the house and won't change no matter how the root prim is then rotated.
|
|
Aakanaar LaSalle
Registered User
Join date: 1 Sep 2006
Posts: 132
|
11-04-2006 09:55
That is correct. When you rotate the root prim without moving the child prim, and then relink, the child prim is in a new vector in relation to the root prim, even though it is in the same place globally.
the llGetLocalPos() function when applied to a child prim in a link set will return the position "in relation" to the root prim.
To get the global position, you need to multiply the offset by the root rotation and add to the root vector.
Try this.
Create the root prim and child prim and link them together. In the child prim add to the script
vector childpos = (llGetLocalPos * llGetRootRotation) + llGetRootPosition;
This will always return the childs position in global coordinates. You can unlink to see for yourself.
|
|
Jon Brendel
Registered User
Join date: 13 Oct 2006
Posts: 7
|
11-05-2006 04:27
ok on to the next problem
Now i'm trying to figure out formulas to convert a local rotation to a global rotaion, and a global rotation to a local rotation
this seems even harder than the problems i had figuring out transforming positions!
Anybody have any insight?
thanks
|
|
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
|
11-05-2006 07:53
From: Jon Brendel Now i'm trying to figure out formulas to convert a local rotation to a global rotaion, and a global rotation to a local rotation Global rotation of child prim is a combination of its local rotation and the rotation of parent prim: rotation child_global = llGetLocalRot() * llGetRootRotation(); ... local rotation of the prim after it's linked with another is its original rotation in world space 'minus' rotation of its new parent: rotation child_local = llGetRot() / parent's_rotation;
|
|
Tracey Luke
Registered User
Join date: 14 Oct 2006
Posts: 6
|
11-05-2006 12:37
thanks Johanna - just one question, you used * and / in the formaulats, but said combine and subtract.. do I use + and - or * and /?
thanks again
|
|
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
|
11-05-2006 14:21
Ack sorry, the operators are * and / ... they are technically multiplication and multiplication by inverse of the supplied quaternion if i recall right, i just use 'combine' and 'subtract' out of habit because that's practical effect of them... the * one spins the supplied rotation further, while the / spins by the given amount in the reverse so to speak, canceling out the effect... if that makes any sense ^^;;
|