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’ (not ‘.w’).
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/OSSL does do some implicit typecasting but the compiler does not actualy convert types or simplify code; it just makes implicit typecasts explicit. So while <0, 0, 0, 1> is valid, it will use more bytecode and be slower than <0.0, 0.0, 0.0, 1.0>. For this reason please be sure to use a decimal point. "0." is enough, you don’t need an extra zero. However, this does lack clarity.
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 not correspond to roll, pitch, and yaw. For more information on what they represent, see the page on quaternions.
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: llEuler2Rot and llRot2Euler.
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 DEG_TO_RAD and RAD_TO_DEG to facilitate conversion to and from degrees.
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
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/OSSL defines the constant ZERO_ROTATION to represent a rotation of angle zero. Calling llSetRot( ZERO_ROTATION ) orients the object so that its local axes are aligned with the global axes. The value returned by llGetRot is the object’s current orientation relative to this null rotation.
An object is rotated by multiplying its current orientation with the desired rotation. The order in which the operands are specified depends if a rotation is performed around the global axes or the local axes.
// 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
This rotates the object around the global x-axis (the axis which runs from west to east).
Now consider the following:
rotation new_rot = x_45 * llGetLocalRot(); // compute local rotation llSetLocalRot(new_rot); // orient the object accordingly
This rotates the object around its local x-axis, which depends on its current orientation. Think of this as specifying the rotation from the object’s point of view, that is, relative to the direction it is currently facing.
This also works Inversely by Dividing two rotations:
rotation new_rot = x_45 / llGetRot(); // compute local rotation llSetRot(new_rot); // orient the object accordingly
Like previously, this would rotate your object along the x-axis based on its current orientation, but in the opposite direction.
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);
|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|
|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|
|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|
A: See: Serialization
A: Do you mean <0,0,0,1>/rot ? That inverts the quaternion. Or do you mean <0,0,1>/rot ? Which multiples the vector by the inverse quaternion.
A: Use llRot2Up(llGetRot()) as the axis. It’s automatically normalized to 1.