Jump to content

Rotation woes


ItHadToComeToThis
 Share

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

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

Recommended Posts

So,

Havent touched rotations properly in a while, especially since I only recently returned to SL and I need reminding xD

When rotating a linked object I get the local rot and then multiple my angle of turn by the local rot value?

Secondly, what's the best way to rotate over a period of time. Lets say I want a linked child prim door to rotate open, 90 degrees, over two seconds

Edited by ItHadToComeToThis
  • Like 1
Link to comment
Share on other sites

25 minutes ago, ItHadToComeToThis said:

Secondly, what's the best way to rotate over a period of time. Lets say I want a linked child prim door to rotate open, 90 degrees, over two seconds

https://wiki.secondlife.com/wiki/Slerp makes it easy to go between two arbitrary rotations scaled by a time variable.

rotation slerp(rotation a, rotation b, float t) {
   return llAxisAngle2Rot(llRot2Axis(b /= a), t*llRot2Angle(b))*a;
}

default
{
    state_entry()
    {
        rotation start_rotation = llEuler2Rot(<paste start rotation from edit tool>*DEG_TO_RAD);
        rotation dest_rotation = llEuler2Rot(<paste end rotation from edit tool>*DEG_TO_RAD);
        float t;
        float max_t = 2.0; // your time here
        float time_step = 0.1;
        for(t = 0; t <= max_t; t += time_step) {
            llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_ROTATION, slerp(start_rotation, dest_rotation, t/max_t)]);
            llSleep(time_step);
        }
    }
}

Alternatively, without slerp, just compute a rotational increment that gets you where you want to be in the given time, but that could end up drifting and requires more thinking about what axis you're wanting to rotate around, etc., instead of just pasting in the endpoint rotations.

default
{
    state_entry()
    {
        float t;
        float max_t = 2.0;
        float time_step = 0.1;
        rotation increment = llEuler2Rot(<0, 0, 90>*DEG_TO_RAD*(time_step/max_t));
        rotation current_rotation;
        for(t = 0; t < max_t; t += time_step) {
            current_rotation = llGetRot();
            llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_ROTATION, current_rotation * increment]);
            llSleep(time_step);
        }
    }
}

 

  • Thanks 1
Link to comment
Share on other sites

45 minutes ago, Frionil Fang said:

https://wiki.secondlife.com/wiki/Slerp makes it easy to go between two arbitrary rotations scaled by a time variable.

rotation slerp(rotation a, rotation b, float t) {
   return llAxisAngle2Rot(llRot2Axis(b /= a), t*llRot2Angle(b))*a;
}

default
{
    state_entry()
    {
        rotation start_rotation = llEuler2Rot(<paste start rotation from edit tool>*DEG_TO_RAD);
        rotation dest_rotation = llEuler2Rot(<paste end rotation from edit tool>*DEG_TO_RAD);
        float t;
        float max_t = 2.0; // your time here
        float time_step = 0.1;
        for(t = 0; t <= max_t; t += time_step) {
            llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_ROTATION, slerp(start_rotation, dest_rotation, t/max_t)]);
            llSleep(time_step);
        }
    }
}

Alternatively, without slerp, just compute a rotational increment that gets you where you want to be in the given time, but that could end up drifting and requires more thinking about what axis you're wanting to rotate around, etc., instead of just pasting in the endpoint rotations.

default
{
    state_entry()
    {
        float t;
        float max_t = 2.0;
        float time_step = 0.1;
        rotation increment = llEuler2Rot(<0, 0, 90>*DEG_TO_RAD*(time_step/max_t));
        rotation current_rotation;
        for(t = 0; t < max_t; t += time_step) {
            current_rotation = llGetRot();
            llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_ROTATION, current_rotation * increment]);
            llSleep(time_step);
        }
    }
}

 

That is amazing, thank you so much.

  • Like 1
Link to comment
Share on other sites

5 hours ago, ItHadToComeToThis said:

Lets say I want a linked child prim door to rotate open, 90 degrees, over two seconds

I'm fairly sure some 'nice' doors use llTargetOmega in a clever way, but I've never found the motivation to try it for myself. (I presume there might be some fine tuning to get it to look perfect.)

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 442 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...