Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Remembering/recreating relative orientations

Pedro McMillan
SLOODLE Developer
Join date: 28 Jul 2007
Posts: 231
07-02-2008 09:07
This should be a basic problem, but it's one that's making me go grey from frustration, so I'd appreciate a little help. :-)

One object (the Sloodle Set) can rez several others, and on-demand, it can instruct each object to store its position and rotation in an external database. These positions and rotations are relative to the Sloodle Set, so that the user can re-use the same layout in some other position/orientation later on.

Everything works fine except for the relative orientations: no matter what I've tried, it always gets them wrong (although it's consistent... it's not a random error, but obviously a flaw with my maths somewhere). Here's what happens: the Sloodle Set sends its root position (rezzerpos) and root rotation (rezzerrot) out to the objects in a chat message, and each object calculates its relative position and rotation like this:

// (executed inside individual rezzed objects)
vector relativepos = (llGetRootPosition() - rezzerpos) / rezzerrot;
rotation relativerot = llGetRootRotation() / rezzerrot;

These are stored in the database, and when it comes to rezzing them, the Sloodle Set calculates each object's position and rotation like this:

// (executed inside the Sloodle Set (the rezzer))
vector newpos = llGetRootPosition() + (relativepos * llGetRootRotation());
rotation newrot = relativerot * llGetRootRotation();

The newpos and newrot are then passed into a rezzing function, but it's not quite working right. If the Sloodle Set had a zero rotation when it stored the objects, then it is at least able to recreate the position of the rezzed objects correctly. Other than that, it's always making a bit of a mess! I haven't quite got my head round quaternions, so I highly suspect I've made the mess myself.

Any ideas?

Many thanks,
-Pedro
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
07-07-2008 15:57
I hate quaternions too, so I don't have a solution. But I may have a debugging suggestion. Start with one rezzed object. You know it works when the root rot is 0. So now try it with the root rotated 90 degrees around Z. You know where the rezzed object should go, you can see where it went instead - can you figure out what the error is? Then try 90 degrees around Z in the other direction. What happens now?

When I've had to debug this kind of stuff, I usually start out trying to work out the math, then I end up with "hmm, a * b didn't work, let's try b * a" :)