Unofficial LSL Reference

[[functions:llapplyrotationalimpulse]]


Unofficial LSL reference

User Tools

Login

You are currently not logged in! Enter your authentication credentials below to log in. You need to have cookies enabled to log in.

Login

Forgotten your password? Get a new one: Set new password

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

functions:llapplyrotationalimpulse [2015-01-09 18:38 SLT]
sei Add complete example, add llTargetOmega to See Also
functions:llapplyrotationalimpulse [2016-11-03 18:18 SLT] (current)
sei speed -> velocity
Line 6: Line 6:
 </​code>​ </​code>​
  
-Apply an instant change to the angular momentum of a physical object. It has no effect on non-physical objects.+Apply an instant change to the angular momentum of a physical object. It has no effect on non-physical objects ​or on attachments.
  
 ===== Parameters ===== ===== Parameters =====
  
 === impulse === === impulse ===
-A [[types/vector]] specifying the impulse to apply, which will add to the object'​s current [[http://​en.wikipedia.org/​wiki/​Angular_momentum|angular momentum]]. The vector indicates the impulse'​s axis and magnitude. The units of the angular impulse vector seem to be [[lsl/lindograms]]·m²/s. Like in the real world, the effect on the angular velocity depends not only on the mass of the object, but also on its shape, as it's the product of [[http://​en.wikipedia.org/​wiki/​Moment_of_inertia|moment of inertia]] (which itself depends on the [[http://​en.wikipedia.org/​wiki/​List_of_moments_of_inertia|shape of the object]]) and angular velocity.+$lty[vector] specifying the impulse to apply, which will add to the object'​s current [[http://​en.wikipedia.org/​wiki/​Angular_momentum|angular momentum]]. The vector's direction ​indicates the impulse'​s axis and its length indicates the magnitude. The units of the angular impulse vector seem to be $lart[lindogram|lindograms]·m²/​s. Like in the real world, the effect on the angular velocity depends not only on the mass of the object, but also on its shape, as it's the product of [[http://​en.wikipedia.org/​wiki/​Moment_of_inertia|moment of inertia]] (which itself depends on the [[http://​en.wikipedia.org/​wiki/​List_of_moments_of_inertia|shape of the object]]) and angular velocity.
  
 === local === === local ===
-[[types/Boolean]] value indicating whether the **impulse** axis' coordinates are local to the root prim (if [[constants/TRUE]]) or in sim coordinates (if [[constants/FALSE]]).+$lty[Boolean] value indicating whether the $prm[impulseaxis' coordinates are local to the root prim (if $lct[TRUE]) or in sim coordinates (if $lct[FALSE]).
  
-When **TRUE**, the **impulse** axis' coordinates are local to the root prim. For example, if **impulse** is `<1, 0, 0> and the X axis of the root prim is looking northwest, then the impulse will have its axis oriented in the northwest direction, aligned with the root prim's X axis.+When $ct[TRUE], the $prm[impulseaxis' coordinates are local to the root prim. For example, if $prm[impulseis `<1, 0, 0> and the X axis of the root prim is looking northwest, then the impulse will have its axis oriented in the northwest direction, aligned with the root prim's X axis.
  
-When **FALSE**, the vector specifies sim coordinates,​ where positive X is east, positive Y is north, positive Z is up, and vice versa for negative; for example, if **impulse** is `<-1, 0, 0>, the rotational impulse will have its axis pointing west, no matter how the root prim is oriented.+When $ct[FALSE], the vector specifies sim coordinates,​ where positive X is east, positive Y is north, positive Z is up, and vice versa for negative; for example, if $prm[impulseis `<-1, 0, 0>, the rotational impulse will have its axis pointing west, no matter how the root prim is oriented
 + 
 +===== Notes ===== 
 + 
 +  * The maximum angular velocity of an object seems to be about 127 rad/s (about 1212 rpm). Note, however, that $lfn[llGetOmega] will not return a value with a magnitude greater than 62.8 rad/s (about 599.7 rpm).
  
 ===== Short examples ===== ===== Short examples =====
Line 28: Line 32:
 llApplyRotationalImpulse(<​0,​ 0, 1>, TRUE); llApplyRotationalImpulse(<​0,​ 0, 1>, TRUE);
 // 0.6 rad/s is derived from the moment of inertia of a cube spinning over its // 0.6 rad/s is derived from the moment of inertia of a cube spinning over its
-// axis (m*l*l/6, where l is the length of the side) and the impulse applied.+// axis (m*l^2/6, where l is the length of the side) and the impulse applied.
 // The mass of such a cube is 10 lindograms. Measurement with llGetOmega // The mass of such a cube is 10 lindograms. Measurement with llGetOmega
 // indicates that it works this way. // indicates that it works this way.
Line 35: Line 39:
 ===== Complete examples ===== ===== Complete examples =====
  
-This example verifies the physical accuracy of **llApplyRotationalImpulse** on an undeformed box of any dimensions. Moment of inertia varies with shape, so most deformations affect the results.+This example verifies the physical accuracy of $fn[llApplyRotationalImpulseon an undeformed box of any dimensions. Moment of inertia varies with shape, so most deformations affect the results.
  
-<code lsl2 llApplyRotationalImpulse-test>​+<code lsl2 llApplyRotationalImpulse-test.lsl>
 float IMPULSE = 1.31; // change this value to any value to test float IMPULSE = 1.31; // change this value to any value to test
  
 default default
 { {
-    ​state_entry()+    ​touch_start(integer n)
     {     {
-        ​llSetStatus(STATUS_PHYSICSFALSE); +        ​// Disable gravityenable physics, wait for the setting to take effect
-        vector size = llGetScale();​ +
-        llSleep(0.2);​+
         llSetPhysicsMaterial(GRAVITY_MULTIPLIER,​ 0, 0, 0, 0);         llSetPhysicsMaterial(GRAVITY_MULTIPLIER,​ 0, 0, 0, 0);
-    } 
- 
-    touch_start(integer n) 
-    { 
-        // Enable physics, wait for the engine to detect it 
         llSetStatus(STATUS_PHYSICS,​ TRUE);         llSetStatus(STATUS_PHYSICS,​ TRUE);
         llSleep(0.5);​         llSleep(0.5);​
Line 64: Line 61:
         // times. Sometimes we're lucky and get the actual value.         // times. Sometimes we're lucky and get the actual value.
         vector omega = llGetOmega();​         vector omega = llGetOmega();​
-        vector size = llGetScale();​ 
  
         // Disable physics again, return to zero rotation.         // Disable physics again, return to zero rotation.
Line 70: Line 66:
         llSetRot(<​0,​ 0, 0, 1>);         llSetRot(<​0,​ 0, 0, 1>);
  
 +        // Calculate and report results.
 +        vector size = llGetScale();​
 +        // Predicted omega is impulse divided by moment of inertia.
 +        // Moment of inertia of a box rotating on its z axis is m*(size.x²+size.y²)/​12.
         float predicted = IMPULSE/​(llGetMass()*(size.x*size.x+size.y*size.y)/​12);​         float predicted = IMPULSE/​(llGetMass()*(size.x*size.x+size.y*size.y)/​12);​
         llSay(0, "​Theoretical omega: " + (string)predicted         llSay(0, "​Theoretical omega: " + (string)predicted
Line 81: Line 81:
 ===== See also ===== ===== See also =====
  
-  * [[llApplyImpulse]] is similar but for [[http://​en.wikipedia.org/​wiki/​Momentum|linear momentum]] instead of angular. +  * $lfn[llApplyImpulse] is similar but for [[http://​en.wikipedia.org/​wiki/​Momentum|linear momentum]] instead of angular. 
-  * [[llSetAngularVelocity]] applies the rotational impulse necessary to set the given angular velocity for an object. +  * $lfn[llSetAngularVelocity] applies the rotational impulse necessary to set the given angular velocity for an object. 
-  * [[llGetOmega]] obtains the current angular velocity of the object. +  * $lfn[llGetOmega] obtains the current angular velocity of the object. 
-  * [[llTargetOmega]] tries to keep a constant angular ​speed+  * $lfn[llTargetOmega] tries to keep a constant angular ​velocity
-  * [[llSetTorque]] applies an angular force (a torque) to an object continuously +  * $lfn[llSetTorque] applies an angular force (a torque) to an object continuously 
-  * [[llSetForce]] is the linear equivalent to **llSetTorque**+  * $lfn[llSetForce] is the linear equivalent to $fn[llSetTorque]
-  * [[llSetForceAndTorque]] sets both force and torque at the same time. +  * $lfn[llSetForceAndTorque] sets both force and torque at the same time. 
-  * [[llSetVelocity]] and [[llGetVel]] are the linear equivalents of **llSetAngularVelocity/​llGetOmega**+  * $lfn[llSetVelocity] and $lfn[llGetVel] are the linear equivalents of $fn[llSetAngularVelocity]/$fn[llGetOmega]
-  * [[llGetMass]] returns the mass in Lindograms of an object. +  * $lfn[llGetMass] returns the mass in $lart[lindogram|Lindogramsof an object. 
-  * [[llGetMassMKS]] returns the mass in kilograms of an object. Most LSL functions use Lindograms, so this function is of limited use in physics calculations. +  * $lfn[llGetMassMKS] returns the mass in kilograms of an object. Most LSL functions use $art[Lindograms], so this function is of limited use in physics calculations. 
 +  * $lfn[llVecNorm] to obtain a unit vector from a given one.