Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Draggable HUD Help

Siann Beck
Beauty & Braiiiiinsss!
Join date: 14 Jul 2007
Posts: 140
12-14-2008 18:51
I want to have a HUD object that can be easily re-positioned on the screen. Here's what I have:

CODE

vector vecPos;
vector vecPrevDelta;

default
{
state_entry() {
vecPos = llGetLocalPos();
}

touch(integer intDetected) {
vector vecCurrDelta = llDetectedGrab(0);
vector vecDelta = vecCurrDelta - vecPrevDelta;

float fltDeltaY = (-1.0 * vecDelta.y) / 10.0;
float fltDeltaZ = (-1.0 * vecDelta.x) / 10.0;

vecPrevDelta = vecCurrDelta;

if (fltDeltaY > 0.5 || fltDeltaZ > 0.5) { return; }

vecDelta = <0.0, fltDeltaY, fltDeltaZ>;

vecPos+= vecDelta;

llSetPos(vecPos);
}

touch_end(integer intDetected) {
vecPrevDelta = ZERO_VECTOR;
}
}


I have to confess, having never worked in a 3D environment before last year, I'm still fairly hopeless with vectors and such, and came up with this code by observing the return values of llDetectedGrab() and lots of trial and error. It works, sort of, but does not move very smoothly, and is rather clunky. This line, for example:

CODE

if (fltDeltaY > 0.5 || fltDeltaZ > 0.5) { return; }


is there because I observed that I always got a large delta value at the beginning of each touch, and don't know why. Also, since with HUD attachments, llDetectedGrab() is relative to the direction the avatar's facing, it only works at all if you're facing due west. Can anyone offer suggestions for improvement?
_____________________
Help find a missing child.
Nexii Malthus
[Cubitar]Mothership
Join date: 24 Apr 2006
Posts: 400
12-14-2008 22:45
You need to get the grab on a local coords to the camera. First request permissions to PERMISSION_TRACK_CAMERA from owner.

Then do
CODE

vector vecCurrDelta = llDetectedGrab(0) / llGetCameraRot();

This will help get you get the grab vector relative to your screen instead.
_____________________

Geometric Library, for all your 3D maths needs.
https://wiki.secondlife.com/wiki/Geometric

Creator of the Vertical Life Client
Siann Beck
Beauty & Braiiiiinsss!
Join date: 14 Jul 2007
Posts: 140
12-15-2008 13:18
Thanks Nexii, that worked perfectly. Were the libraries you linked to intended as part of the reply? They look interesting. Would any of the functions apply to this operation?

Edit: Interestingly, it appears PERMISSION_TRACK_CAMERA is automatically granted for attachments. I tested it with myself, an alt and a friend, and it did not present the permission dialog.
_____________________
Help find a missing child.
Nexii Malthus
[Cubitar]Mothership
Join date: 24 Apr 2006
Posts: 400
12-15-2008 22:27
Oh no, the libraries weren't linked to the post, they are part of my signature.

Wow, wait tracking camera doesn't give a request permissions anymore? Sweet.

Oh and I think I might have a HUD window that could be dragged around in a similiar way. Lemme see if I can grab the code and post it.

CODE

vector Start; integer First;

default{
state_entry(){
llRequestPermissions( llGetOwner(), PERMISSION_TRACK_CAMERA );
}

touch_start( integer d ){
Start = llGetLocalPos( );
First = TRUE;
}

touch( integer d ){
if( First ){ First = FALSE; return; }
vector Grab = llDetectedGrab(0);
if( llDetectedLinkNumber(0) == LINK_ROOT ){
if( Grab.x > 5.0 || Grab.x < -5.0)
Grab += llGetRootPosition();
Grab -= Start;
}

Grab /= llGetCameraRot();
Grab = Start + Grab;
Grab.x = 0.0; Grab.y /= 6.0; Grab.z /= 4.0;
llSetText( (string)Grab, <1,1,1>, 1.0 );
llSetPos( Start + Grab );
}
}


This is as close to realism I could get.
_____________________

Geometric Library, for all your 3D maths needs.
https://wiki.secondlife.com/wiki/Geometric

Creator of the Vertical Life Client
Nexii Malthus
[Cubitar]Mothership
Join date: 24 Apr 2006
Posts: 400
12-15-2008 23:22
Interesting, seems like PERMISSION_TRACK_CAMERA is only automatically granted to the root prim of the attachment. A dialog is still called for children.

Actually, going to go forward and post my script to the scripting library.
_____________________

Geometric Library, for all your 3D maths needs.
https://wiki.secondlife.com/wiki/Geometric

Creator of the Vertical Life Client
Ima Huckleberry
Registered User
Join date: 28 Nov 2008
Posts: 29
12-16-2008 12:20
You mean right-click, edit and reposition is not easy? LMAO :rolleyes:
Nexii Malthus
[Cubitar]Mothership
Join date: 24 Apr 2006
Posts: 400
12-17-2008 00:14
Yeah, right click edit and reposition is really not easy if the build-editting doesn't behave normally as on the ground. For instance the arrows are only grabbable on their arrow heads than what would intuitively be along their entire axis length of the arrow. Very annoying! I would prefer an instant intuitive control of a grabbable window bar of a HUD any day, and that is coming from someone who has been building in SL for years.
_____________________

Geometric Library, for all your 3D maths needs.
https://wiki.secondlife.com/wiki/Geometric

Creator of the Vertical Life Client
Siann Beck
Beauty & Braiiiiinsss!
Join date: 14 Jul 2007
Posts: 140
12-20-2008 18:24
From: Nexii Malthus
Oh and I think I might have a HUD window that could be dragged around in a similiar way. Lemme see if I can grab the code and post it.

Thanks, Nexii. I wasn't able to try it until now. It's not working for me; as soon as I start dragging, the HUD snaps to a position WAY below the window, so I have to zoom out almost all the way to see it. I didn't spend a whole lot of time with it, though; unless I'm missing something, it looks to be essentially the same as what I have.
_____________________
Help find a missing child.
Siann Beck
Beauty & Braiiiiinsss!
Join date: 14 Jul 2007
Posts: 140
12-20-2008 18:28
From: Ima Huckleberry
You mean right-click, edit and reposition is not easy? LMAO :rolleyes:

It does, but I wanted to make something simpler for those who might be afraid to go into edit mode on the HUD, or not even be familiar with it, etc. I know it sounds weird, but even in SL some people are very technophobic. Some of my products use a full-perm script for their configuration, rather than a note card, and I've found that some people simply won't touch it, despite very clear instructions and assurances that they can't mess up anything.
_____________________
Help find a missing child.