Jump to content

calculate position a fixed offset left or right of avatar


Judy Hynes
 Share

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

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

Recommended Posts

I imagine this problem has been discussed here before but I couldn't seem to hit on the right search terms to use.  So I apologize in advance if it has been covered.

I have a script where I need to figure out the position vector (in global coordinates) of a position a fixed distance to the left or right of the avatar based on its current rotation.   So for example consider this code:

rotation rot = llGetRot();
vector start = llGetPos();
vector end = start + <100.0,0.0,0.0>*rot;

This will give me a start position where avatar is and end position that's 100 meters straight ahead of where the avatar is facing.  It's like a pole sticking out from avatar's chest.

Now let's say I want the same thing that's 1 meter to the left.  That is, I want to know the start and end positions of a "pole" that's parallel to the original one and shifted over 1 meter to the avatar's left.  How can I calculate the start and end points?  Sorry if the answer is obvious but doing vector and rotation math always makes my head hurt.

 

Link to comment
Share on other sites

"shifting to the left" is just adding to the y-coordinate, like forward is adding to the x coordinate or going up is adding to the z coordinate.

3 useful functions for things like this are llRot2Fwd, llRot2Left and llRot2Up. (although they're less efficient than just multiplying a unit-vector by the rotation)

rotation MyRot = llGetRot();
vector MyPosition = llGetPos();
vector InFrontOfMe1 =  MyPosition + <1, 0, 0>*MyRot;
vector ToMyLeft1 = MyPosition + <0,1,0>*MyRot;
vector AboveMe1 = MyPosition + <0,0,1>*MyRot;

// the start and end posiitons of a rod extending from your groin to 10m infront of you:
list forward_rod = [MyPosition,10*InFrontOfMe];
// the start and end positions of a rod shift-coppied 1 unit to the left:
list left_rod = [MyPosition+ToMyLeft, 10*InFrontOfMe+ToMyLeft];

 

  • Like 1
Link to comment
Share on other sites

Thanks for the reply.  This makes more sense now.  One follow-up on the example you gave.  You wrote:

list left_rod = [MyPosition+ToMyLeft, 10*InFrontOfMe+ToMyLeft];

But ToMyLeft already has MyPosition added to it.  So if I put your example all in one line it looks like this:

list left_rod = [MyPosition+MyPosition+<0,1,0>*MyRot, 10*(MyPosition+<1,0,0>*MyRot)+MyPosition+<0,1,0>*MyRot];

Is this really correct that the starting point has MyPosition added twice?  It feels like ToMyLeft has already done that addition.

Link to comment
Share on other sites

Oh, Yeah your right, MyPosition should only be in there once in the total sum.  Corrected:

rotation MyRot = llGetRot();
vector MyPosition = llGetPos();
vector FWD = <1, 0, 0>*MyRot; // = llRot2Fwd(MyRot);
vector LFT = <0,1,0>*MyRot;   // = llRot2Left(MyRot);
vector UP =  <0,0,1>*MyRot;   // = llRot2Up(MyRot);

// the start and end posiitons of a rod extending from your groin to 10m infront of you:
list forward_rod = [MyPosition,MyPosition+10*FWD];
// the start and end positions of a rod shift-coppied 5 unit to the left:
list left_rod = [MyPosition+5*LFT, MyPosition+10*FWD+5*LFT];

is closer to how I would usually do something like this.

If you think of looking down at it from above, and you draw a little Cartesian coordinate plane with (0,0) where your object is, and (1,0) one unit in front of your object (assuming your object is an x-forward object) you just have to add scaled versions of your local FWD and LFT vectors to get to any point of interest. (2,3)  is just MyPos+2*FWD+3*LFT.

You can also do this sort of thing directly:

list left_rod = [MyPosition+<0,5,0>*MyRot, MyPosition+<10,5,0>*MyRot];

would be equivalent; multiplying by your rotation changes from local coordinates to global offsets.

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

You are about to reply to a thread that has been inactive for 1038 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...