Don't click here unless you want to be banned.

LSL Wiki : ExampleGetRootRot

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are ia360925.us.archive.org
This function can be used to get the rotation of the root object, even if
called from a child object.

-- Xylor Baysklef

rotation GetRootRot() {
    // If this object is not linked, or if it is the
    // root object, just return llGetRot
    integer LinkNum = llGetLinkNumber();
    
    if (LinkNum == 0 || LinkNum == 1)
        return llGetRot();
        
    // Otherwise take local rotation into account.
    
    // This is the rotation of this object with the
    // root object's rotation as the reference frame.
    rotation LocalRot = llGetLocalRot();
    // This uses the global coord system as the 
    // reference frame.
    rotation GlobalRot = llGetRot();
    
    // Reverse the local rotation, so we can undo it.
    LocalRot.s = -LocalRot.s;
    
    // Convert from local rotation to just root rotation.
    rotation RootRot = LocalRot * GlobalRot;
    
    // Make the sign match (mathematically, this isn't necessary, 
    // but it makes the rotations look the same when printed out).
    RootRot = -RootRot;
    
    return RootRot;
}


Examples
Comments [Hide comments/form]
How, if any, does this differ from llGetRootRotation()? One test I did (in a child prim in a linkset) gave the following results:
GetRootRot()........: <-0.00000, -0.00000, -0.00000, 1.00000>
llGetRootRotation(): <0.00000, 0.00000, 0.00000, 1.00000>
Are the negative zeros a significant difference?
-- adsl-68-94-188-134.dsl.rcsntx.swbell.net (2007-09-18 05:45:50)
Attach a comment to this page: