Jump to content

Having issues with HUD object re position


Crystarx
 Share

You are about to reply to a thread that has been inactive for 1543 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I have a hud attached that I am experimenting with and I want to move an object on the hud to the centre of my screen. That part is easy enough using a local pos variable based on the root prim position on the hud.

What I am finding a little more difficult is getting the object I am moving, to move to a central position on my hud view regardless of where the hud (root prim) is actually moved to. At the minute, if you move the hud elsewhere the "central" position changes. as its offset from the hud root prim locally.

How do I do this exactly?. I need the object to move to the centre regardless of where the hud is positioned

Edited by Crystarx
Link to comment
Share on other sites

See if this works:

default
{
    state_entry()
    {
        llSetTimerEvent(0.5);
    }
    on_rez(integer i)
    {
        llResetScript();
    }
    timer()
    {
        integer HUD_index = llListFindList([ATTACH_HUD_CENTER_2,ATTACH_HUD_TOP_RIGHT,ATTACH_HUD_TOP_CENTER,ATTACH_HUD_TOP_LEFT,ATTACH_HUD_CENTER_1,ATTACH_HUD_BOTTOM_LEFT,ATTACH_HUD_BOTTOM,ATTACH_HUD_BOTTOM_RIGHT],[llGetAttached()]);
        if (~HUD_index)
        {
            vector HUD_center_position = llList2Vector([<0.0,0.0,0.0>,<0.0,1.0,-0.5>,<0.0,0.0,-0.5>,<0.0,-1.0,-0.5>,<0.0,0.0,0.0>,<0.0,-1.0,0.5>,<0.0,0.0,0.5>,<0.0,1.0,0.5>],HUD_index);
            list GLPP = llGetLinkPrimitiveParams(1,[PRIM_POS_LOCAL,PRIM_ROT_LOCAL]);
            vector target_direction = <-1.0,0.0,0.0>;
            vector r2f = llRot2Fwd(llRotBetween(<1.0,0.0,0.0>,llVecNorm(target_direction)));
            llSetLinkPrimitiveParamsFast(2,[
                PRIM_ROT_LOCAL,(llEuler2Rot(<0.0,llAsin(-r2f.z),0.0>) * llEuler2Rot(<0.0,0.0,llAtan2(r2f.y,r2f.x)>)) / llList2Rot(GLPP,1),
                PRIM_POS_LOCAL,(HUD_center_position - llList2Vector(GLPP,0)) / llList2Rot(GLPP,1)]);
        }
    }
}

This "should" move and orientate link #2 to the center position on the screen regardless of the root's rotation, position and HUD attach point.

Its set up to face the forward x axis towards you. If you want it to face a different direction you will have to edit the "target_direction" vector.

[EDIT] Posted without testing the top & bottom left & right attach point center positions and was burned. Should be fixed now.

This is good for keeping a "maximize" or "bring back on screen" button on screen in case a user moves the HUD out of the way off-screen or attaches to a new HUD slot which could lead it to being off-screen as well.

It's also good for keeping single prim, child HUD's in a master HUD linkset or toolbar aiming towards you no matter how the user rotated the root.

Edited by Lucia Nightfire
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1543 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...