User:Void Singer/Rotations
Jump to navigation
Jump to search
Common Rotation Tasks Simplified
These are a few simplifications of common rotation tasks for those (like me) who get a bit glassy eyed and overwhelmed reading the 'official' version...
- forward rotation vs reverse rotation
- same as counter-clockwise vs clockwise (viewed from the positive end of the axis)
- same as left turn vs right turn (viewed as if standing in the axis w/ head at positive end)
//-- 2 ways to reverse rotation //-- use negative numbers in original variable, good for rotation that won't change vector vgVecLeftRotation = <.0, .0, 90.0>; //-- left 90 degrees around z-axis vector vgVecRightRotation = <.0, .0, -90.0>; //-- right 90 degrees around z-axis //-- use quaternion inversion, good for rotations that will reverse dynamically vector vgVecDegreesRotation = <.0, .0, 90>; //-- left 90 degrees around the z-axis rotation vgRotConvertedDegrees = llEuler2Rot( vgVecDegreeRotation * DEG_TO_RAD ); //-- still left vgRotConvertedDegrees.s *= -1; //-- reverses the rotation direction each time called
- rotating in global axis vs local
- Global axis is the world, up, down, north, east, south, west
- Local axis is the object, top, bottom, left-side, right-side, front-side, back-side.. imagine writing on a cardboard box
//-- to rotate around the global axis (think stationary carousel) llSetRot( llGetLocalRot() * vgRotConvertedDegrees ); //-- to rotate around the local axis (think spinning tilted top) just reverse the order llSetRot( vgRotConvertedDegrees * llGetRot() );
- roatating a given point to match objects position/rotation
- Do this to find where a point is in relation to an object (good for rezzors)
- for instance if you want to know the point 1m from the top of an object, and 2m right..
vector vVecOffset = <2.0, .0, 1.0>; //-- even after rotating your object this will give the point in relation to it's new rotation vector vVecCurrentOffset = llGetPos() + vVecOffset * llGetLocalRot();
- rotatating an objects POSITION around a given offset point
- same idea as planets orbiting the sun
vector vVecOffset = <.0, .0, 1.0>; //-- the point we are rotating around in relation to our object vector vgVecArc = <.0, .0, 60.0>; //-- how far around the circle to travel each move rotation vgRotArc = llEuler2Rot( vgVecArc * DEG_TO_RAD ); //-- notice you have to move AND rotate, or else the new //-- position becomes a diagonal line instead of a circle llSetPrimitiveParams( [PRIM_POSITION, llGetPos() + (vVecOffset - vVecOffset * vRotArc) * llGetLocalRot(), PRIM_ROTATION, vRotArc * llGetLocalRot] );
- Warnings:
- do NOT use rotation division to reverse direction
- llSetPrimitiveParams & llSetRot do not work correctly for rotations in child prims
//-- this might work in some cases, but fails in most, so don't use it! llSetRot( llGetRot() / vgRotConvertedDegrees ); //-- this works in a child prim llSetLocalRot( vgRotConvertedDegrees * llGetLocalRot() ); //-- these work incorrectly in child prims llSetRot( vgRotConvertedDegrees * llGetLocalRot() ); llSetPrimitiveParams( [PRIM_ROTATION, vgRotConvertedDegrees * llGetLocalRot()] ); //-- presumably this works incorrectly as well llSetLinkPrimitiveParams( 2, [PRIM_ROTATION, vgRotConvertedDegrees * llGetLocalRot()] ); //-- see jira article SVC-93 for details + a workaround if you need to use llSetPrimitiveParams
Comments
Feel free to leave me a note on my User Talk page.