Jump to content

Basic HUD Local Rotation problems


Bezilon Kasei
 Share

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

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

Recommended Posts

Hey I was just wondering why this function doesn't rotate the linked prims in my HUD. The link numbers are fine and I followed the instructions on the wiki on how to rotate something with a desired angle. I even tried to give it my angles that I looked up in the build window, but it only nudges a tiny little bit and I don't really understand why. Please help!

 integer ColorMenu() {
    rotation on = llEuler2Rot(<0,0,90.0>*DEG_TO_RAD);
    rotation off = llEuler2Rot(<0,0,-90.0>*DEG_TO_RAD);

    if (colormenu) {
        llSetLinkPrimitiveParams(3,[PRIM_ROT_LOCAL,(llGetLocalRot()*off)]);
        llSetLinkPrimitiveParams(4,[PRIM_ROT_LOCAL,(llGetLocalRot()*off)]);
        llSetLinkPrimitiveParams(5,[PRIM_ROT_LOCAL,(llGetLocalRot()*off)]);
        colormenu = 0;
    }
    else {
        llSetLinkPrimitiveParams(3,[PRIM_ROT_LOCAL,(llGetLocalRot()*on)]);
        llSetLinkPrimitiveParams(4,[PRIM_ROT_LOCAL,(llGetLocalRot()*on)]);
        llSetLinkPrimitiveParams(5,[PRIM_ROT_LOCAL,(llGetLocalRot()*on)]);
        colormenu = 1;
    };
    
    return 0;
}

 

Link to comment
Share on other sites

Did you try:

integer ColorMenu() {    rotation on = llEuler2Rot(<0,0,90.0>*DEG_TO_RAD);    rotation off = llEuler2Rot(<0,0,-90.0>*DEG_TO_RAD);    if (colormenu) {        llSetLinkPrimitiveParams(3,[PRIM_ROT_LOCAL,off]);        llSetLinkPrimitiveParams(4,[PRIM_ROT_LOCAL,off]);        llSetLinkPrimitiveParams(5,[PRIM_ROT_LOCAL,off]);        colormenu = 0;    }    else {        llSetLinkPrimitiveParams(3,[PRIM_ROT_LOCAL,on]);        llSetLinkPrimitiveParams(4,[PRIM_ROT_LOCAL,on]);        llSetLinkPrimitiveParams(5,[PRIM_ROT_LOCAL,on]);        colormenu = 1;    }    return 0;}

 I can not know what you want but this code will set the child prim rotation relative to the root by on respectively off

Link to comment
Share on other sites

EDIT: You may want to replace llSetLinkPrimitiveParams() with llSetLinkPrimitiveParamsFast() if the 0.2 sec. delay freezes your script at the wrong moment.

From what I see in your script, it looks like you are trying to rotate child prims a quarter of turn if colormenu is set and to rotate them back otherwise. Your scripts fails for two reasons:

First, llGetLocalRot() returns the local rotation of the prim in which it is called from. I assume your script is in the root... which does not rotate. So...

Second, to add more rotation to a current one, the right "formula" is more_rot * current_rot.

And third, not a reason for failure but a question that crossed my mind. The way your script is written, the same rotation is applied to the 3 child prims. Is that what you want?

If yes, here is what I would write:

integer colormenu = TRUE;integer ColorMenu(){    colormenu = !colormenu; // if (colormenu == 1) { colormenu = 0; } else if (colormenu == 0) { colormenu = 1; }    rotation quarter_rot = llEuler2Rot(<0.0, 0.0, PI_BY_TWO>); // 90 * DEG_TO_RAD == PI_BY_TWO    rotation child_rot = llList2Rot(llGetLinkPrimitiveParams(3, [PRIM_ROT_LOCAL]), 0);    list params;    if (colormenu) { params = [PRIM_ROT_LOCAL, quarter_rot * child_rot]; } // Turn one way...    else { params = [PRIM_ROT_LOCAL, child_rot / quarter_rot]; } // ...or the other way.    llSetLinkPrimitiveParams(3, params + [PRIM_LINK_TARGET, 4] + params + [PRIM_LINK_TARGET, 5] + params);    // Synchronized rotation    return 0; // Do you really need to return something?}default{    touch_start(integer num)    {        ColorMenu();    }}

If the prims do not turn the right way, just move the line colormenu = !colormenu; to the end of the function (before the return).

If the child prims all have different original rotations, things are a bit different:

integer colormenu = TRUE;ColorMenu(){    colormenu = !colormenu;    rotation quarter_rot = llEuler2Rot(<0.0, 0.0, PI_BY_TWO>);    list child_rot = llGetLinkPrimitiveParams(3, [PRIM_ROT_LOCAL,                                             PRIM_LINK_TARGET, 4, PRIM_ROT_LOCAL,                                             PRIM_LINK_TARGET, 5, PRIM_ROT_LOCAL]);    list params;    integer i = 0;    for (; i < 3; ++i) // 3 prims    {        if (i) { params += [PRIM_LINK_TARGET, i + 3]; } // Link numbers: 3, 4, 5        if (colormenu)        {            params += [PRIM_ROT_LOCAL, quarter_rot * llList2Rot(child_rot, i)]; // Turn one way...        }        else        {            params += [PRIM_ROT_LOCAL, llList2Rot(child_rot, i) / quarter_rot]; // ...or the other way.        }    }    llSetLinkPrimitiveParams(3, params);}default{    touch_start(integer num)    {        ColorMenu();    }}

 (I removed the return which seems very superfluous to me.)

Both scripts tested in-world. They work whatever the rotation of the root prim.

Link to comment
Share on other sites

Thanks for both of you! The only problem I had was that I missed that the local rotation is respective to the root prim. Thus I'm not in need of a universal code, but thank you for taking your time and explaining it to me. The return value is not necessary I know, but it's still not a void function and it's just a habbit, casue 0 means that the function works well.

Link to comment
Share on other sites

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