Calculate Distance and XY

07/08/2012 11:43 fatihy93#1
Hi. I need calculating distance between positionX & destinationX.

That are my codes but not perfectly works.

Code:
 
float Distance = Formula.Distance (posX, 0, directionX, 0);
            float waitTime = (Formula.Distance (posX, posY, directionX, directionY)) * 10000f / (((Speed * (Speed * 1.05f)) / 100f) + ((20f / Speed) * 105f));
            
            float Interval =  (waitTime / Distance) * 0.1f;
Distance Formula

Code:
       
public static float Distance(float posX, float posY, float directionX, float directionY) 
       {

           double gamedistance = Math.Sqrt((directionX - posX) * (directionX - posX)) + ((directionY - posY) * (directionY - posY));
           
           return float.Parse(gamedistance.ToString());
       }
Waiting your helps...
07/08/2012 13:15 theonly112#2
(((Speed * (Speed * 1.05f)) / 100f) + ((20f / Speed) * 105f)

WTF?

Time = distance / speed
Although if i recall correctly you have to multiply by 10. I don't recall why though
07/08/2012 14:15 zeteris#3
I use this to get time in ms:
Code:
int time = Convert.ToInt32(dist * 10000 / Speed);
07/08/2012 15:37 theonly112#4
Quote:
Originally Posted by zeteris View Post
I use this to get time in ms:
Code:
int time = Convert.ToInt32(dist * 10000 / Speed);
Which is the same thing i said, except it will be in milliseconds instead of seconds
07/09/2012 09:58 fatihy93#5
Thanks but why i can't calculate %100 correctly?
07/09/2012 11:13 paxemuman#6
Quote:
Originally Posted by fatihy93 View Post
Thanks but why i can't calculate %100 correctly?
because there is Z position
07/09/2012 20:52 PortalDark#7
i have some interest on this(i dont know how to make coords for /warp command)
07/09/2012 23:39 paxemuman#8
Quote:
Originally Posted by PortalDark View Post
i have some interest on this(i dont know how to make coords for /warp command)
[Only registered and activated users can see links. Click Here To Register...]
07/09/2012 23:42 PortalDark#9
Quote:
Originally Posted by paxemuman View Post
[Only registered and activated users can see links. Click Here To Register...]
have the method to myself, not that page
07/09/2012 23:55 paxemuman#10
Quote:
Originally Posted by PortalDark View Post
have the method to myself, not that page
let me search in my backups , i should have somewhere an app which convert warp to normal coords (i have made it to convert spots from pk2 and put it to my emu). It was hard to figureout it :). If i will find it i will make second option (from normal coorfinates to Pk2"Warp") and i will public it here as an open source tool :). To be honest i don't rememeber formula it was too long time ago.
Edit :
I have found it, i will make an app today or tommorow and i will make it public here in coding section(source will be included).
07/10/2012 01:39 fatihy93#11
Quote:
Originally Posted by paxemuman View Post
because there is Z position
What? You tell i need calculate distance with Z position ?
07/10/2012 03:15 paxemuman#12
Quote:
Originally Posted by fatihy93 View Post
What? You tell i need calculate distance with Z position ?
if you want 100% correct then yes i will draw for you why:

[Only registered and activated users can see links. Click Here To Register...]


As you can see A terrain are flat so you will go faster trought when same X/Y distance in B will take you longer because Z position are different.
07/10/2012 08:33 fatihy93#13
Quote:
Originally Posted by paxemuman View Post
if you want 100% correct then yes i will draw for you why:

[Only registered and activated users can see links. Click Here To Register...]


As you can see A terrain are flat so you will go faster trought when same X/Y distance in B will take you longer because Z position are different.
I know this but i thought Z position not important on this time.

Ah, now i understand. When i walk on directly, i calculate correctly because Z was not effective or fixed.

Thank you bro, and sorry for my sentences without grammar ^^.
07/16/2012 00:50 giniyat202#14
here is code in c++ (sorry idk any other language)
Code:
float CalculateDist(D3DXVECTOR3 from, D3DXVECTOR3 to)
{
	float _x, _y, _z;
	_x = to.x - from.x;
	_y = to.y - from.y;
	_z = to.z - from.z;
	return sqrt(_x*_x + _y*_y + _z*_z);
}
sorry for using D3DXVECTOR3 as i use this in my crossfire hack
any way if you dont have directx sdk use this structure:

Code:
#ifndef D3DXVECTOR3
struct D3DXVECTOR3
{
    float x;
    float y;
    float z;
};
#endif
07/16/2012 10:16 kevin_owner#15
Thanks now I know why the movement was always a bit wrong.

Little note the so called "z" axis is actually the "y" axis in a 3d space. Not that it matters in distance calulation but it might confuse the hell out of you if you are going to work with the navmesh and other 3d objects.