Jump to content

Rotation of Child Prims


xtc4u
 Share

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

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

Recommended Posts

Trying to write a general rotator of child prim routine.  The code below works but only rotates on a single axis whether I pass in x, y or z.  I'm sure it's a matter of basic misunderstanding of rotation but I am stumped.  

Whether I call MoveChildsRot as below I get the same rotation on the Y axis:

MoveChildsRot(10, "x", 2);
llSleep(2);
MoveChildsRot(10, "y", 2);
llSleep(2);
MoveChildsRot(10, "z", 2);

 

 

// calc the rotation
rotation rotAmount ( float amt, string xyz)
{
    vector x_angles = < amt,0,0 >;
    vector y_angles = < 0,amt,0 >;
    vector z_angles = < 0,0,amt >;
    vector angles_in_radians;
        
    if (xyz = "x")
    {
        angles_in_radians = x_angles* DEG_TO_RAD; // Change to Radians
    }
    if (xyz = "y")
    {
        angles_in_radians = y_angles* DEG_TO_RAD; // Change to Radians
    }
    if (xyz = "z")
    {
        angles_in_radians = z_angles* DEG_TO_RAD; // Change to Radians
    }
    if (debug) llOwnerSay("Angle in Radians: " + (string)angles_in_radians);    
    return llEuler2Rot ( angles_in_radians ); // Change to a Rotation
}

// Rotate a child prim 
//  nAmount: number of degrees to rotate (i.e 10, -10)
//  str_xyz: axis to rotate (i.e. "x", "y", "z")
//  nun: child prim number
MoveChildsRot(integer nAmount, string str_xyz, integer num)
{
    // rotate a child prim    
    list        lRot = llGetLinkPrimitiveParams(num, [PRIM_ROT_LOCAL]);
    rotation    localRot = llList2Rot(lRot, 0); // current Rot
    rotation  deltaRot;

    if (debug) llOwnerSay( (string)nAmount);    
    if (debug) llOwnerSay("xyz: " + str_xyz + " " +  (string)localRot);
    
    deltaRot = rotAmount ((float)nAmount,str_xyz) ;
    
    llSleep(.5);
    
    if (debug) llOwnerSay("xyz2: " + str_xyz + " Delta: " + (string)deltaRot);
    
    llSetLinkPrimitiveParamsFast(num , [ PRIM_ROT_LOCAL, (localRot * deltaRot)] ) ;
        
}

 

Link to comment
Share on other sites

Two mistakes, one fatal:

(1) You are using "=" (assignment) in the if statements in the rotAmount function, instead of "==" (equivalence), and

(2) Your second and third if tests should be else if tests.

rotation rotAmount ( float amt, string xyz){    vector x_angles = < amt,0,0 >;    vector y_angles = < 0,amt,0 >;    vector z_angles = < 0,0,amt >;    vector angles_in_radians;            if (xyz == "x")    {        angles_in_radians = x_angles* DEG_TO_RAD; // Change to Radians    }   else if (xyz == "y")    {        angles_in_radians = y_angles* DEG_TO_RAD; // Change to Radians    }    else if (xyz == "z")    {        angles_in_radians = z_angles* DEG_TO_RAD; // Change to Radians    }    if (debug) llOwnerSay("Angle in Radians: " + (string)angles_in_radians);        return llEuler2Rot ( angles_in_radians ); // Change to a Rotation}
  • Like 1
Link to comment
Share on other sites

Wow, talk about a big time rookie mistake.  I have stared at this code for you can't imagine how long, I really should have spotted that.  Thanks much.

As to the if vs. if else.  I agree I should have used the if else's but wouldn't it have worked even with just the if's.  I'm assuming it would have but would be less efficient code.  I guess that is what you meant by one fatal and one "not fatal".

Again thank you.

Link to comment
Share on other sites

OK here is the final version, tightened up a bit and only one function.  Thanks for the help and second set of eyes. Note it does not check if the prim number is valid.

 

// Rotate a child prim //   degrees: number of degrees to rotate (i.e 10, -10)//       xyz: axis to rotate (i.e. "x", "y", "z")//  prim_nun: child prim numberMoveChildsRot(float degrees, string xyz, integer prim_num){      list lRot = llGetLinkPrimitiveParams(prim_num, [PRIM_ROT_LOCAL]);    vector angles_in_radians;            if (xyz == "x") {        angles_in_radians = < degrees,0,0 > * DEG_TO_RAD;     } else if (xyz == "y") {        angles_in_radians = < 0,degrees,0 > * DEG_TO_RAD;     } else if (xyz == "z") {        angles_in_radians = < 0,0,degrees > * DEG_TO_RAD; }    // rotate the child prim      llSetLinkPrimitiveParamsFast(prim_num ,         [ PRIM_ROT_LOCAL,(llList2Rot(lRot, 0) * llEuler2Rot ( angles_in_radians ))] ) ;       }

 

Link to comment
Share on other sites

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