Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

changing prim center of rotation

Epictetus Theas
Registered User
Join date: 30 Oct 2007
Posts: 3
02-03-2008 14:10
Hello all! I've been experimenting with prim rotation and seem to have hit a stumbling block (more than likely due to my lack of experience with higher mathematics). My understanding of prim rotation is that the prim will rotate according to it's geometric center. Is there some formula to alter the point of rotation within a prim of an arbitrary size/shape? Thank you in advance!
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-03-2008 14:27
A prim rotates about the geometric center of its uncut version (if you've path cut away half a box, for example, it'll rotate around a point on one of the sides). There is no way to change this. You can use both rotation and re-positioning to EFFECTIVELY rotate around a different point, but not really for dynamic rotation such as that provided by llTargetOmega().

An OBJECT rotates about the same center point that it's ROOT PRIM would. So if you have a single-prim object you want to rotate about a point not at its center, you can cheat by linking it to a (usually small, transparent) root prim, and centering that root prim at the point about which you want to rotate, and rotating the whole object by rotating the root prim rather than the child. This doesn't really work if you want to rotate a prim that is already a child of an object though, since all an object's prims are linked in a big flat list (or one parent with a flat list of children, would be more accurate) rather than being a hierarchical tree structure like most graphical modeling applications use. That is where about the best you can do is to rotate and reposition to get an equivalent non-physical, non-smooth effect.
Nyles Nestler
Registered User
Join date: 5 Jan 2008
Posts: 72
02-03-2008 14:35
From: someone
So if you have a single-prim object you want to rotate about a point not at its center, you can cheat by linking it to a (usually small, transparent) root prim, and centering that root prim at the point about which you want to rotate, and rotating the whole object by rotating the root prim rather than the child.


Glad I stumbled onto this thread! This is great news! Thank you!
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-03-2008 14:40
Sure thing. By the way, this is very different from the way an object rotates when you do it using the mouse in edit mode. With the mouse, an object rotates about the whole object's geometric center, not the origin of the root prim. The NUMBER FIELDS in the edit window, however, perform similarly to scripted rotation.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
02-03-2008 17:02
to get the object (or prim) rotation around around an arbitrary offset from the root center using a move/rot combo like heewee mentioned use the following formula

llSetPos( llGetPos() + (offset - offset * arc) * llGetRot() );
llSetRot( arc * llGetRot );

where arc is the rotation amount you want to preform, and offset is the local axis offset from the root.

beware that offsets with llVecMag() > 5 meters combined with large arcs can produce moves greater than 10m which will fail, so make sure that the new position is <10m away (or use warppos or a similar function)
_____________________
|
| . "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...
| -
Tazmania Trefusis
Registered User
Join date: 13 Jan 2008
Posts: 85
05-06-2008 02:58
Anyone have a small script to show how this rotation offset in action!!

I have this problem, I have ship which contains root prim at its center
Vert mast coming down with satellite dish (it was a 2xsat dish assembly with spikes, meshes etc but I cant rotate all that at once so had to settle for 1 prim dish :-(
Trouble is the axis for the torus 'dish' is at the end of the spike! and of course thats its center of rotation, with the dish facing inwards and off center (as shown in crude diagram)


Ship

R .... < Main ship body containing Root prim
¦
¦
-D .... < Satellite dish, made with configured torus -1 prim ¦
¦

So it was bad enough havin to scrap the 2 x sat dish assembly as all of the bits wouldnt have rotated in sync lol.
Then I finally find a prim (tried some sculpies but just looked crap!) that is sorta shaped like a sat dish,lol and it's axis of rotation is right on the tip of the spike and not at the back of the dish as that would have been ideal!.

Limitations, limitations :-(
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
05-06-2008 09:29
From: Tazmania Trefusis
Anyone have a small script to show how this rotation offset in action!!

Sure. This function returns the position to which to move the prim/object given the new rotation and the center of rotation (in global coordinates for a root prim, or object coordinates for a child prim; not likely to work in attachments):
CODE

vector calculateCenterPos(rotation newRot, vector centerOfRotation)
{
rotation currRot = llGetLocalRot();
vector currPos = llGetLocalPos();

vector displacement = currPos-centerOfRotation;
vector newDisplacement = displacement*(newRot/currRot);

return centerOfRotation+newDisplacement.
}


You might use it like this:
CODE

rotateToRotAround(rotation newRot, vector centerOfRotation)
{
vector newPos = calculateCenterPos(newRot, centerOfRotation);
llSetPrimitiveParams([PRIM_POSITION, newPos, PRIM_ROTATION, newRot]);
}
Tazmania Trefusis
Registered User
Join date: 13 Jan 2008
Posts: 85
05-06-2008 10:57
Over my head but thanks anyway
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
05-06-2008 12:26
From: Tazmania Trefusis
Over my head but thanks anyway

The attached image may help. It is the equivalent in a 2D context.