A rotation is a variable type comprising 4 floats used together as a single item. This data is interpreted as a quaternion. As with vectors, each component can be accessed via '.x', '.y', '.z', and '.s' (

Syntax:

float x = 0.0; float y = 0.0; float z = 0.0; float s = 1.0; rotation rot_a = <0.0, 0.0, 0.0, 1.0>;//copies these values into the respecive values of the rotation. rotation rot_b = <x,y,z,s>;//copies the values of the variable into the rot. rotation rot_c = rot_b;//copies the value of rot_b into rot_c

LSL does do some implicit typecasting but the LSL compiler does not actualy convert types or simplify code; it just makes implicit typecasts explicit. So while

There are a number of ways to visualize an arbitrary rotation in three dimensions. The simplest is to think of a rotation as being equivalent to a set of 3 rotations around the x, y, and z axes (known as the Euler representation). In LSL this can be represented using the vector type, where the x element specifies the roll (angle of rotation around the x-axis), the y element specifies the pitch (angle of rotation around the y-axis), and the z element specifies the yaw (angle of rotation around the z-axis). Also see Banking.

Unfortunately, the Euler representation has drawbacks when it comes to combining rotations (see below). To avoid these problems, LSL represents rotations using mathematical entities known as quaternions, which consists of 4 elements: x, y, z, and s. Note that the x, y, and z elements do

However, you can use rotations without dealing with the individual elements of quaternions. LSL offers library calls that convert between a quaternion and a vector containing the equivalent Euler representation:

Note: LSL expects angles to be specified in terms of radians rather than degrees. A radian is the angle reached if you were to take a string the length of a circle's radius and lay it along the circumference, approximately equal to 57.296 degrees. This ratio means that a full circle, which contains 360 degrees, is equal to 2*PI radians. Similarly, a semicircle of 180 degrees equals PI radians. LSL defines the constants

vector eul = <0,0,45>; //45 degrees around the z-axis, in Euler form eul *= DEG_TO_RAD; //convert to radians rotation quat = llEuler2Rot(eul); //convert to quaternion llSetRot(quat); //rotate the object

LSL also defines the constants

vector x_ninety = <PI_BY_TWO,0,0>; //90 degrees around the x-axis vector y_one_eighty = <0,PI,0>; //180 degrees around the y-axis

LSL defines the constant

Example:

// a rotation of 45 degrees around the x-axis rotation x_45 = llEuler2Rot( <45 * DEG_TO_RAD, 0, 0> ); rotation new_rot = llGetRot() * x_45; // compute global rotation llSetRot(new_rot); // orient the object accordingly

Now consider the following:

rotation new_rot = x_45 * llGetLocalRot(); // compute local rotation llSetLocalRot(new_rot); // orient the object accordingly

This also works Inversely by Dividing two rotations:

rotation new_rot = x_45 / llGetRot(); // compute local rotation llSetRot(new_rot); // orient the object accordingly

When rotating a vector, the rotation must appear to the right of the vector:

vector new_vec = old_vec * x_45; // compiles vector new_v = x_45 * old_v; // doesn't compile

Note: An object can be rotated around an arbitrary point by multiplying a vector by a rotation in the manner described above. The vector should be the difference between the object's current position and the desired "center-point" of rotation. Take the result of the multiplication and add it to the point of rotation. This vector will be the "new location" the object should be moved to.

vector currentPos = llGetPos(); vector rotPoint = llGetPos() + <1, 1, 1>; // in global coordinates vector newPos = rotPoint + ((currentPos - rotPoint) * x_45); llSetPos(newPos);

Bear in mind that any translation (position) operation can result in a vector that would put the object outside of the world, or require a move further than 10 meters--so plan for these possibilities.

Function Name | Purpose |

llAngleBetween | Returns the angle between two rotations |

llAxes2Rot | Converts three axes to a rotation |

llAxisAngle2Rot | Returns the rotation made by rotating by an angle around an axis |

llEuler2Rot | Converts a vector euler rotation into a quaternion rotation |

llList2Rot | Returns rotation from an element of a list |

llRot2Angle | Returns the angle of a rotation |

llRot2Axis | Returns the axis of a rotation |

llRot2Euler | Converts a quaternion into a euler rotation |

llRot2Fwd | Returns a unit vector representing the forward axis after a rotation |

llRot2Left | Returns a unit vector representing the horizontal axis after a rotation |

llRot2Up | Returns a unit vector representing the vertical axis after a rotation |

llRotBetween | Returns the smallest angle (as a rotation) between two vectors |

Function Name | Purpose |

llApplyRotationalImpulse | Applies a rotational impulse |

llDetectedRot | Returns the rotation of detected object or agent |

llGetCameraRot | Gets the rotation of a user's camera |

llGetLocalRot | Gets the local rotation of the object |

llGetOmega | Returns the current rotational velocity |

llGetPrimitiveParams | Gets rotation as well as many other params |

llGetRootRotation | Gets the global rotation of the root object |

llGetRot | Gets the global rotation of the object |

llGetTextureRot | Returns the texture rotation of a side of an object |

llGetStatus | Get wheter an object can be rotated |

llLookAt | Set the target for object to rotate to look at |

llRezAtRoot | Rez an object, specifying rotation |

llRezObject | Rez an object, specifying rotation |

llRotateTexture | Sets the rotation of a texture a side of an object |

llRotLookAt | Sets the target rotation of an object |

llRotTarget | Set rotational target for an object |

llRotTargetRemove | Remove rotational target for an object given its handle |

llSetForceAndTorque | Set rotational and linear force of a physical object |

llSetLocalRot | Sets the local rotation |

llSetPrimitiveParams | Set rotation as well as many other params |

llSetRot | Sets the global rotation |

llSetStatus | Set whether object can be rotated, among other parameters |

llSetTorque | Sets rotational force of a physical object |

llSetVehicleRotationParam | Sets the vehicle rotation parameter |

llSitTarget | Sets the sit target for an object, specifying rotation |

llStopLookAt | Cancel rotation started by llLookAt or llRotLookAt |

llTargetOmega | client-side smooth rotation |

Event Name | Purpose |

at_rot_target | when object comes within target angle |

not_at_rot_target | when rotation target is set but object is not there |

changed | when texture is changed, but not when object rotates |

control | when avatar rotates left or right |

It seems that, for some strange reason, things that rotate don't necessarily update their rotation immediately. You have to grab them in edit mode to actually see the new rotation occur if the new rotation is under a certain threshhold. Physically, the object is still rotated, it just doesn't update on the screen. Is there any way to force the new rotation to update and be visible? -- Myra Loveless

There's similar behaviour with position changes; below a certain treshhold, no changes are shown. The way to fix that one is to first move the object some distance in the opposite direction by atleast the treshhold distance, then to it's intended direction. This trick probably works for rotation too. It's not pretty, but it works if you're just using it to set things up.

This has been reported as a viewer bug, SVC-220 I believe. The script needs to force a viewer update. The best workaround I've found is to set the text, but the update is only forced if the text changes. I use llSetText("x", <1,1,1>, 1.0); immediately followed by llSetText("", <1,1,1>, 1.0); I've seen documentation that suggests llSetColor() will force one as well. -- RJ Thibaud

Functions | Types | Constants | Transform | Child Rotation | Quaternion | Vector | Euler | LibraryRotationFunctions | Dynamics | Interpolate | Joint | Memory Usages

There are 29 comments on this page.
[Display comments/form]