
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