Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help with Gradual Rotation Between Two Points

Debbie Trilling
Our Lady of Peenemünde
Join date: 17 Oct 2006
Posts: 434
09-20-2008 01:51
Hi

I have a script that moves a prim from PointA to PointB to PointC etc.

Each Point has two properties 1) the required x, y and z co-oridnates of the prim 2) the required x, y and z rotations of the prim.

I can calculate the distances between each point on the x, y and z co-ordinates and I know what "speed" (meters per second) that is required. From this information I am able to determine how much x, y and z distance that has to be applied per llSetPos() iteration.

So far so good, and this is working well.

The problem I am struggling with is applying similar priniciples to the rotations.

I know the required rotations on the x, y and z for the two points...that is, the Start Rotation and the End Rotation...but how do I calculate how many degrees of change have to be applied per iteration (ie: calculate the change in degrees per meter)?

At the moment I can apply the necessary rotation change in a single action using llRotLookAt(), but what I really want is to apply it gradually as it travels between the two points. For example, if the number of degrees rotation difference is, say, 60, then mid-way between the two points it should have turned 30degrees; when three-quarters of the distance has been traveled it should be at 45degrees rotation.


I think the question I am asking is, "how do I calculate the number of degrees of rotation difference on the x, y and z axis between PointA and PointB?"

Once I have these values I can divide by the distance on that specific axis to get the degree of change per iteration.

Or am I missing the point entirely and is there a better solution?

Thanks in advance from one of the Rotationally Challenged.

BTW: the prim is non-physical, and I would prefer to keep it this way.
_____________________
http://wiki.secondlife.com/wiki/User:debbie_Trilling
Uchi Desmoulins
Registered User
Join date: 30 Jan 2006
Posts: 1
09-20-2008 02:40
You can find the axis of rotation between two rotations by using a function like:

llRot2Axis(rot_a / rot_b) * rot_a); // We'll assign the resulting value to 'axis' here.

How's it work? I forget. But it made sense at the time when I was trying to solve this exact problem. There might be a more sensible solution to this.

The second half is easier. To find the angle between your two rotations, you just perform a function like:

llAngleBetween(rot_a, rot_b); // The resulting value here can be 'maximum_angle'

Now that you know the range between the two, it's just a matter of modifying rot_a:

rot_a * llAxisAngle2Rot(axis, maximum_angle);

That should change the rotation of rot_a to match rot_b! And maximum_angle can be whatever you want. A range between 0.0 and maximum_angle.

llAngleBetween() only returns positive values, so you might have to negate the maximum_angle value.
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
Not an answer....
09-20-2008 08:24
...just vague advice.

first, be careful of your terminology. The angles around the x, y, and z axis are not the same as the 'rotation' type in SL.

Have you tried the simple approach?

If your final rotation is going to be

rot = llEuler2Rot( <x, y, z>;); //assuming radians


Then when you are half way, why not

rot = llEuler2Rot( 0.5*<x,y,z> );
_____________________
So many monkeys, so little Shakespeare.
BamBam Sachertorte
floral engineer
Join date: 12 Jul 2005
Posts: 228
09-20-2008 22:48
What you are trying to do is called a Slerp, or spherical linear interpolation. One of the great things about SL's quaternion representation for rotations is that this kind of smooth shift from one orientation to another is easy. Read this wikipedia entry for slerps. I don't know the details for implementing slerps in LSL, but it should just be some simple math.
Caoimhe Armitage
Script Witch
Join date: 7 Sep 2004
Posts: 117
09-28-2008 02:45
This is an old thread on the topic - mostly because I needed to revisit it myself and was pleased to see that this is still an issue that comes up for people. Francis Chung's comments at the end of the thread are probably the most practically useful.

/54/3b/50692/1.html
Debbie Trilling
Our Lady of Peenemünde
Join date: 17 Oct 2006
Posts: 434
09-28-2008 05:38
Thanks for all these contributions, especially for the 'slerp' reference in the first place and the link to how this could be done in LSL.

The 'slerp' calculations, although interesting, were above-my-head tbh, and the task of converting to LSL very daunting.

Francis Chung's post as given in the link from Caoimhe offers a relatively straightforward* function for returning the required rotation and I look forward to incorporating it into my script.

Many thanks.

EDIT: * straightforward to use, not necessarily straightforward to understand!
_____________________
http://wiki.secondlife.com/wiki/User:debbie_Trilling
Nexii Malthus
[Cubitar]Mothership
Join date: 24 Apr 2006
Posts: 400
09-28-2008 11:59
Well if interested I also made two SLERP variations, cosine and cubic.
https://wiki.secondlife.com/wiki/Interpolation
_____________________

Geometric Library, for all your 3D maths needs.
https://wiki.secondlife.com/wiki/Geometric

Creator of the Vertical Life Client