Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Rotate a prim around a point

Rael Delcon
Registered User
Join date: 23 Nov 2006
Posts: 86
05-31-2009 05:12
Hi there. I've a rotation question for which I've not been able to find a good answer on the Wiki or searching on the forum I hope somebody could enlighten me.

I have two prims; let's call the first one "object" and the second one "point". The second one is a small sphere placed exctly on the surface of the first one (that's the reason of the names).

Now I want to rotate the point and have the object rotating accordingly around that point so that the position on the surface will not change.

I figured out that due to the rotation the object will be moved as follow:
newpos = pointpos + (objpos - pointpos) * rot
which correspond to translate in the origin the vector from the center of the point to the center of the object, rotate that vector around the origin and translate the rotated vector back to the point.

The problem is: how should I calculate the rotation of the object itself?

I also had the opposite problem: rotate the object and having the point rotating so that it will continue staying on the object surface but I managed to handle this case.

Any suggestion on how to do it?

Thanks.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
05-31-2009 09:38
Rotate Offset Point Around An Object Position
https://wiki.secondlife.com/wiki/User:Void_Singer/Rotations#Rotating_an_offset_point_to_match_objects_position.2Frotation

Rotate Object Position Around An Offset Point
https://wiki.secondlife.com/wiki/User:Void_Singer/Rotations#Rotate_an_objects_POSITION_around_a_given_offset_point

they are really the same problem approached from two sides

and the tl;dr for you is to apply the rotation first if your getting the poin, last if you're around the point.
_____________________
|
| . "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...
| -
Rael Delcon
Registered User
Join date: 23 Nov 2006
Posts: 86
05-31-2009 11:43
THanks Void. I'm reading the page and I'll try to adapt it to my case.

One thing that I think I'm still missing is this: I have a rotation that has to be applied to the pivot point and I want that the other object will rotate accordingly.

It's not clear to me how the parameters in your functions (say vDegArc) relates to that general rotation. Is it the same or should I apply any other function to calculate it?

Thanks
RD
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
05-31-2009 12:57
From: Rael Delcon
THanks Void. I'm reading the page and I'll try to adapt it to my case.

One thing that I think I'm still missing is this: I have a rotation that has to be applied to the pivot point and I want that the other object will rotate accordingly.

It's not clear to me how the parameters in your functions (say vDegArc) relates to that general rotation. Is it the same or should I apply any other function to calculate it?

Thanks
RD

arc is the amount to rotate around the point, in your case, as a one time use, it's the rotation you want around that point.

depending on how your heirarchy works, you'd start with the base object and calculate the next outward point(s) position (and rotation) from that, and so on, then apply them all at once.
_____________________
|
| . "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...
| -
Rael Delcon
Registered User
Join date: 23 Nov 2006
Posts: 86
06-01-2009 01:24
From: Void Singer
arc is the amount to rotate around the point, in your case, as a one time use, it's the rotation you want around that point.


Thanks Void. Does this imply that I'm confined on a plane? I need to apply a generic rotation to the reference point (it's not up to me to decide, it's an input parameter) and I want the object to rotate so that the relative position does not change.

Imagine you had a lever attached to an object. The attachment point is the pivot point and is confined to rotate around its center.

Moving the lever you can make the pivot point rotate around its center and the attached obiect has to rotate (and its center has to move) accordingly. The pivot point remains in its original position while rotating around its center.

By moving and rotate the lever around its axis (assume is the positive z of the pivot point) you can define an arbitrary rotation.

Is this view that I can't understand how to relate with the code you have on your page and I'm not sure what I'm missing.

RD

-----------------------------

Let me add something more in the hope it's clearer.

If I do the following:

obj_pos = pointpos + (obj_pos-pointpos) * rot;
obj_rot = obj_rot * rot;
pointrot = rot *pointrot;

I have that the point stays where it should but the rotation rot is applied relative to the the object axes while I want it to be applied relative to the pivot point axes. In terms of the example above, attaching the lever is like requiring that the z axis of the object is now the lever itself rather than its original axis.

I guess I should first rotate the object so that its axes have the same orientation than the pivot point, then apply the rotation and than rotate it back. But I'm not clear how to express this in LSL.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
06-02-2009 00:34
two boxes, made of clay, on the left:red(@llGetPos), on the right:blue(@llGetPos+<1,0,0>;). note that blues position is defined as a local offset to red. if you're looking at it from blue's side then the relative positions are r@llGetPos+<-1,0,0> and b:@llGetPos

(for our purpose we'll assume they both start at zero rotation, but it's not necessary)

blues position after red rotates,
calculated from red
bluePos = llGetPos() + <1,0,0> * llGetRot();
calculated from blue (where arc is reds rotation)
bluePos = llGetPos + (<-1,0,0> - <-1,0,0> * arc) * llGetRot();

if you want blue to match it's rotation to red as well
calculated in red
blueRot = llGetRot() * blueRot;
calculated in blue
blueRot = arc * llGetRot();
(much like the moon always has the same side facing the earth, blue will always have the same relative facing to red with this formula)

the calculations are equivalent, and the rotation direction is not constrained in any way. the easiest way to calculate offset is to set up both objects, the one that you're doing the calculation from should be rotated to face the other how you want, and then the formula for geting the LOCAL offset is ((bluePos- redPos) / xRot) (where x is the rotated prim you'll do the calculations from)
_____________________
|
| . "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...
| -
Rael Delcon
Registered User
Join date: 23 Nov 2006
Posts: 86
06-02-2009 02:42
Thanks Void, I'll try again following your suggstions

I also got the suggestion to check the llAxisAngle2Rot() function that would give me the rotation around the axis defined by the the reference point.

I guess rotation are among the most complex things to grasp ... at least for me :)


Thanks,
RD
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
06-02-2009 03:08
From: Rael Delcon
Thanks Void, I'll try again following your suggstions

I also got the suggestion to check the llAxisAngle2Rot() function that would give me the rotation around the axis defined by the the reference point.

I guess rotation are among the most complex things to grasp ... at least for me :)


Thanks,
RD

I have trouble doing the math too... that's why I write down these formulas... so I can just plug in the things I need, for the actions I want... keeps my head from blowing up... most of the time...
_____________________
|
| . "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...
| -