Don't click here unless you want to be banned.

LSL Wiki : rotation

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawl338.us.archive.org

Rotation


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').

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 <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.

Example:
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 PI_BY_TWO, PI, and TWO_PI to let you specify common rotations in radians directly:

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 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.

Combining Rotations

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.

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
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.

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.

Math Functions

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

World Functions

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

Events

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

Q: Is there a non lossy way to convert a rotation to a string and then back to a rotation again so that the resulting rotation has the same value as the original rotation?
A: See: Serialization

Q: I see 1/rot sometimes. What does that mean, exactly?
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.

Q: How do I use llTargetOmega to rotate an object about it's local Z-axis?
A: Use llRot2Up(llGetRot()) as the axis. It's automatically normalized to 1.

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
Comments [Hide comments/form]
Cat -- the // denotes italics. So half this page is italicized.
-- BinoArbuckle (2003-12-28 18:21:47)
And none of your // comment tags are shown.
-- BinoArbuckle (2003-12-28 18:22:56)
Fixed. Use &quot;&quot;//&quot;&quot;
-- EzharFairlight (2003-12-29 02:02:41)
Oh, I know... I had to wander off and do something else while I was in the middle of it. I figured someone else would get to it. That's the point of a wiki, you know. :)
-- CatherineOmega (2003-12-29 04:51:39)
Yeah. I would have done it, but I wasn't sure exactly what was supposed to be italicized or commented. Or I'm lazy. Probably the latter.
-- BinoArbuckle (2003-12-29 16:01:23)
Need reference to llTargetOmega and anything else related to rotation
-- ZenoConcord (2005-08-15 15:49:38)
llTargetOmega WAS here before Keknazi removed it... It's back now.
-- EepQuirk (2005-08-19 22:35:17)
Eep, please stop with the personal attacks and profanity. Calling Keknehv a Nazi is uncalled for, and does nothing but detract from the wiki's usefulness.
-- CatherineOmega (2005-08-20 00:21:20)
I'll stop when he and others stop screwing up my pages and info I add to pages...
-- EepQuirk (2005-08-20 01:18:47)
Another amazing thing to say, Eep. You rival Churchill himself. I especially like how you combined it with my name. That was creative.

Hey, I thought that llTargetOmega wasn't quite a rotation function. I was looking at it in terms of the variable type, and llTargetOmega doesn't even take rotations as parameters or as a return value.

Perhaps you could label the information that you put on pages with something like "Eep's private property" next to them, so I can know what's your information. Then I wouldn't edit that, respecting your feeling of ownership over the things you edit.
-- KeknehvPsaltery (2005-08-20 13:24:50)
Stop assuming you know everything and get over yourself, Kek. If you can't see how llTargetOmega is a rotation function, yer a freakin' IDIOT. Stop butchering this wiki!
-- EepQuirk (2005-08-20 15:50:35)
Yes Eep, and you've done nothing but help make this Wiki a great and fun place. And how can you tell someone to get over themselves when YOU think that everthing YOU do is right?
-- SchitsoMonkey (2005-08-20 17:27:23)
I am trying to make this wiki more efficient; you and Kek are just cluttering it up with junk and removing useful information.
-- EepQuirk (2005-08-21 02:23:51)
Ahh, so you see yourself as better than everyone else? Just because you see something as more efficient, you have a right to change everything to what you see fit? What you have to realize is that, just because you think its right, doesn't mean it's right. You need to listen to other peoples suggestions before you go off on an editing rampage, just because you see something as inefficient.
-- SchitsoMonkey (2005-08-21 12:44:51)
llTargetOmega doesn't use the rotation type. That's why I removed it in the first place.

How about you add content, instead of just trying to keep yours in place?
-- KeknehvPsaltery (2005-08-21 12:46:17)
Then your definition of "rotation" is insufficient, Kek; not MY problem but don't remove something that obviously belongs...
-- EepQuirk (2005-08-22 01:30:45)
If that's my definition, how would I know that it obviously belongs?
-- KeknehvPsaltery (2005-08-22 14:06:27)
Lack of relativistic thinking on your part. <shrug>
-- EepQuirk (2005-08-23 15:33:03)
Those comments are hardly professional, Eep.
-- IceBrodie (2005-08-25 18:18:00)
And your wiki vulture-trolling is? Look in the mirror, putz!
-- EepQuirk (2005-08-26 20:09:24)
I'm not the one calling others names, Eep... please grow up.
-- IceBrodie (2005-08-27 05:11:21)
I added references to everything related to rotations.

I, for one, would appreciate if these references are preserved. When I was learning LSL, I looked here for things about rotations... yes, even rotations of textures. Free free to organize the references into subsections about the different kinds of functions.

Also, feel free to delete your meta-messages unrelated to rotations :).
-- ZenoConcord (2005-08-27 15:29:03)
AndrewMontagne, don't remove existing function examples and replace them with non-working ones--or ones that are more complex than they need to be. If you feel the need to do so, ADD it but don't REPLACE an existing example.
-- EepQuirk (2006-04-15 13:57:58)
I'm currently trying to make an analogue clock to learn about textures, I've got one working with rotatetextures and I've got one working with using LLSetRot by linking my arm with an invis object and making it the pivot. I was wondering if anyone could elaborate on this function that uses vector math to rotate around a point? Does anyone have a better description of what vector math is going on here or a more complete script that does it?

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

Would be really great if I could get this work just for my own knowledge, I still think using texture rotate is more efficient then moving around prims for the clock arms but more interested in learning everything about rotation in SL.
-- FleaCure (2006-04-19 03:32:23)
Escaped italics I do love these heated agreements Eep gets himself into so well...
-- HazVega (2006-04-24 14:18:59)
I'm trying to make an autoshield, how could I get the rotation between two points?
-- DurnusScripter (2006-11-10 10:44:06)
Maybe the function in the table with the description "Returns the smallest angle (as a rotation) between two vectors"
-- BlindWanderer (2006-11-10 11:28:56)
Thank you, I didn't know what that did until now, when I looked into it in detail.
-- DurnusScripter (2006-11-10 12:35:05)
Assuming you know the coordinates of all points that can identify a prim, is there a way to calculate the rotation quaternion from the coordinates of the prim before and after it was rotated?
-- EadoinWelles (2007-01-22 03:02:28)
Attach a comment to this page: