Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Smooth rotation transition using llTargetOmega()

Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
10-30-2005 11:09
I was thinking about how to reduce the impact on screen real estate that a HUD attachment would have when I'm not using it. I thought of the possibility of having it rotate out of view when inactive, and started exploring the use of llSetRot() in steps to make the transition seem smoother. Then I realized that llTargetOmega() could be used to smoothly transition between two rotations, and if you quickly stop the llTargetOmega() and call llSetRot() at just the right moment, the transition could be seamless.

Here's a script I came up with that does this (apologies if this has already been done). Given an axis, an angle, a duration, and an initial rotation, this script will smoothly transition back and forth between two rotations each time the object is touched. To see a demo, just put this script in a prim and poke at it a few times :) Works on attachments and in-world objects.

CODE

// Lex Neva
//
// Smooth Rotation

// This script demonstrates how to use llTargetOmega() to smoothly transition between two
// rotations. Occasionally the object will under- or over-rotate, but generally, the effect
// is to rotate smoothly between a starting and ending rotation.


// how long to take to rotate
float ROT_TIME=1.0;

// axis to rotate around
vector ROT_AXIS=<0.0,0,1>;

// angle in radians to rotate
float ROT_ANGLE=PI_BY_TWO;

// initial rotation
rotation ROT_START=ZERO_ROTATION;

default
{
state_entry() {
// this needs to be a unit vector
ROT_AXIS = llVecNorm(ROT_AXIS);

// get the process started
llSetRot(ROT_START * llAxisAngle2Rot(ROT_AXIS, ROT_ANGLE));
state unflipped;
}
}

state unflipped {
state_entry()
{
llTargetOmega(ROT_AXIS,-ROT_ANGLE/ROT_TIME,1);
llSleep(ROT_TIME);
llTargetOmega(ROT_AXIS,0,1);
llSetRot(ROT_START);
}

touch_start(integer total_number)
{
state flipped;
}
}

state flipped {
state_entry()
{
llTargetOmega(ROT_AXIS,ROT_ANGLE/ROT_TIME,1);
llSleep(ROT_TIME);
llTargetOmega(ROT_AXIS,0,1);
llSetRot(ROT_START * llAxisAngle2Rot(ROT_AXIS, ROT_ANGLE));
}

touch_start(integer total_number)
{
state unflipped;
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
11-01-2005 06:06
/54/31/69230/1.html
_____________________
i've got nothing. ;)