Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

arbitrary rotation around arbitrary points

Brookston Holiday
Registered User
Join date: 29 May 2005
Posts: 58
05-04-2006 16:48
Hell0 all-

I'm trying to figure out how to make an object rotate around an arbitrary rotation point, but not rotate around the global axis.
Here's the situation. Imagin a box located a little forward and to the left of the rotation point. Now, when I rotate this object i want it to rotate in the plane formed by the z-axis and the vector connecting the object to the rotation point.

This could be thought of much like when you have an object rotate around it's own y, or x axis when it is not facing along the global y or x axis. In other words, I want this object to rotate around an arbitrary rotation point, as if it is rotating around the local axes of a prim located at the rotation point, facing the object to be rotated.

Is this at all clear???
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
05-04-2006 18:01
Yes-- find the vector difference from the object to the control point (llGetPos()-controlPoint), and then multiply it by the rotation that you want, then add controlPoint to that vector.

So, it might look like this...

CODE

vector newOffset = (llGetPos()-controlPoint)*myRot;
llSetPos(controlPoint+newOffset);


That should work, but I may have some negatives mixed up (maybe it should be controlPoint-llGetPos()).

Hope this helps.
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
05-04-2006 18:27
I know this is touched on in the wiki under the page for the rotation Type. I'm fiddling with it trying to come up with a script that does what you're describing... or, well, what I think you're describing. :)
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
Brookston Holiday
Registered User
Join date: 29 May 2005
Posts: 58
05-04-2006 20:40
thanks guys...

From: Keknehv Psaltery
find the vector difference from the object to the control point (llGetPos()-controlPoint), and then multiply it by the rotation that you want, then add controlPoint to that vector.


That part i've gotten so far.. the problem is, figuring out the rotation that keeps the object rotating in the verticle plane connecting the object to the rotation point.

the wiki would be more accurate if it described the "arbitrary rotation around a point" as being an arbitrary rotation around the x-axis running through that point. Try it out to see what i mean:

CODE


vector rotPoint = llGetPos()+<3,7,5>;


touch_start(integer number)
{
vector currentPos = llGetPos();
vector newPos = rotPoint + ((currentPos - rotPoint) * x_45);
llSetPos(newPos);
}



what i want it to do is rotate around the rotation point's x-axis if for instance the Y-axis of the rotation point was pointing towards the object.
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
05-05-2006 17:45
You know, I got this script to work, but to be honest, it's hideous, and I'm not entirely sure WHY it works. I hate rotations. :)

CODE
// This hideous script will rotate an object around the point 2m in its local +x
// direction, and will rotate it in the plane formed by it's local x and z axes.

vector startpos ;
rotation startrot ;

// Axis about which to rotate (object's local axes)
vector rotaxis = < 0, 1, 0 > ;

// Offset of center of rotation (object's local coordinates)
vector rotoffset = < 2, 0, 0 > ;

vector rotpoint ;

default
{
state_entry()
{

}

touch_start(integer total_number)
{
startpos = llGetPos() ;
startrot = llGetRot() ;

rotpoint = startpos + ( rotoffset * startrot ) ;

vector targetpos ;

float i ;

for( i = 0 ; i < TWO_PI; i += ( TWO_PI / 90 ) )
{
targetpos = rotpoint - ( rotoffset * llEuler2Rot( rotaxis * i ) * startrot ) ;
llSetPos( targetpos ) ;
}
}
}
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
AJ DaSilva
woz ere
Join date: 15 Jun 2005
Posts: 1,993
05-06-2006 05:02
Just woke up and can't actually focus enough to make sense of what's being said, but here's some code for you:

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);
}


Would be better to use llSetPrimitiveParams rather than the separate rot and pos calls, but I can't be bothered to log in and check I'm getting the sytax for it right.
_____________________