OsGetSitTargetPos
From OpenSimulator
Jump to navigationJump to search
vector osGetSitTargetPos()
| |
| Return the sit target location as set by llSitTarget. | |
| Threat Level | This function does not do a threat level check |
| Permissions | Use of this function is always allowed by default |
| Extra Delay | 0 seconds |
| Example(s) | |
// Unit test : Writing then reading SitTarget
default
{
state_entry()
{
vector write_pos = <1,2,3>;
vector write_rot = <4,5,6>;
llSitTarget (write_pos, llEuler2Rot(write_rot * DEG_TO_RAD));
vector read_pos = osGetSitTargetPos();
vector read_rot = llRot2Euler (osGetSitTargetRot()) * RAD_TO_DEG;
llOwnerSay (read_pos);
llOwnerSay (read_rot);
}
}
[12:45] Object: <1.000000, 2.000000, 3.000000>
[12:45] Object: <4.000000, 5.000000, 6.000000>
// Sit Adjuster, Jeff Kelley, 2024
//
// This script allows interactive adjustment of the sit position.
// Put the script in a seat, then sit. Mode (POSITION or ROTATION),
// avatar position and avatar rotation are displayed in green.
// Adjust the position using the arrow keys + PageUp/PageDown.
// Once satisfied, click on the seat to enter ROTATION mode
// and adjust the rotation. Toggle between POSITION and ROTATION
// as many times as necessary. Finally, standup. The new sittarget
// is now written, and the script deletes itself.
//
// PLEASE NOTE - It is strongly advised to disable the setting :
// Preferences > Move&View > Reset camera position on avatar movement
// so the camera won't jump when you hit the arrow keys.
////////////////////
// Avatar ajustement
////////////////////
integer MODE;
integer MODE_POS = 0;
integer MODE_ROT = 1;
float increment = 0.005; // The smaller, the slower
vector DELTA_X = < 1, 0, 0 > * increment;
vector DELTA_Y = < 0, 1, 0 > * increment;
vector DELTA_Z = < 0, 0, 1 > * increment;
vector AvatarPos; // Memorize last position
rotation AvatarRot; // Memorize last rotation
vector GetAvatarPos()
{
integer nprims = llGetNumberOfPrims(); // Last link = avatar
list l = llGetLinkPrimitiveParams (nprims, [PRIM_POS_LOCAL]);
AvatarPos = llList2Vector (l,0);
return AvatarPos;
}
rotation GetAvatarRot()
{
integer nprims = llGetNumberOfPrims(); // Last link = avatar
list l = llGetLinkPrimitiveParams (nprims, [PRIM_ROT_LOCAL]);
AvatarRot = llList2Rot (l,0);
return AvatarRot;
}
SetAvatarPos(vector pos)
{
integer nprims = llGetNumberOfPrims(); // Last link = avatar
llSetLinkPrimitiveParamsFast (nprims, [PRIM_POS_LOCAL, pos]);
}
SetAvatarRot(rotation rot)
{
integer nprims = llGetNumberOfPrims(); // Last link = avatar
llSetLinkPrimitiveParamsFast (nprims, [PRIM_ROT_LOCAL, rot]);
}
Move(vector deltapos, vector deltarot)
{
if (MODE == MODE_POS)
SetAvatarPos (GetAvatarPos() + deltapos);
if (MODE == MODE_ROT)
SetAvatarRot (GetAvatarRot() * llEuler2Rot(deltarot));
DisplayInfos();
}
///////////////////////////////
// Sit/Unsit, keyboard bindings
///////////////////////////////
integer KeysToBind = CONTROL_FWD | CONTROL_BACK | CONTROL_ROT_LEFT
| CONTROL_ROT_RIGHT | CONTROL_UP | CONTROL_DOWN;
vector drift;
Sit ()
{
key avatar = llGetPermissionsKey();
llTakeControls (KeysToBind, TRUE, FALSE);
MODE = MODE_POS;
DisplayUsage();
DisplayInfos();
drift = osGetSitTargetPos() - GetAvatarPos();
}
Unsit ()
{
key avatar = llGetPermissionsKey();
llSitTarget (AvatarPos+drift, AvatarRot);
llReleaseControls ();
DisplayClear();
llRemoveInventory (llGetScriptName());
}
//////////
// Display
//////////
DisplayClear()
{
llSetText ("", <0,1,0>, 1.0);
}
DisplayInfos()
{
string text;
vector color;
GetAvatarPos();
GetAvatarRot();
if (MODE == MODE_POS)
{
text = "MODE POSITION";
color = <0,1,0>;
}
if (MODE == MODE_ROT)
{
text = "MODE ROTATION";
color = <1,1,0>;
}
text += "\n" + (string) AvatarPos;
text += "\n" + (string) (llRot2Euler(AvatarRot)*RAD_TO_DEG);
llSetText (text, color, 1.0);
}
DisplayUsage()
{
llWhisper (0, "Use arrow keys + PageUP/PageDown");
llWhisper (0, "to adjust avatar position in X, Y and Z");
llWhisper (0, "Click the seat to toggle between position ane rotation");
llWhisper (0, "Standup to record the parameters in your seat");
}
/////////////////
// Event handlers
/////////////////
default
{
state_entry()
{
// If the seat has a previous sittarget, use it as a starting point.
// Else, define a random sittarget for llAvatarOnSitTarget to work.
vector sitPos = osGetSitTargetPos();
rotation sitRot = osGetSitTargetRot();
if (sitPos == ZERO_VECTOR)
{
sitPos = <0,0,1.0>;
sitRot = ZERO_ROTATION;
}
llSitTarget (sitPos, sitRot);
DisplayClear();
}
changed(integer change)
{
if (change & CHANGED_LINK)
{
key whosit = llAvatarOnSitTarget();
if (whosit == NULL_KEY) Unsit ();
else llRequestPermissions (whosit, PERMISSION_TAKE_CONTROLS);
}
}
run_time_permissions(integer perms)
{
if (perms == PERMISSION_TAKE_CONTROLS) Sit();
}
touch_start (integer n)
{
MODE = ! MODE;
DisplayInfos();
}
control (key id, integer level, integer edge)
{
integer start = level & edge;
integer end = ~level & edge;
if (level & CONTROL_FWD) { Move( DELTA_X, DELTA_Y); } // Up arrow
if (level & CONTROL_BACK) { Move(-DELTA_X, -DELTA_Y); } // Down arrow
if (level & CONTROL_ROT_LEFT) { Move( DELTA_Y, DELTA_Z); } // Left arrow
if (level & CONTROL_ROT_RIGHT) { Move(-DELTA_Y, -DELTA_Z); } // Right arrow
if (level & CONTROL_UP) { Move( DELTA_Z, DELTA_X); } // Page up
if (level & CONTROL_DOWN) { Move(-DELTA_Z, -DELTA_X); } // Page down
}
}
| |
| Notes | |
| This function was added in 0.9.3.0 | |