Difference between revisions of "GetRootLocalPos"

From Second Life Wiki
Jump to navigation Jump to search
m
(bad assumption i think, llGetRootPosition i do not think includes the attachments local position (since the rot does not), pretty sure of this because attachment pos doesn't effect rez offset.)
Line 8: Line 8:


Something like this should work...
Something like this should work...
<lsl>list offsets = [ 0, <0.5, 0.5, 0.5, 0.5>, <0.0, 0.0, 0.70710678118654752440084436210485, 0.70710678118654752440084436210485>, 0, 0, 0, 0, 0, 0, <-0.5, -0.5, 0.5, 0.5> ];
<lsl>//list offsets = [ 0, <0.5, 0.5, 0.5, 0.5>, <0.0, 0.0, 0.70710678118654752440084436210485, 0.70710678118654752440084436210485>, 0, 0, 0, 0, 0, 0, <-0.5, -0.5, 0.5, 0.5> ];


vector GetRootLocalPos()
vector GetRootLocalPos()
{
{
    if(llGetLinkNumber() <= LINK_ROOT)
        return llGetLocalPos();
     integer point = llGetAttached();
     integer point = llGetAttached();
     if(point)
     if(point)// (((child-global - avatar-position) / rot-avatar) / rot-root) (/ attach-offset?) - child-local == root-local
    {
         return (((llGetPos() - llGetRootPosition()) / llGetRootRotation()) / GetRootLocalRot()) - llGetLocalPos();
        list avatar = llGetObjectDetails( llGetOwner(), [OBJECT_POS, OBJECT_ROT]);
         return ((llList2Vector(avatar, 0) - llGetRootPosition()) / llList2Rot(avatar, 1)) / llList2Rot(offsets, point);
    }
     return llGetRootPosition();
     return llGetRootPosition();
}
}
Line 23: Line 22:
vector GetRootLocalRot()
vector GetRootLocalRot()
{
{
     integer point = llGetAttached();
     return return llList2Rot(llGetLinkPrimitiveParams(!!llGetLinkNumber(), [PRIM_ROT_LOCAL]), 0);;
    rotation root = llGetRootRotation();
    if(point)
        return ((root / llList2Rot(llGetObjectDetails( llGetOwner(), [OBJECT_ROT]), 0)) / llList2Rot(offsets, point);
    return root;
}</lsl>
}</lsl>
-- '''[[User:Strife_Onizuka|Strife]]''' <sup><small>([[User talk:Strife_Onizuka|talk]]|[[Special:Contributions/Strife_Onizuka|contribs]])</small></sup> 08:35, 6 May 2010 (UTC)
-- '''[[User:Strife_Onizuka|Strife]]''' <sup><small>([[User talk:Strife_Onizuka|talk]]|[[Special:Contributions/Strife_Onizuka|contribs]])</small></sup> 08:35, 6 May 2010 (UTC)

Revision as of 21:18, 29 October 2010

While writing another function, I got thinking about the whole attachment local root rotation problem (you need to know the local rotation of the root prim in an attachment so you can use PRIM_ROTATION). I came to the conclusion with all the new(ish) functions, it is now possible to actually work this out.

  1. You know the position and rotation of the avatar, thanks to llGetObjectDetails.
  2. You know the attach point (llGetAttached)
  3. You know the combined rotation and position (llGetRootRotation & llGetRootPosition)

It should just be a matter of subtracting the one from the other and canceling out the attach point offsets.

Something like this should work... <lsl>//list offsets = [ 0, <0.5, 0.5, 0.5, 0.5>, <0.0, 0.0, 0.70710678118654752440084436210485, 0.70710678118654752440084436210485>, 0, 0, 0, 0, 0, 0, <-0.5, -0.5, 0.5, 0.5> ];

vector GetRootLocalPos() {

   if(llGetLinkNumber() <= LINK_ROOT)
       return llGetLocalPos();
   integer point = llGetAttached();
   if(point)// (((child-global - avatar-position) / rot-avatar) / rot-root) (/ attach-offset?) - child-local == root-local
       return (((llGetPos() - llGetRootPosition()) / llGetRootRotation()) / GetRootLocalRot()) - llGetLocalPos();
   return llGetRootPosition();

}

vector GetRootLocalRot() {

   return return llList2Rot(llGetLinkPrimitiveParams(!!llGetLinkNumber(), [PRIM_ROT_LOCAL]), 0);;

}</lsl> -- Strife (talk|contribs) 08:35, 6 May 2010 (UTC)