Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Functions to accurately set local position and rotation

Huns Valen
Don't PM me here.
Join date: 3 May 2003
Posts: 2,749
06-27-2004 17:58
llSetPos() and llSetRot() are world-relative, whether they are used on an object itself or on child prims in its link set. This is causing a problem for a jet I am working on, which has child prims that can change their position and rotation. If I am flying in a straight line (at any angle) the repositioning works correctly. However, if they change position when the aircraft is changing direction, the repositioning is thrown off by a visible amount. I have to sample the rotation of the aircraft and perform some quaternion math before I have good numbers for llSetRot() and llSetPos(), and the results I get are stale by the time they are applied.

What I would like is a set of functions that take local positions and rotations relative to the object:
llSetLocalPos(vector pos);
llSetLocalRot(vector rot);
llSetLocalPosAndRot(vector pos, rotation rot); // simultaneous

The local positions and rotations fed into these functions would be relative to the object, not the world (so the developer would sample them at zero rotation.) The link set would be adjusted regardless of object rotation.
Eggy Lippmann
Wiktator
Join date: 1 May 2003
Posts: 7,939
06-27-2004 18:42
Isnt your llSetLocalRot the same as llSetRot(newrot*llGetLocalRot())?
Huns Valen
Don't PM me here.
Join date: 3 May 2003
Posts: 2,749
06-27-2004 20:55
It is this:

setLocalRot(rotation rot) {
    rotation localRot = llGetLocalRot();
    rotation parentRot = llGetRot();
    localRot.s = -localRot.s;
    parentRot = localRot * parentRot;
    parentRot.s = -parentRot.s;
    llSetRot(rot * parentRot);
}

You have to go through all this because llSetRot() is relative to the world, instead of the object. If your object is at zero rotation all the time you don't have to do this, but for a vehicle it's necessary. There is a delay inherent in this even without several lines of math, since it takes time to sample the rotation and to set the new rotation.

I did have the thought of building some prediction into this, but since the vehicle changes direction on an exponential curve (not linear) it would be difficult.
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
06-27-2004 21:17
I totally agree with you Huns, but I think instead of functions being added, I'd rather like to see more constants for the llSetPrimitiveParams function.

This way, only two constants need to be added, vs. three functions. (You can set the position and rotation seperately or both at the same time with llSetPrimitiveParams.)
Ezhar Fairlight
professional slacker
Join date: 30 Jun 2003
Posts: 310
06-28-2004 08:26
llSetPos is root-relative for child prims.

llSetRot is not, but here is a function that is:
CODE
SetLocalRot(rotation localrot) {
llSetRot(localrot / ( (ZERO_ROTATION / llGetLocalRot()) * llGetRot()));
}


It's probably a bit faster, but doesn't really fix your problem with the change of rotation while the function executes. I agree that there should be a LSL function to directly set the local rotation.
_____________________
Huns Valen
Don't PM me here.
Join date: 3 May 2003
Posts: 2,749
06-28-2004 15:59
From: someone
Originally posted by Christopher Omega
I totally agree with you Huns, but I think instead of functions being added, I'd rather like to see more constants for the llSetPrimitiveParams function.

This way, only two constants need to be added, vs. three functions. (You can set the position and rotation seperately or both at the same time with llSetPrimitiveParams.)
Either way is fine with me.