Jump to content

HUD arrow pointing at inworld object.


TonyBowlin
 Share

Recommended Posts

My goal is to have an arrow on my HUD pointing to various objects in the world depending on the object selected. Thus far I've only managed to get the arrow HUD to point north as I'm walking around and moving the camera about. The objective is for the arrow to always point at checkpoints as I'm moving around the inworld in a vehicle with mouselook-steering. My knowledge of trigonometry is zero. Any help would be greatly appreciated.

 

timer()
    {

        vector c_pos = llGetCameraPos(); //Get Users Camera Position
        rotation c_rot = llGetCameraRot(); //Get Users Camera Rotation
        
        rotation p_arc = llEuler2Rot( c_pos * DEG_TO_RAD );//Player pos arc
        rotation b_arc = llEuler2Rot( b_pos * DEG_TO_RAD );//Object POS ARC
        rotation c_arc = llEuler2Rot( c_pos  *DEG_TO_RAD );//CAMERA POS ACH

        llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_ROTATION, (   (ZERO_ROTATION / c_rot )   )]);//This always point the arrow HUD north. It needs to always point at the object or b_pos while moving throughout the sim and as I'm looking around in mouselook.
        

    }

Link to comment
Share on other sites

This is not what my design has intended. This only moves the HUD object to the position on the inworld object within view. My intent is to have a 3d mesh arrow rotate on the HUD to point at the inworld object. The llWorldPosToHUD outputs position values that are specific to HUD positions which I'm not adjusting per design. Thanks for the suggestion though. =D

Link to comment
Share on other sites

Objects on your HUD are in isometric perspective, which means it's impossible to make a 3d HUD that perfectly points at an object and doesn't look a little off, but exaggerating the closeness of the target when it's in front of you seems to work decently:

key inworld_object = "a10a343b-ec44-cd27-1898-3c15d8f4622b";
float distance_factor_forwards = 0.1;
float distance_factor_backwards = 1.0;

rotation rINTRINSIC; // see https://community.secondlife.com/forums/topic/472730-rotations/?do=findComment&comment=2713790 for how to set this value propperly. 
uLookAt(vector direction, float roll) // to look at a specific position in-world, set direction to (position-llGetPos())
{   rotation look = // inline YPR2Rot() 
        llAxisAngle2Rot(<1,0,0>, roll) *
        llAxisAngle2Rot(<0,1,0>, 
            -llAtan2(direction.z,llVecMag(<direction.x,direction.y,0>)) )*
        llAxisAngle2Rot(<0,0,1>, llAtan2(direction.y,direction.x) ) ;
        
    llSetLinkPrimitiveParamsFast((llGetNumberOfPrims()>1), // root prim being 0 or 1 is dumb.
    [   PRIM_ROT_LOCAL, (ZERO_ROTATION/rINTRINSIC)*look
    ]);
}

default
{
    state_entry()
    {   rINTRINSIC = llEuler2Rot(DEG_TO_RAD*<0,270,0>);
        llSetTimerEvent(1.0);
    }
    timer()
    {   if(llGetPermissions()&PERMISSION_TRACK_CAMERA)
        {   vector pObj = llList2Vector(llGetObjectDetails(inworld_object,[OBJECT_POS]),0);
            vector point_to = llWorldPosToHUD(pObj);
            vector pCam = llGetCameraPos();
            
            point_to.x *= llVecMag(pObj-pCam);
            
            // position results for objects behind the camera are funny.
            if(point_to.x<0)
            {   point_to.z = -point_to.z;
                point_to.y = -point_to.y;
                point_to.x *= distance_factor_backwards;
            }else
            {   point_to.x *= distance_factor_forwards;
            }
            
            uLookAt(point_to-llGetLocalPos(), 0.0 );
            
        }else
        {   llRequestPermissions(llGetOwner(),PERMISSION_TRACK_CAMERA);
        }
    }
}

 

Edited by Quistess Alpha
  • Confused 1
Link to comment
Share on other sites

A while back, Chalice Yao posted a neat little snippet with explanations on the VVO forums. Her example uses two llRotBetween calls to essentially rotate the pointer object like a turret. I've modified it slightly to work as a hud demo.

/*
https://www.virtualverse.one/forums/threads/kept-simple-rotate-object-towards-another-object.178/
1. rez a cube prim
2. drop this script into it
3. wear prim as hud
4. update script's target variable to have UUID of prim to point at
5. click hud
*/
key target = "e178c14a-dcc4-77ca-fad6-99dbc4850e38";
integer toggle = FALSE;

