Difference between revisions of "User:Dora Gustafson/Replacing llTargetOmega"

From Second Life Wiki
Jump to navigation Jump to search
Line 1: Line 1:
{{LSL Header}}
== Replacing llTargetOmega with a Key Framed Motion ==
== Replacing llTargetOmega with a Key Framed Motion ==
<lsl>
KeyFramedOmega( vector axis, float spinrate)
{
    llSetKeyframedMotion( [], []);
    if ( spinrate )
    {
        float v = TWO_PI/3.0;
        if ( spinrate < 0 ) v = -v;
        list L = [llAxisAngle2Rot( axis/llGetRot(), v), v/spinrate];
        llSetKeyframedMotion( L+L+L, [KFM_DATA, KFM_ROTATION, KFM_MODE, KFM_LOOP]);
    }
}
</lsl>
{{LSL_Function
|func=KeyFramedOmega
|func_id
|func_sleep
|func_energy
|func_desc=Rotates the object/prim around axis at a rate of spinrate in radians per second
|func_footnote
|return_type
|return_text
|p1_type=vector
|p1_name=axis
|p1_desc=arbitrary axis to rotate the object around
|p1_hover
|p2_type=float
|p2_name=spinrate
|p2_desc=rate of rotation in radians per second
|p2_hover
|constants
|spec=
: This doesn't make [[llTargetOmega]] redundant but in some cases a Key Framed motion may be preferred
: This doesn't make [[llTargetOmega]] redundant but in some cases a Key Framed motion may be preferred
: The routine: "KeyFrameOmega" is easy to use for [[llTargetOmega]]: It takes the first two parameters in [[llTargetOmega]]: axis and spinrate
: The routine: "KeyFramedOmega" is easy to use for [[llTargetOmega]]: It takes the first two parameters in [[llTargetOmega]]: axis and spinrate
: The included script shows how to use the routine to start, stop and reverse a spin on repeated touches
: All viewers will see the same spin and rotation
: The object will keep the rotation it has when spin is stopped
: A spin will continue even when the script is deleted
|caveats=
: The script must be in the root prim
: It can not spin child prims
: The object must be convex hull physics type
: Can not spin physical objects
|examples=
This script shows how to use the routine to start, stop and reverse a spin on repeated touches
<lsl>
<lsl>
// llTargetOmega substitution by Dora Gustafson, Studio Dora 2014
// llTargetOmega substitution by Dora Gustafson, Studio Dora 2014
// The script must be in the root prim
// It can not spin child prims
// The object must be convex hull physics type
// Can not spin physical objects
// The parameters are the same as the two first for llTargetOmega
// All viewers will see the same spin and rotation
// The object will keep the rotation it has when spin is stopped
// A spin will continue even when the script is deleted


integer P;
integer P;
Line 42: Line 74:
         else KeyFramedOmega( <0,0,1>, 0.0);                // Stop spin
         else KeyFramedOmega( <0,0,1>, 0.0);                // Stop spin
     }
     }
}</lsl>
}
{{LSLC|Library}}
</lsl>
|helpers
|also_header
|also_functions=[[llTargetOmega]]
|also_tests
|also_events
|also_articles=[[llSetKeyframedMotion]]
|also_footer
|notes
|mode=user
|deprecated
|location
|cat1=LSL Rotation
}}

Revision as of 03:47, 12 August 2014

Replacing llTargetOmega with a Key Framed Motion

<lsl> KeyFramedOmega( vector axis, float spinrate) {

   llSetKeyframedMotion( [], []);
   if ( spinrate )
   {
       float v = TWO_PI/3.0;
       if ( spinrate < 0 ) v = -v;
       list L = [llAxisAngle2Rot( axis/llGetRot(), v), v/spinrate];
       llSetKeyframedMotion( L+L+L, [KFM_DATA, KFM_ROTATION, KFM_MODE, KFM_LOOP]);
   }

} </lsl>

Summary

Function: KeyFramedOmega( vector axis, float spinrate );

Rotates the object/prim around axis at a rate of spinrate in radians per second

• vector axis arbitrary axis to rotate the object around
• float spinrate rate of rotation in radians per second

Specification

This doesn't make llTargetOmega redundant but in some cases a Key Framed motion may be preferred
The routine: "KeyFramedOmega" is easy to use for llTargetOmega: It takes the first two parameters in llTargetOmega: axis and spinrate
All viewers will see the same spin and rotation
The object will keep the rotation it has when spin is stopped
A spin will continue even when the script is deleted

Caveats

The script must be in the root prim
It can not spin child prims
The object must be convex hull physics type
Can not spin physical objects

Examples

This script shows how to use the routine to start, stop and reverse a spin on repeated touches <lsl> // llTargetOmega substitution by Dora Gustafson, Studio Dora 2014

integer P;

KeyFramedOmega( vector axis, float spinrate) {

   llSetKeyframedMotion( [], []);
   if ( spinrate )
   {
       float v = TWO_PI/3.0;
       if ( spinrate < 0 ) v = -v;
       list L = [llAxisAngle2Rot( axis/llGetRot(), v), v/spinrate];
       llSetKeyframedMotion( L+L+L, [KFM_DATA, KFM_ROTATION, KFM_MODE, KFM_LOOP]);
   }

}

default {

   state_entry()
   {
       llSetPrimitiveParams([PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_CONVEX]);
   }
   touch_end( integer n)
   {
       P = ++P%4;
       if ( P == 1 ) KeyFramedOmega( <0,0,1>, 2.0);       // Positive spin
       else if ( P == 3 ) KeyFramedOmega( <0,0,1>, -2.0); // Negative spin
       else KeyFramedOmega( <0,0,1>, 0.0);                // Stop spin
   }

}

</lsl>

See Also

Functions

llTargetOmega

Articles

llSetKeyframedMotion