Jump to content

Clockwise rotation of a prim via llSetLinkPrimitiveParams


Barry Moody
 Share

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

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

Recommended Posts

I'm working on a script in a set of linked prims that rotates a child prim 180 degress around the z-axis when the root prim is touched. This is so a user can view the front and back of an item on display. A message is sent from the root prim to the first child prim in the link set An if/else statement checks which way the prim is "facing" ("front" or "back" views) and swaps between two vector values according to which way it is currently facing:

vector front = <0.0, 180.0, 0.0>;
vector back = <180.0, 0.0, 0.0>;
vector facing = front;

default
{
    state_entry()
    {
    }

    link_message(integer sender_num, integer num, string msg, key id)
    {
        llSay(0, msg);
        
        if(facing == front)
        {
            llSay(0, "Show Back");
            facing = back;
        }else{
            llSay(0, "Show Front");
            facing = front;
        }
        
        vector rads = facing * DEG_TO_RAD;       
        rotation rot = llEuler2Rot(rads);        
        llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_ROTATION, rot]);
        
    }
}

The first touch (rotate from "front" view to "back" view) works fine as it rotates the prim clockwise. When the prim is touched again, (rotate from "back" view to "front" view) it rotates back to its original position, but does so in a counter-clockwise direction.

Is there a way to force the second touch to rotate the prim clockwise like the first touch? Is llSetLinkPrimitveParams the rifght function to do this with? Please be patient with the above code, this is my first script in three years.

 

Link to comment
Share on other sites

You should be able to force it by the sign on the rotation, but if not, one way to be sure which direction you turn is to do it in two or more steps.

llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_ROTATION, llEuler2Rot(<0.0,0.0,-PI/2>)*llGetRot()]);  // 90 degrees clockwisellSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_ROTATION, llEuler2Rot(<0.0,0.0,-PI/2>)*llGetRot()]);  // Another 90 degrees clockwise

Or

 

llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_ROTATION, llEuler2Rot(<0.0,0.0,PI/2>)*llGetRot()]);  // 90 degrees anti-clockwisellSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_ROTATION, llEuler2Rot(<0.0,0.0,PI/2>)*llGetRot()]);  // Another 90 degrees anti-clockwise

 

  • Like 1
Link to comment
Share on other sites

So a couple of questions about this:

  1. Why use link messages to d this instead of llSetLinkPrimitiveParamsFast?  There may be good reasons for this, so a minor concern.
  2. If you are rotating by PI radians (which is 180 degrees) then you can always use current local rotation * llEuler2Rot (<0., 0., PI>) to spin it half way around (assuming the prim is still aligned with the world)
  3. If you are truly rotating by pi radians (180 degrees), it doesn't make a difference whether you rotate clockwise or counterclockwise, although admittedly sometimes the graphics speed can catch it in mid-turn and make it look like it's animating in a particular direction.

I only mention 3 because sometimes we make things harder on ourselves than necessary :)


And LOCAL_ROT (and LOCAL_POS) are your friend when moving/rotating around children prims! :)

Link to comment
Share on other sites

Yup.  I agree that using a single script and SLPPF is often preferable to using a cloud of many linked scripts.  I'm assuming that the OP either (1) has other things going on that make linked scripts preferable or (2) is a new scripter who is experimenting with link messages.  So yeah, minor concern.

As far as rotation is concerned, it shouldn't matter whether you rotate in a local or a region framework, as long as you get the math right. You are correct, though, that what I wrote ...

llEuler2Rot(<0.0,0.0,-PI/2>)*llGetRot()

is only correct if the Z-axis of the prim in question points in the same direction as the Z-axis of the root. Otherwise, you'd have to use

rotation LRot = llList2Rot(llGetLinkPrimitiveParams(LINK_THIS,[PRIM_ROT_LOCAL])),0);

and then apply that instead of llGetRot().  

Link to comment
Share on other sites

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