default
{
    state_entry()
    {
        llRequestPermissions(llGetOwner(),PERMISSION_TRACK_CAMERA);
        
        llSetLinkPrimitiveParamsFast(LINK_THIS, [   //make prim look like a simple arrow
            PRIM_TYPE, PRIM_TYPE_PRISM, 0, <0,1,0>, 0.0, <0,0,0>, <1,1,0>, <0,0,0>,
            PRIM_SIZE, <0.1,0.1,0.05>,
            PRIM_COLOR, 0, <0,0,1>, 1.0,
            PRIM_COLOR, 1, <0,1,0>, 1.0,
            PRIM_COLOR, 3, <1,0,0>, 1.0
        ]);
    }
    
    touch_start(integer total_number)
    {
        if(toggle = !toggle)
            llSetTimerEvent(0.1);
        else
            llSetTimerEvent(0.0);
    }
    
    timer()
    {
        vector vTarget=llList2Vector(llGetObjectDetails(target,[OBJECT_POS]),0); //target position
        vector vPos=llGetCameraPos(); //our position
        float fDistance=llVecDist(<vTarget.x,vTarget.y,0>,<vPos.x,vPos.y,0>); //XY Distance, disregarding height differences.
        llSetLinkPrimitiveParamsFast(LINK_THIS, [
            PRIM_ROT_LOCAL, (llRotBetween( //rotation between pointer's local "forward" orientation and difference to target
                <1,0,0>,
                llVecNorm(<fDistance,0,vTarget.z - vPos.z>)) * llRotBetween(<1,0,0>,llVecNorm(<vTarget.x - vPos.x,vTarget.y - vPos.y,0>))
            )/llGetCameraRot()
        ]);
    }
}

The demo assumes you want the prim to point it's "forward" face towards the target which is denoted by the <1,0,0> normal vector. Positive X is considered forward for objects locally. (<0,1,0> is left, and <0,0,1> is up)

  • Like 1
  • Thanks 2
Link to comment
Share on other sites

59 minutes ago, Fenix Eldritch said:

The demo

Works surprisingly well, as long as you understand that it points as if it were in the center of your HUD, which may or may not be the effect wanted.

Not what was asked for, but with that demo, it feels better to me if it points based on the avatar's position&rotation,

Quote
    timer()
    {
        vector vTarget=llList2Vector(llGetObjectDetails(target,[OBJECT_POS]),0); //target position
        vector vPos=llGetPos(); //our position
        vector fwd = llRot2Fwd(llGetRot());
        vector to_target = vTarget-vPos;
        vector v=to_target; v.z = 0;
        rotation yaw = llRotBetween(fwd,v);
        rotation pitch = llAxisAngle2Rot(<0,-1,0>,llAtan2(to_target.z,llVecMag(v)));
        
        llSetLinkPrimitiveParamsFast(LINK_THIS, [
            PRIM_ROT_LOCAL, (pitch*yaw)
        ]);
    }

 

Edited by Quistess Alpha
  • Like 1
Link to comment
Share on other sites

11 hours ago, Fenix Eldritch said:

A while back, Chalice Yao posted a neat little snippet with explanations on the VVO forums. Her example uses two llRotBetween calls to essentially rotate the pointer object like a turret. I've modified it slightly to work as a hud demo.

/*
https://www.virtualverse.one/forums/threads/kept-simple-rotate-object-towards-another-object.178/
1. rez a cube prim
2. drop this script into it
3. wear prim as hud
4. update script's target variable to have UUID of prim to point at
5. click hud
*/
key target = "e178c14a-dcc4-77ca-fad6-99dbc4850e38";
integer toggle = FALSE;

default
{
    state_entry()
    {
        llRequestPermissions(llGetOwner(),PERMISSION_TRACK_CAMERA);
        
        llSetLinkPrimitiveParamsFast(LINK_THIS, [   //make prim look like a simple arrow
            PRIM_TYPE, PRIM_TYPE_PRISM, 0, <0,1,0>, 0.0, <0,0,0>, <1,1,0>, <0,0,0>,
            PRIM_SIZE, <0.1,0.1,0.05>,
            PRIM_COLOR, 0, <0,0,1>, 1.0,
            PRIM_COLOR, 1, <0,1,0>, 1.0,
            PRIM_COLOR, 3, <1,0,0>, 1.0
        ]);
    }
    
    touch_start(integer total_number)
    {
        if(toggle = !toggle)
            llSetTimerEvent(0.1);
        else
            llSetTimerEvent(0.0);
    }
    
    timer()
    {
        vector vTarget=llList2Vector(llGetObjectDetails(target,[OBJECT_POS]),0); //target position
        vector vPos=llGetCameraPos(); //our position
        float fDistance=llVecDist(<vTarget.x,vTarget.y,0>,<vPos.x,vPos.y,0>); //XY Distance, disregarding height differences.
        llSetLinkPrimitiveParamsFast(LINK_THIS, [
            PRIM_ROT_LOCAL, (llRotBetween( //rotation between pointer's local "forward" orientation and difference to target
                <1,0,0>,
                llVecNorm(<fDistance,0,vTarget.z - vPos.z>)) * llRotBetween(<1,0,0>,llVecNorm(<vTarget.x - vPos.x,vTarget.y - vPos.y,0>))
            )/llGetCameraRot()
        ]);
    }
}

The demo assumes you want the prim to point it's "forward" face towards the target which is denoted by the <1,0,0> normal vector. Positive X is considered forward for objects locally. (<0,1,0> is left, and <0,0,1> is up)

This is perfectly what I'm wanting. Thank you so much! ❤️

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...