Jump to content
Arska134

Distance to picked point

Recommended Posts

Is there any command to get distance from point x, y, z to x2, y2, z2. I need to get distance from camera position to picked position.

Share this post


Link to post

PointDistance(p1:TVec3, p2:TVec3)

 

or just do what it is doing and perform the math yourself

distance = ( (x1 - x2)^2 + (y1 - y2)^2 + (z1 - z2)^2 )^0.5

Share this post


Link to post

no its not listed as a command but i found it in lua a long time ago by accident when i tried to make my own function as well and used the obvious name for the function, PointDistance()... and i noticed it turned blue in the ScriptEditor as it was recognized... i mentioned it to josh at the time and he didnt seem too concerned about putting it in the wiki / forum docs... i assume since its basic math...

Share this post


Link to post

Is there any command to get distance from point x, y, z to x2, y2, z2. I need to get distance from camera position to picked position.

 

If you put a pivot at your picked position you could use EntityDistance(camera, pivot);.

Share this post


Link to post

Wait... let me get this right.... instead of steps like this:

 

1. PointDistance(TVec3. LE::TVec3) // If you are in bmax or LUA, otherwise simple math funciton in C++

 

You do this:

 

1. CreatePivot();

2. PositionEntity(pivot, Vec3);

3. GetEntityDistance(pivot, camera);

 

.... I don't see the logic here.

Share this post


Link to post

Looks like he tagged this post as BMax. Sounded like PointDistance() is a Lua function? Could be wrong, but that's how I read the post by macklebee. If the language/library I was using already had the function, then for sure use it. If not then for me, it's about not having to think about it or implementing it every time I do a new project (which is often). I'm not very organized so I don't keep a library of common code really. I know the function already exists in LE but it just so happens it needs an entity, so this is a way to do that with using just LE code that's easier for me to remember.

 

So I guess for me it's not about logic, it's about laziness. smile.png

Share this post


Link to post

Well for anyone who wants a function for C++ that they can re-use every time its pretty simple:

 

#include <math>

float GetDistance(LE::TVec3 start, LE::TVec3 end){

 return sqrt(pow(start.X-end.X, 2) + pow(start.Y-end.Y, 2) + pow(start.Z-end.Z, 2));
}

Share this post


Link to post

its in lua because it was in bmax... its not in the dll i assume because its basic math as i and ken have both shown...

Share this post


Link to post

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...