Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

how can this cause rotation?

paulie Femto
Into the dark
Join date: 13 Sep 2003
Posts: 1,098
02-24-2006 14:56
The scripting wiki includes an example of how to rotate an object around an arbitrary point. The example doesn't seem to work. The example moves the object instead of rotating it.

Here's the example:

-----------
Note: An object can be rotated around an arbitrary point by multiplying a vector by a rotation. 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);
-------------


How could this work? How can llSetPos() change the rotation of an object? In my experiments with this code, it doesn't.
_____________________
REUTERS on SL: "Thirty-five thousand people wearing their psyches on the outside and all the attendant unfettered freakishness that brings."
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
02-24-2006 15:02
Because rotating around a point that's not the object's center means moving in an arc. So the object's position and rotation must both change. It's like walking in a circle - that's the same thing as rotating around the center of the circle.
AJ DaSilva
woz ere
Join date: 15 Jun 2005
Posts: 1,993
02-24-2006 16:01
Ziggy's right, although the example in the wiki is lacking for many purposes. This is what I use:
CODE
offsetRot(vector rotPoint, rotation rotAngle)
{
rotation new_rot = llGetRot() * rotAngle;
llSetRot(new_rot);

vector currentPos = llGetPos();
vector newPos = rotPoint + ((currentPos - rotPoint) * rotAngle);
llSetPos(newPos);
}
Sky Honey
Coder
Join date: 16 May 2005
Posts: 105
02-25-2006 06:49
I read the wiki the same as Paulie at first - it seems to be saying that rotation about a point can be achieved with one call to llSetPos. This is not the case - that snippet of code has to be combined with the earlier snippet that uses llSetRot. Like AJ did in his example.
_____________________
paulie Femto
Into the dark
Join date: 13 Sep 2003
Posts: 1,098
Thanks!
02-25-2006 09:40
Thanks for the clarification, everyone! :) I understand, now, that the code is designed to cause an object to "revolve" (orbit) around an arbitrary point. Perhaps the wiki text could be rewritten to make this clearer...
_____________________
REUTERS on SL: "Thirty-five thousand people wearing their psyches on the outside and all the attendant unfettered freakishness that brings."