Jump to content

llSetKeyFramedMotion and global pos/rot


Snippy Yifu
 Share

You are about to reply to a thread that has been inactive for 3515 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hello

I have a prim being rezzed by a rezzer, and then asked to move around given global coords (calculated from local coords of the rezzer).

I've created this snippet for the moving prim to convert the global coords to keyframed position and rotation.

But something is odd with the rotation. Sometimes (depending of the rezzer's rotation) the moving object ends up upside-down (inverted z- world axis).

 

rotation NormRot(rotation Q)
{
    float MagQ = llSqrt(Q.x*Q.x + Q.y*Q.y +Q.z*Q.z + Q.s*Q.s);
    return <Q.x/MagQ, Q.y/MagQ, Q.z/MagQ, Q.s/MagQ>;
}

uMoveTo(list keyframes)
{
    iTarget = llTarget((vector)llList2String(keyframes, -3), 0.05);
vector offset = llGetPos(); rotation orientation = llGetRot();
vector newFramePos; rotation newFrameRot;
integer i; integer length = llGetListLength(keyframes); for (i = 0; i < length; i += 3) { newFramePos = (vector)llList2String(keyframes, i) - offset; newFrameRot = NormRot((rotation)llList2String(keyframes, i+1)) / orientation; offset += newFramePos; orientation *= newFrameRot; keyframes = llListReplaceList(keyframes, [ newFramePos, newFrameRot, (float)llList2String(keyframes, i+2) ], i, i+2); } llSetKeyframedMotion(keyframes, [ ]); }

 Keyframes is giving as a strided list of strings (position, rotation, time).

I'm clueless with rotations and ends up guessing what to do with them all the time ... so any help would be greatly apreciated :)

 

Thanks

Link to comment
Share on other sites

Try this:

rotation NormRot(rotation Q){    float MagQ = llSqrt(Q.x*Q.x + Q.y*Q.y +Q.z*Q.z + Q.s*Q.s);    return <Q.x/MagQ, Q.y/MagQ, Q.z/MagQ, Q.s/MagQ>;}uMoveTo(list keyframes){    iTarget = llTarget((vector)llList2String(keyframes, -3), 0.05);    vector offset = llGetPos();    rotation orientation = llGetRot();    vector newFramePos;    rotation newFrameRot;    integer i;    integer length = llGetListLength(keyframes);    for (i = 0; i < length; i += 3)    {        newFramePos = (vector)llList2String(keyframes, i) - offset;        newFrameRot = NormRot((rotation)llList2String(keyframes, i+1)) / orientation;        offset = (vector)llList2String(keyframes, i);        orientation = (rotation)llList2String(keyframes, i+1);        keyframes = llListReplaceList(keyframes, [ newFramePos, newFrameRot, (float)llList2String(keyframes, i+2) ], i, i+2);    }    llSetKeyframedMotion(keyframes, [ ]);}

 Your code is changed in the lines in red
This should give you the relative change in position and rotation between keys provided your list holds absolute positions and rotations

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3515 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...