Rotation woes

Grey Mars

Just Some Guy
Joined
Oct 23, 2018
Messages
149
I've been away from lsl for to long. Well, okay, I was never good at rotations anyway. The issue is this: I have a gear like assembly that needs to make a full revolution on it's z axis. This is a child prim. So far so good. It needs to do it's spin even if the child prim is rotated, with the relative z axis. Still okay... Where my brain utterly burns out and crashes is that it needs to do all this no matter what the root's global rotation is. I'll include the relevant chunks of the script below as I currently have it. Please don't laugh to hard!



rotation g_rXYZS; // The adjustment value
integer g_iPrimGearOpen; // link number of this prim
integer g_iPrimGearRest; // link number of this prim

default {
state_entry() {
vector vXYZ_Angles = <0,0,3.0>; // This defines a 3 degree change on the Z axis
vector vAngles_In_Radians = vXYZ_Angles*DEG_TO_RAD; // Change to radians
g_rXYZS = llEuler2Rot(vAngles_In_Radians); // Convert to a rotation

integer n; // Initialize the counter
integer iLinkCount = llGetNumberOfPrims(); // How many items in the link set?
for (n = 2; n <= iLinkCount; n++) { // Cycle through, skipping root
string sThisElement = llGetLinkName(n); // Get the prim name
if (sThisElement == "Gear_Swing_Low") g_iPrimGearOpen = n; // this link number is this item:
} // End if
} // end state_entry

touch_start(integer s) {

integer x; // set up counter var
rotation rGearCurrentRot; // set up rotation var
for (x = 1; x <= 120; x++) {
rGearCurrentRot = llList2Rot( llGetLinkPrimitiveParams(g_iPrimGearOpen,[PRIM_ROT_LOCAL]), 0 );

llSetLinkPrimitiveParamsFast(g_iPrimGearOpen, [PRIM_ROTATION,g_rXYZS*rGearCurrentRot] );
} // end for

} // end touch_start
} // end default
 

Grey Mars

Just Some Guy
Joined
Oct 23, 2018
Messages
149
So a solution did come up, with the help of better scripters than I. The solution goes in a more elegant direction than I was trying, using PRIM_OMEGA rather than stepping the rotation through a loop. That came with it's own little hick-ups, but was eventually solved. Included below is the corrected and working snippet, just in case someone else ends up in the same predicament.

integer g_iPrimGearOpen; // link number of this prim

default {
state_entry() {
integer n; // Initialize the counter
integer iLinkCount = llGetNumberOfPrims(); // How many items in the link set?
for (n = 2; n <= iLinkCount; n++) { // Cycle through, skipping root
string sThisElement = llGetLinkName(n); // Get the prim name
if (sThisElement == "Gear_Swing_Low") g_iPrimGearOpen = n; // this link number is this item:
} // End if
} // end state_entry

touch_start(integer s) {
rotation lr = llList2Rot(llGetLinkPrimitiveParams(g_iPrimGearOpen,[PRIM_ROT_LOCAL]),0);
llSetLinkPrimitiveParamsFast(g_iPrimGearOpen, [PRIM_OMEGA, llRot2Up(lr),PI*3,1]); // spinrate
llSleep(0.75);
llSetLinkPrimitiveParamsFast(g_iPrimGearOpen, [PRIM_OMEGA, <0,0,0>,0,0,PRIM_ROT_LOCAL,<0,0,0,1>]); // need to sent a reset packet to override omega rot
llSleep(.01);
llSetLinkPrimitiveParamsFast(g_iPrimGearOpen, [PRIM_ROT_LOCAL,lr]);
} // end touch_start
} // end default
 

Innula Zenovka

Nasty Brit
VVO Supporter 🍦🎈👾❤
Joined
Sep 20, 2018
Messages
22,095
SLU Posts
18459
Where my brain utterly burns out and crashes is that it needs to do all this no matter what the root's global rotation is
I know you've found the solution, but I just wanted to highlight that PRIM_ROT_LOCAL was the answer to that one, since it tells the script to use the root prim's frame of rotational reference rather than that of the region, which is what PRIM_ROTATION assumes.

PRIM_ROTATION is also broken, and always has been, in child prims -- see SVC-93 -- and I would advise against using it for anything other than the whole linkset.

need to sent a reset packet to override omega rot
If you mean you want to return the child prim to its original rotation (as opposed simply to stopping it) then doing something that forces the viewer to redraw what it can see will also do the trick -- I change the alpha of some hidden face and then change it back again. That's all it generally needs.
 
Last edited:
  • 1Useful
Reactions: Clara D.

Grey Mars

Just Some Guy
Joined
Oct 23, 2018
Messages
149
I know you've found the solution, but I just wanted to highlight that PRIM_ROT_LOCAL was the answer to that one, since it tells the script to use the root prim's frame of rotational reference rather than that of the region, which is what PRIM_ROTATION assumes.

PRIM_ROTATION is also broken, and always has been, in child prims -- see SVC-93 -- and I would advise against using it for anything other than the whole linkset.
Ooooof. I feel a little better knowing it's not JUST my brain melting while trying every possible permutation and failing radiacally for it to make any sense visually in world.


If you mean you want to return the child prim to its original rotation (as opposed simply to stopping it) then doing something that forces the viewer to redraw what it can see will also do the trick -- I change the alpha of some hidden face and then change it back again. That's all it generally needs.
Yup! That's pretty much what I'm doing, I just cleaned out the various alpha changes to hidden items etc for simplicity. Those at least worked perfectly fine. :p
 
  • 1Like
Reactions: Innula Zenovka