Jump to content
Daniells Brandi

Angle relative to a fixed point in the world.

Recommended Posts

Angle relative to a fixed point in the world

Hello, is it possible for me to find out which angle to follow to get to a fixed point in the world?
  Something like the image below ..

 

1459434683_exemplemap.jpg.6be9102da3a151bb013c84f1c235261e.jpg

Share this post


Link to post
Share on other sites

Thanks for the help Mollymews.
  It seems a little difficult for me, so far I have a compass and managed to find the angle that I find myself in the world in relation to the fixed point.
  But what I need is to know which angle to follow to get to the fixed point.

 

vector fix_point = <305310.70000, 234906.70000, 20>; //any position in the world
default
{
    state_entry()
    {
        llSetTimerEvent(0.1);
    }   
    timer()
    {
/////////////////////////////////////////////////////////////////////
//////////////// RELATION TO FIXED POINT /////////////////////////////      
        vector my_pos = (llGetRegionCorner()+llGetPos()); 
        my_pos = my_pos - fix_point;
        
        float angle = llAtan2(my_pos.x,my_pos.y) * RAD_TO_DEG;
        if(angle < 0.0)
        angle += 360.0;
        angle * DEG_TO_RAD;

/////////////////////////////////////////////////////////////////////
//////////////// COMPASS //////////////////////////////////////////// 
        rotation currRot=llGetRot();
        vector currEuler=llRot2Euler(currRot);
        float zRotAngle=currEuler.z;

        float heading=PI_BY_TWO-zRotAngle;
        while (heading<0) 
        heading+=TWO_PI;
        heading=heading*RAD_TO_DEG;
/////////////////////////////////////////////////////////////////////////    
        llSetText("Angle" + (string)angle + "° |" + "Compass=" + (string)heading + "°",<1,1,1>, TRUE );
        ]);            
    }
}

 

Edited by Daniells Brandi

Share this post


Link to post
Share on other sites

i am maybe not understanding what you are wanting to do. Like are you moving your avatar using the UI key controls to propel yourself and the idea is that the compass will tell you where you are relative to the target vector ?

if so then the angle would be between your avatar and the target vector

you might also look at llRotBetween http://wiki.secondlife.com/wiki/LlRotBetween

which helps to determine what direction the avatar is currently facing relative to the target vector

Share this post


Link to post
Share on other sites

I don't know what you want to find out, so no suggestion here.

When looking at your compass - are you aware that East is 0° in SL? North is -90° or 270° so whatever you do you need to compensate that.

 

Share this post


Link to post
Share on other sites
10 hours ago, Daniells Brandi said:

I want to know what angle I should follow to get to the fixed point, so I can align the angle of the compass with the angle I have to go to get to the fixed point.

You need to be clear about which frame of rotational reference you're using -- yours or that of the region.    

In this case, I think you need to use your own frame of rotational reference -- that is, you want to know how far to turn to your left or right in order to face your target, before setting off towards it in a straight line.

 You also need to be clear about whether you need to take into account the difference between your z coordinate and that of your target (that is, the difference between your respective elevations) or whether you're interested only in your respective x and y coordinates.     

The basic formula I use to calculate this is the one provided by @Chalice Yao over at  VirtualVerse.One.    Assuming you want to constrain your rotation to the x and y planes -- that is, you want to know how far to turn in order to face your target in order to move towards it but aren't interested in your different elevations (as you would be if you were aiming a gun at it or flying towards it),  this formula from Chalice's tutorial should calculate the angle you need to turn to face vTarget:

llRotBetween(<1,0,0>,llVecNorm(<vTarget.x - vPos.x,vTarget.y - vPos.y,0>))

in which vPos is your position and vTarget is that of your target.   That will tell you the angle (expressed as a quaternion) you need to turn on your own z axis to face your target.

Your illustrations suggest you want to move between regions, which would mean you need to take into account the difference between the world positions of the two regions.   So you would need to add the data returned by llGetRegionCorner to vPos and by llRequestSimulatorData("target region name", DATA_SIM_POS) to vTarget.

Everyone finds rotations confusing at first -- I struggled with them for years -- but when someone finally explains them to you, they're actually pretty simple to work with.    Besides Chalice's little tutorial on how to point an object at another object by script, I strongly recommend @Grandma Bates' two introductory tutorials at https://www.virtualverse.one/forums/forums/tutorials.31/ and the invaluable wiki article on rotations at http://wiki.secondlife.com/wiki/Rotation.

 

 

 

Edited by Innula Zenovka

Share this post


Link to post
Share on other sites

 Hello Innula ZenovkaI appreciate your help, but I still do not understand what I should do, I will try to illustrate better ..

 

I have a fixed point on the world map, this point I already have. Example vector fix_point = <305310.70000, 234906.70000, 27.44904>

indicated by the Red Point the image

I only need x and y.

 

I have my position on the world map using  llGetRegionCorner()+llGetPos();  In real time.

indicated by the Blue Point the image

 

I have a compass that indicates my rotation in the world

80 ° in the picture

 

I need to know, which direction (which angle ?° relative to the compass) I must take to get to this fixed point.

In the example image, I know that I must take the 235 ° direction to get to the fixed point,

  but how to find the direction in the virtual world?

(remembering that I will be moving, so this direction will not be fixed)

 

exmple.thumb.jpg.73b3d470c8b3afb694646f5fdc591906.jpg

 

I tried to use your formula, but I was unsuccessful, it really seems to be very difficult to work with angles.

 

A second image as an example, I'm in another place in the world....

 

exemple_2.thumb.jpg.11f767d55b2ce6838474b91d209a2564.jpg

 

thanking for the help.

Share this post


Link to post
Share on other sites
11 minutes ago, Daniells Brandi said:


 

I think I could, in fact I just needed to multiply by -1.

float angle = llAtan2(my_pos.x*-1,my_pos.y*-1) * RAD_TO_DEG;

 

thanks again for the support.

you are on to it

a longhand way to do this is something like:

default
{
    state_entry()
    {
        // Y points North. X points East
        
        vector home = <0.0, 0.0, 0.0>;
        vector dest = <1.0, 0.0, 0.0>;
        
        vector my_pos = <0, 1, 0.0>;
             
        integer angle_to_home = 
            llRound(
                llAtan2(my_pos.x - home.x, my_pos.y - home.y) 
                * 180.0 / PI + 180.0
            ) % 360;
                        
        integer angle_to_dest = 
            llRound(
                llAtan2(my_pos.x - dest.x, my_pos.y - dest.y) 
                * 180.0 / PI + 180.0
            ) % 360;
       
         
        llOwnerSay("home " + (string)angle_to_home + " dest " + (string)angle_to_dest);
    }
}

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...