Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Fastest Distance Calculation

This topic is 5437 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Since square roots are so cpu intensive I try to stay away from them. I use to use a fast distance calculator in 2d space it was 97% accurate but way faster (think used Newton Raphson approx method), here's the code...
int FastDistance(int dx, int dy)
// Calculate the distance quickly given dx, dy (can be negative)

int mn = min(dx,dy);

} //End FastDistance

I tried to adapt it over to 3d, by adding a dz (also changed all to floats) but couldn't get it to give me reasonable values. Anyone have the 3d equivalent ?? Righ now I am using D3DXVec3Length which I believe uses sqrt(dx+dy+dz). In general what other d3d or math functions do you try to stay way from (i.e. tan(), D3DXVec3Length, D3DXVec3Dot ...etc). Not saying these functions are bad just using as example... Thanks, rhuala [edited by - rhuala on November 28, 2003 9:25:07 AM]

Share this post

Link to post
Share on other sites
How often are you calculating the distance? Have you profled the code and found that your distance calculations are an issue? Otherwise I''d just use the D3DX functions as they are spiffy quick.

Stay Casual,

Drunken Hyena

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!