Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Rotation and Math

Kaylan Draken
Registered User
Join date: 2 Dec 2006
Posts: 127
02-09-2009 11:07
Hi all,

I hope someone can help me.

I want to rotate a light around a danceball without linking them together.
I know the center position and the radius but don't know how to calculate
the the path so i can change the position with llSetPos.

Or does someone knows a better way to rotate a light around a danceball
without linking them together. Rotate will be the default position of the light
but it will move to other things to so linking can't be used (so far i know).
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
02-09-2009 11:52
Does the light itself need to rotate on its own axis? Or is it just revolving around the danceball?

I'll assume the latter, and if it needs to rotate on its axis as well, we can add that later.

All you need to do, for the *simplest* (but not necessarily best) implementation is plot the path of a circle around the center, which is high school algebra.

I'd use a timer to periodically reposition the object.

The Z coordinate will stay constant, matching that of the center.

X and Y are calculated using llSin() and llCos() times the radius, as offsets from the center. The parameter you pass to these the time, divided by a scale factor that is inversely proportional to the rotation speed. Set the timer to run at any interval and you'll get nearly the same results; the tradeoffs would be smoother motion for smaller intervals and less lag for bigger ones. Since setting position causes a script delay, there's a minimum effective timer, documented for llSetPos(). Going lower than that will have no effect.

HTH
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
02-09-2009 12:14
Why would you use sin and cos instead of the LL vector operators? Is there some subtle point I'm missing?

And you can use a sensor instead of a timer so if the danceball is moved a bit it will follow it.

CODE

float DISTANCE = 1.0; // 1.0 meters;
float UPDATE_RATE = 1.0; // update once per second
float TURN_RATE = 1.0; // move 1 degree per update
float degrees = 0.0;

//...

state_entry()
{
llSensorRepeat("danceball", NULL_KEY, ACTIVE|PASSIVE, DISTANCE*2, PI, UPDATE_RATE);
}

sensor(integer n)
{
vector base = llDetectedPos(0);
rotation angle = llEuler2Rot(<0,0,degrees>*DEG_TO_RAD);
vector direction = <1,0,0> * angle;
vector position = direction * DISTANCE + base;
llSetPos(position);
llSetRot(angle);
degrees += TURN_RATE;
}
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Kaylan Draken
Registered User
Join date: 2 Dec 2006
Posts: 127
02-09-2009 12:19
thanks argent and lear,

I will try it but math isn't my thing :))
had always trouble with sin and cos but i will try to figure it out.

Thanks again
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
02-10-2009 09:11
Argent's solution is better. The llSetRot() is needed only if you want the light to rotate. If the light is symmetrical about the vertical axis, may be better to leave that out because it causes a delay in the script (as does llSetPos()).
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
02-10-2009 10:24
Note that my solution is not complete, it is intended to be put in the existing script for the light.

To make it run as is, you need to wrap the event handlers in a default state. You probably want to add some touch events and the like as well.
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
02-10-2009 16:36
presuming you set it up yourself at a given offset you don't need the sensor, just a timer, a radius and an arc (how much of the circle do you want to travel at once)
CODE

llSetPrimitiveParams( [PRIM_POSITION, llGetPos() + (gPosOffset - gPosOffset * gRotArc) * llGetRot(),
PRIM_ROTATION, gRotArc * llGetRot()] );

will move the object gRotArc degrees around gPosOffset (and as a bonus it'll face the center consistently) or you could use the same formula, and have it move to target on the new position, although that either requires keeping track of where you are on the arc, or recalculating the offset..

formula:
vector_orbiters_position + (vector2center - vector2center * rotation_arc2travel) * obiters_rotation = new_position
==
rotation_arc2travel * orbiters_rotation = new+rotation
(this can be ommited if you recalculate the offset as below)
==
vector2center *= rotation_arc2travel
(omit this if you used the previous method
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Kaylan Draken
Registered User
Join date: 2 Dec 2006
Posts: 127
02-11-2009 09:59
Thanks guys,

I will try it.
Have always trouble with math but have now some examples to try
to make it work for me :)