Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Simple Rotation

Jesu Forager
Registered User
Join date: 17 Oct 2007
Posts: 25
06-07-2008 13:10
Okay, this seems a simple problem but I've been scratching my head for an hour

I have an object rotating by using llLookAt, then stopping, after that I want it to use the difference between a set rotation and the current rotation of an avatar.

My question is how do I get the difference between the two second rotations. Basically I want to do

rot look
rot SET
rot current

llsetrot(look * (SET- current));

Any ideas?
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
06-07-2008 13:28
There is something called an inverse transformation, which always exists in the case of rotations. A rotation times its inverse (or vice versa) is always unity (like multiplying by 1). Note that you can write a rotation A as:

A = A*I = A*(inverse(B)*B) = (A*inverse(B))*B

So if you want a rotation that you can use to transform B into A, you are looking for A*inverse(B). Note however that rotations do NOT commute (A*B != B*A), so depending on what you are doing, you might also need:

A = I*A = (B*inverse(B))*A = B*(inverse(B)*A)

So there what you need is inverse(B)*A. LSL doesn't give us a direct function/operator to take an inverse, but using the division operator ('/') implicitly takes the inverse of the rotation on the right, so A*inverse(B) can be written in LSL as A/B, and inverse(B)*A can be written in LSL as (ZERO_ROTATION/B)*A.
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
Gold
06-07-2008 14:30
From: Hewee Zetkin
There is something called an inverse transformation, which always exists in the case of rotations. A rotation times its inverse (or vice versa) is always unity (like multiplying by 1). Note that you can write a rotation A as:

A = A*I = A*(inverse(B)*B) = (A*invserse(B))*B

So if you want a rotation that you can use to transform B into A, you are looking for A*inverse(B). Note however that rotations do NOT commute (A*B != B*A), so depending on what you are doing, you might also need:

A = I*A = (B*invserse(B))*A = B*(inverse(B)*A)

So there what you need is inverse(B)*A. LSL doesn't give us a direct function/operator to take an inverse, but using the division operator ('/') implicitly takes the inverse of the rotation on the right, so A*inverse(B) can be written in LSL as A/B, and inverse(B)*A can be written in LSL as (ZERO_ROTATION/B)*A.

This is gold! I have been missing these formulas! I have not been able to find anything but fragments of these in the wikis or in any other place. Here the magic is served on a silver plate!
A big thank you Hewee
_____________________
From Studio Dora
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
06-07-2008 14:53
Sure thing. I'm editing a couple minor misspellings. My fingers seem to very badly want to type 'insverse' or 'invserse' instead of 'inverse' today. Heh.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
06-07-2008 15:07
Note also that while there is no direct operator or function to determine the inverse of a rotation, both of the following should work if the input is a valid normalized rotation (x^2+y^2+z^2+s^2=1):

CODE

rotation inverse1(rotation r)
{
return ZERO_ROTATION/r;
}

rotation inverse2(rotation r)
{
return <-r.x, -r.y, -r.z, r.s>;
}