Positioning & Rotating Seated Avatar - Standalone Prim vs Child Prim
|
|
Cyd Woolley
Carpe Cerevisiam
Join date: 6 Jan 2007
Posts: 21
|
09-17-2007 22:03
Below is a function in a poseball script I am working on. It is called immediately after an avatar has sat upon the prim containing the script. The function's purpose is to change the orientation (position and rotation) of the seated avatar relative to the prim. The function works perfectly when the containing prim is a standalone prim (i.e., it is not linked to other prims). When I link it as a child prim in a linkset, the seated avatar ends up facing 180 degrees the wrong way, and the avatar's position is slightly shifted to one side. In this scenario, the child prim has a global rotation of <0, 0, 90> and the root prim has a global rotations of <0, 0, 0> (as seen in the Edit window). I believe my difficulties have something to do with child rotations vs global rotations, but I am struggling. I am especially confused by the avatar being shifted to one side in the child prim scenario. I have searched through this forum for clues, but I'm failing to find a way to make the function work correctly in both the standalone and child prim scenarios. I assume the function need some additional rotation logic that is conditionally executed when the containing prim is a child in a linkset. (Like the similar conditional logic for position that is already in place.) Guidance would be greatly appreciated. Thanks!
setAvatarOrientation(vector offset, vector spin) { // example offset value: <0.5, 0, 0> // example spin value: <0, 0, 0> (euler representation in degrees)
vector pos = offset; if(llGetLinkNumber() > 1) pos += llGetLocalPos();
vector localRot = llRot2Euler(llGetRot()) * RAD_TO_DEG; vector eul = (spin - localRot) * DEG_TO_RAD; rotation rot = llEuler2Rot(eul);
vector size = llGetAgentSize(avatar); pos.z += (size.z * 0.5); integer av = llGetNumberOfPrims(); llSetLinkPrimitiveParams(av, [PRIM_POSITION, pos, PRIM_ROTATION, rot]); }
|
|
Simil Miles
Creator
Join date: 1 Mar 2007
Posts: 300
|
09-18-2007 11:29
Make sure that you're always rotating the avatar and not the prim it sits on.
_____________________
UnConWTech @ Flo (144, 84, 224) http://unconwtech.free.fr
SL books http://astore.amazon.com/secondlife-sl-20/
Need a beta tester for quality assurance ? Need a translator for English, French, Spanish ?
|
|
Cyd Woolley
Carpe Cerevisiam
Join date: 6 Jan 2007
Posts: 21
|
09-18-2007 12:55
The last 2 lines of the function position and rotate the last prim in the linkset, which is the seated avatar. The problem is that the position and rotation of the avatar is not right when the containing prim is a child in a linkset.
|
|
Simil Miles
Creator
Join date: 1 Mar 2007
Posts: 300
|
09-18-2007 13:51
I'm not sure but I think that the avatar becomes link number 2.
_____________________
UnConWTech @ Flo (144, 84, 224) http://unconwtech.free.fr
SL books http://astore.amazon.com/secondlife-sl-20/
Need a beta tester for quality assurance ? Need a translator for English, French, Spanish ?
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
09-18-2007 16:34
This may take a fair bit of straightening out, but before trying to do that, just want to be sure that there's a reason to work this hard. That is: there's some need of the application that's not satisfied just by putting a sit target in each child prim? (I see the attempted adjustment-by-height, but that could be applied after a sit target has taken effect, so...). Anyway, on the assumption that the avatar's position will be some function computed every time someone sits (or possibly *while* they're sitting), it seems that the "offset" and "spin" arguments to setAvatarOrientation() are intended to be expressed in the coordinate system of the scripted prim, whether or not that prim is root--is that right? In general, I think the problem being observed is that offsets, too, have to be corrected for rotation of their frame of reference--which may not be the same as the coordinate system in which they're most simply expressed. In the case of the avatar "sitting on" a child prim, it's doubly complicated because the avatar is really a child of the root prim--that's its frame of reference--so it has to be rotated according to "spin" relative to the child prim, and to the rotation of the child prim relative to the root, and to the root prim's own rotation. Moreover, the avatar's offset is expressed in terms of the child prim's position and orientation, which is itself a rotated offset from the root prim's origin. So, all this is possible (with the added vagaries of  ), but it won't be easy to keep straight all these frames of reference, so best to be sure llSitTarget() won't suffice for the intended application.
|
|
Cyd Woolley
Carpe Cerevisiam
Join date: 6 Jan 2007
Posts: 21
|
09-19-2007 05:19
Thanks for the thoughtful post Qie. Yes, the arguments to setAvatarOrientation() ARE INDEED intended to be expressed in the coordinate system of the scripted prim, whether or not that prim is root. I think you've accurately identified the issue I am facing when you mentioned having to correct for the offset too due to the different frames of reference involved. That is what I am struggling to achieve in a generic fashion within this function. As for questioning the need to do all this instead of just using sit targets, yes, the overall script I am working on does need to make these offset/rotation adjustments after the avatar has sat upon the containing prim. This capability is the primary reason for the script, in fact. So, no easy way out on this one.  It was a perfectly reasonable question though. I am still working on this problem, so further input from you (or others) is welcome.
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
09-20-2007 09:04
From: Cyd Woolley So, no easy way out on this one. I was kinda afraid of that.  Hope this is close to what's desired: setAvatarOrientation(vector offset, vector spin) { rotation spinRot = llEuler2Rot(spin * DEG_TO_RAD); rotation primRot; vector primOffset; if (llGetLinkNumber() > 1) { primOffset = llGetLocalPos(); primRot = llGetLocalRot(); } else { primOffset = ZERO_VECTOR; primRot = ZERO_ROTATION; } integer av = llGetNumberOfPrims(); vector size = llGetAgentSize(llGetLinkKey(av)); offset.z += (size.z * 0.5); vector pos = primOffset + (offset * primRot);
rotation rot = spinRot * primRot / llGetRootRotation();
llSetLinkPrimitiveParams(av, [PRIM_POSITION, pos, PRIM_ROTATION, rot]); }
default { changed(integer change) { if ((change & CHANGED_LINK) && llGetAgentInfo(llGetLinkKey(llGetNumberOfPrims()))) setAvatarOrientation(<0.0, 0.5, 0>, <0,0,90>); } }
|
|
Cyd Woolley
Carpe Cerevisiam
Join date: 6 Jan 2007
Posts: 21
|
09-21-2007 03:05
Yes yes yes! Your updated version of setAvatarOrientation() works beautifully in both the linked and unlinked scenarios! Thanks very much Qie!
|