- Joined
- Sep 20, 2018
- Messages
- 3,901
((This function is ripped and derived from a post by someone familiar to many oldbies here, but I forgot who and I didn’t carry the attribution forward. I’m sorry, I didn’t expect the code to survive in nearly it’s original form))
Offset Rotation uses this function, which takes two vector values representing a Euler rotation and a positional offset:
Where both rotation and offset are expressed as vectors,and have two zero values and one non-zero value, and an object is a single prim whose size is one meter cubed,
and where a rotation constant for each slot is expressed as a 360 degree rotation, +/-:
and an offset is ½ the scalar value of the prim for the respective XYZ value, +/-:
And any reference to prim also applies to Meshes:
Findings:
Offset Rotation uses this function, which takes two vector values representing a Euler rotation and a positional offset:
Code:
pOffset_rotate(vector vArgRotArc, vector vArgPosOffset)
{
rotation vRotArc = llEuler2Rot(vArgRotArc * DEG_TO_RAD );
vector vPosOffset = vArgPosOffset;
vector vPosRotOffset = vPosOffset * vRotArc;
vector vPosOffsetDiff = vPosOffset - vPosRotOffset;
vector vPosRotDiff = vPosOffsetDiff * llGetRot();
vector vPosNew = llGetPos() + vPosRotDiff;
rotation vRotNew = vRotArc * llGetRot();
llSetPrimitiveParams([
PRIM_POSITION, llGetPos() + (vPosOffset - vPosOffset * vRotArc) * llGetRot(),
PRIM_ROTATION, vRotArc * llGetRot()
]);
}
and where a rotation constant for each slot is expressed as a 360 degree rotation, +/-:
and an offset is ½ the scalar value of the prim for the respective XYZ value, +/-:
And any reference to prim also applies to Meshes:
Findings:
A Rotation governs (1) the magnitude of the rotation, (2) the direction of the rotation, and (3) the axis of rotation:A When the rot and the offset share the same axis, rotation is centered on that axis; it does not rotate on a face
Example: rot = <0.0, 0.0, 30.0>, offset = <0.0, 0.0, 0.5> centers on the Z axis
B A positve offset rotates on the matching + face, a negative offset rotates on the matching – face
Example: <0.0, 0.5, 0.0> spins on the +Y face
Example: <0.0, -0.5, 0.0> spins on the -Y face
C A rot spins on it’s respective axis.
Example: <30.0, 0.0, 0.0> spins on the X axis
Note: because the value is positive, it also spins counter-clockwise
D A positive rot spins counter-clockwise when facing the + face of the prim, and a negative rot spins clockwise when facing the + face of the prim.
Example: <30.0, 0.0, 0.0> spins counter-clockwise on the X axis
Example: <-30.0, 0.0, 0.0> spins clockwise on the X axis
An Offset governs whether the center of rotation is (1) the prim center, or (2) one of it’s faces (aka end points):Magnitude is determined from the absolute value of the rotation
Direction is determined by the +/- attribute of the value: + spins CCW, - spins CW
Axis is determined by whether the rotation value is X (X axis), Y (Y axis), or Z (Z axis)
Example: rot <30.0, 0.0, 0.0> spins 30 degrees CCW on the X axis
Example: rot <0.0, -30.0, 0.0> spins 30 degrees CW on the Y axis
Putting it all together:When a rotation and an offset have a value in the same XYZ slot, the prim rotatation is from the center of the prim around the respective axis
Example: rot <0.0, 0.0, 30.0>, offset <0.0, 0.0, 0.5> spins CCW around the Z axis from the prim’s center
When a rotation and an offset have values in different XYZ slots, the center of rotation is along the face (aka endpoint) of the respective positve or negative face
Example: rot <-30.0, 0.0, 0.0>, offset <0.0, 0.5, 0.0> spins CW around the Y axis with the center of rotation being the positive Y face (aka endpoint) of the prim
- Determine the clockwise/anti-clockwise direction you wish to offset rotate a prim, and along which axis:
- For clockwise, make the value negative
- For anti-clockwise, make the value positive
- Place the value in the respective XYZ slot of the vector to rotate on that axis
- Determine the face (or end point) you wish to offset rotate from:
- The value should be +/- half the scalar value of the respective prim
- The XYZ slot should correspond to the face you want to offset rotate from, when the prim is viewed in edit mode
- In edit mode the arrow direction notates the positive side, and vice-versa
Last edited:


