Adjust sitting target hell...
|
|
Marcel Flatley
Sampireun Design
Join date: 29 Jul 2007
Posts: 2,032
|
05-16-2009 04:14
Okay, kind of hard to explain, but here we go.
I have a prim with a sit target. The prim does have a rotation, and I do know in my script the current pos and rot. Now I want to adjust the position of the avatar in x y and z direction. So what I basically did is make a menu, resulting in an adaption of x, y, z. Then I use the script UpdateSitTarget from the wiki, to adapt the position.
Example: pos = <-0.03800, 0.27868, 0.19616> rot = <0.00000, 0.00000, 0.77713, 0.62934>
User chooses to go 0.1 UP, so I give the UpdateSitTarget the parameters: pos = <-0.03800, 0.27868, 0.29616> rot = <0.00000, 0.00000, 0.77713, 0.62934>
Well the move is done, but it seems that the rotation of the prim is not taken into account. The avatar is moved into unpredictable directions, depending the rotation of the prim.
Somehow I do not grasp the whole position/rotation thing... so I do not have a clue where to start solving this.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
05-16-2009 10:32
Please see this thread: /54/8d/320853/1.html
|
|
ashtangajoy Kanya
Registered User
Join date: 27 Jan 2009
Posts: 11
|
incorrect quaternion?
05-17-2009 03:06
Is your rot a correct/valid rotation? The first three components of the quaternion should have unit size - generally should be of form < sin(theta/2)*< n.x , n.y , n.z > , cos(theta/2) > for theta rotation about unit vector n
|
|
Marcel Flatley
Sampireun Design
Join date: 29 Jul 2007
Posts: 2,032
|
05-17-2009 13:55
Thanks you both  I found a script that does things similar to what I want, and indeed they use formulas quite different from mine. Are going to implement those formulas now, to see whether they do better!
|
|
Harmony Levee
Registered User
Join date: 8 Dec 2008
Posts: 189
|
05-17-2009 19:10
I see you found something but personally I use the HEZ sit target positioner, really nice and easy accompainied with another thingie majingie(forgot its name but combined basically you just drag yourself to where you want to be posed, hit the button, its sets the quardinates and presto, done.
|
|
Marcel Flatley
Sampireun Design
Join date: 29 Jul 2007
Posts: 2,032
|
05-18-2009 05:04
My problem is not in positioning, I have a great tool for that, Learjef Innis developed that if my mind doesn't play me tricks. The problem that not all avatars have the same size, so if I tune the sit target for my avatar, others might have a wrong position. I am creating a section in my main script (which also takes care of color/texture changes, and multiple animations to choose from), where one can adjust their position. And there lies the trick: I cannot get it right! The script I found does put me in the right direction, but still doesn't do as I want. Imagine the sitting target on a prim that is a child prim in the linkset. The prim almost always has a rotation, and the parameters of the sit target is adjusted to that rotation. The avatar of course always sits head up, back towards the back of the seat. Now no matter what I try, the left-right, up-down, and front-back motions do not work. I implemented the following script to see if it does as I want, but still no succes if the prim with the sit target is rotated: // This script was mainly made of Strife & Escort's UpdateSitTarget function. // And I learned the way of detecting the avatar positon from Qui Niangao's mass. // Tonkotsu Nico & Shizuna Jeffries helped to create. // Thanks all guys. key av; vector currentPos; rotation currentRot; integer touchFlag; //Sets / Updates the sit target moving the avatar on it if necessary. UpdateSitTarget(vector pos, rotation rot) { llSitTarget(pos, rot);//Set the sit target key user = llAvatarOnSitTarget(); if(user)//true if there is a user seated on the sittarget, if so update their position { vector size = llGetAgentSize(user); if(size)//This tests to make sure the user really exists. { //We need to make the position and rotation local to the current prim rotation localrot = ZERO_ROTATION; vector localpos = ZERO_VECTOR; if(llGetLinkNumber() > 1)//only need the local rot if it's not the root. { localrot = llGetLocalRot(); localpos = llGetLocalPos(); } pos.z += 0.4; integer linkNum = llGetNumberOfPrims(); do{ if(user == llGetLinkKey( linkNum ))//just checking to make sure the index is valid. { llSetLinkPrimitiveParams(linkNum, [PRIM_POSITION, ((pos - (llRot2Up(rot) * size.z * 0.02638)) * localrot) + localpos, PRIM_ROTATION, rot * localrot / llGetRootRotation()]); jump end;//cheaper but a tad slower then return } }while( --linkNum ); } else {//It is rare that the sit target will bork but it does happen, this can help to fix it. llUnSit(user); } } @end; } //Written by Strife Onizuka, size adjustment provided by Escort DeFarge default { state_entry() { llSitTarget(<0, 0, 0.25>, ZERO_ROTATION); } changed(integer change) { av = llAvatarOnSitTarget(); if(av == NULL_KEY) { if(llGetPermissions() & PERMISSION_TAKE_CONTROLS) { llReleaseControls(); } } } touch_start(integer num_detected) { if(av == llDetectedKey(0)) { if(!touchFlag) { vector avPos = llDetectedPos(0); rotation avRot = llDetectedRot(0); vector avSize = llGetAgentSize(llDetectedKey(0)); vector heightGlitch = <0, 0, (avSize.z/37.9)>; vector primPos = llGetPos(); rotation primRot = llGetRot(); currentPos = (avPos + heightGlitch*avRot - primPos) / primRot - < 0, 0, 0.4>; currentRot = avRot / primRot; llRequestPermissions(av, PERMISSION_TAKE_CONTROLS); } else { if(llGetPermissions() & PERMISSION_TAKE_CONTROLS) { llReleaseControls(); llWhisper(0, "UpdateSitTargget has been deactivated."); } } touchFlag = !touchFlag; } } run_time_permissions(integer perms) { integer desired_controls = CONTROL_FWD | CONTROL_BACK | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_ROT_LEFT | CONTROL_ROT_RIGHT | CONTROL_UP | CONTROL_DOWN; if(perms & PERMISSION_TAKE_CONTROLS) { llWhisper(0, "UpdateSitTargget has been activated."); llTakeControls(desired_controls, TRUE, FALSE); } } control(key id, integer level, integer edge) { if(level & CONTROL_FWD) { currentPos = currentPos + (llRot2Fwd(llGetRot())/10); } else if(level & CONTROL_BACK) { currentPos = currentPos - (llRot2Fwd(llGetRot())/10); } else if(level & CONTROL_LEFT) { currentRot = llGetRot() + (currentRot * llEuler2Rot(<0, 0, -10> * DEG_TO_RAD)); } else if(level & CONTROL_RIGHT) { currentRot = llGetRot() + (currentRot * llEuler2Rot(<0, 0, 10> * DEG_TO_RAD)); } else if(level & CONTROL_ROT_LEFT) { currentPos = currentPos + (llRot2Left(llGetRot())/10); } else if(level & CONTROL_ROT_RIGHT) { currentPos = currentPos - (llRot2Left(llGetRot())/10); } else if(level & CONTROL_UP) { currentPos = currentPos + llRot2Up(llGetRot())/10; } else if(level & CONTROL_DOWN) { currentPos = currentPos - (llRot2Up(llGetRot())/10); } UpdateSitTarget(currentPos, currentRot); llSleep(0.1); } }
|
|
Marcel Flatley
Sampireun Design
Join date: 29 Jul 2007
Posts: 2,032
|
05-18-2009 15:02
Okay I discovered something I should be able to solve... The above script DOES work, but left-right and forward-back are working exactly against the X and Y axis of the prim. So probably this must be adjustable so it always works... will take some testing though. If anyone knows what goes wrong in the script above (it should adapt to rotation in the prim), I would be happy to hear it!
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
05-18-2009 23:21
I'll be perfectly honest I read your previous post (#6) and I couldn't understand what the problem was or what you were trying to do. the script looks vaguely like you are taking controls to shift the avatar around and then to reset the sit target for them.
a few thoughts because I'm half awake and not up to digging.
llSetLinkPrimitiveParams used on the av will get and return their offset from the root in root local coordinates. same with the rotation (beware of SVC-93). the reference point for an av is the center of their hips. nothing else.
all changes should be applied as offsets, and rotated by the av's relative rotation, BEFORE being applied to that local frame of reference..
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Marcel Flatley
Sampireun Design
Join date: 29 Jul 2007
Posts: 2,032
|
05-19-2009 13:20
Hiya Void, Thanks for looking! It is kind of hard to describe anyway. Say I have a chair based on a hollowed and cut cube, looks like an L. The rotation can be in and direction, I never know in what direction the buyer puts the chair. Now I set the sit target and animation, and I want to enable the user (sitter) to adjust their position (not all avatars are the same size). The script above I used as reference, I do not want to use the key controls, but if the user chooses left or right, that movement needs to be parallel to the seats back. Front/back needs to move away/towards the back of the seat. Up/down is obvious  Whatever I tried so far did not result in what I wanted, the movement is always the same direction. So if I rotate the seat 90 degrees, left/right changes in forward/back. Hope to have clarified it a bit 
|