Jump to content

Rotation woahs


VirtualKitten
 Share

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

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

Recommended Posts

I have this script which kind of works but it rotates the child object right round first and am unsure why as otherwise if it  didnt it would be ok. I want to just rotate it around Y

list p;
float rotClickAngle = 10;
float height=0;
rotate(integer link) {
    list L = llGetLinkPrimitiveParams(link,[PRIM_ROT_LOCAL, PRIM_POS_LOCAL]);
    rotation rotRoot2Axis = llList2Rot(L,0);
    vector posRoot2Axis = llList2Vector(L,1);
    
    vector axisAxis=<0,1,0>*rotRoot2Axis;
    rotation rotClick_inRootFrame = llAxisAngle2Rot(axisAxis, rotClickAngle *DEG_TO_RAD);
    // for body.
    L = llGetLinkPrimitiveParams(1,[PRIM_ROT_LOCAL, PRIM_POS_LOCAL]);
    rotation rotRoot2Body = llList2Rot(L,0);
    vector posRoot2Body = llList2Vector(L,1);
    rotation newrotRoot2Body = rotRoot2Body * rotClick_inRootFrame;
    vector offsetBody_inRootFrame = posRoot2Body - posRoot2Axis;
    vector newoffsetBody_inRootFrame = offsetBody_inRootFrame* rotClick_inRootFrame;
    llSetLinkPrimitiveParamsFast(link,[PRIM_ROT_LOCAL,newrotRoot2Body,PRIM_POS_LOCAL, posRoot2Axis + newoffsetBody_inRootFrame]);
    
}

default
{
    
    touch_start(integer total_number)
    {
        integer touchFace = llDetectedTouchFace(0);
        vector  touchST   = llDetectedTouchST(0);
        integer link    = llDetectedLinkNumber(0);
        height=0;
        rotClickAngle = 10;
        rotate(link);
      }
     touch_end(integer total_number) {
         integer touchFace = llDetectedTouchFace(0);
         vector  touchST   = llDetectedTouchST(0);
         integer link    = llDetectedLinkNumber(0);    
         height=0;
       rotClickAngle = -10;
         rotate(link);
     }
    
}

 

 

Edited by VirtualKitten
Link to comment
Share on other sites

It would help if you were more clear about what you want it to do; you have a lot of weird irrelevant stuff in the script.

float rotClickAngle = 10;

default
{   state_entry()
    {   rotClickAngle*=DEG_TO_RAD;
    }
    
    touch_start(integer total_number)
    {   integer link    = llDetectedLinkNumber(0);
        rotation rot = llList2Rot(llGetLinkPrimitiveParams(link,[PRIM_ROT_LOCAL]),0);
        rotation apply = llAxisAngle2Rot(<0,1,0>,rotClickAngle);
        llSetLinkPrimitiveParams(link,[PRIM_ROT_LOCAL,apply*rot]); // reverse the order of apply and rot to use root axes instead of link axes.

    }
    touch_end(integer total_number)
    {   integer link    = llDetectedLinkNumber(0);    
        rotation rot = llList2Rot(llGetLinkPrimitiveParams(link,[PRIM_ROT_LOCAL]),0);
        rotation apply = llAxisAngle2Rot(<0,-1,0>,rotClickAngle); // use negative axis for reverse.
        llSetLinkPrimitiveParams(link,[PRIM_ROT_LOCAL,apply*rot]); // reverse the order of apply and rot to use root axes instead of link axes.
    }
}

 

  • Like 1
Link to comment
Share on other sites

20 hours ago, Quistess Alpha said:

you have a lot of weird irrelevant stuff in the script.

No! Surely not!

 

Seriously though I remember ages ago reading that rotations attempt to find the shortest path, but from my own experiences moving the Y-axis will often also alter the other two axis values. The order in which you alter the three axes can be significant. As an experiment, try rezzing an object that has values already in the three fields, then rezz a prim, and set the same values into the X and Z fields, then alter the Y value appropriately, and it frequently changes the X and Z values as a result. 

I am starting to think that you need to be a witch to cope with SL rotations. (Not looking at Tessa, mind you, I was thinking more of Grandma Bates).

Link to comment
Share on other sites

4 hours ago, Profaitchikenz Haiku said:

moving the Y-axis will often also alter the other two axis values.

That's (more-or-less) a result of the 'gimbal lock' problem with euler-vectors; there are multiple values of x,y,z that correspond to the same orientation, and converting between them is, non-intuitive. It's even less intuitive that Linden-euler-vectors are not in the relatively easy to conceptualize pitch-yaw-roll format. If you wrap your head around axis-angle form, quaternions are (IHMO) actually easier to reason about. I've heard a 'orientation mixing' mental model can also be useful:

 

Link to comment
Share on other sites

18 hours ago, Quistess Alpha said:

If you wrap your head around axis-angle form, quaternions are (IHMO) actually easier to reason about.

It's a shame the build floater values are in Euler form in that case. I would find it easier to understand the way the three components varied with rotation if those values were the ones displayed. I made a rotation visualiser some time ago with hovertext showing the Euler degrees and quaternian radian values, but it was a bit clumsy to alter in order to watch those transitions. As you say, there is a gimbal effect where X and/or Z values snap through 180 degrees with the variations in the Y axis. That is why I tend to view Y as the governing one of the three.

Link to comment
Share on other sites

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