Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] Faster way to Find 3D Distance -- testing appreciated

Author
Message
Omen
18
Years of Service
User Offline
Joined: 7th Nov 2006
Location: Maple Grove, MN US
Posted: 18th May 2007 01:21
OK, so, please don't yell at me if this has already been posted somewhere, but I searched and couldn't find anything like it.

In my testing, the various and sundry SIN/COS functions are much slower than using 3D Vector Math... but I'd really appreciate it if anyone wants to run some tests on their machines to verify.

In any case, the code is below. You would call systemGetDistance3DSetup() before your main program loop and then whenever you want to calculate the distance between 2 objects, you'd do like this:








Enjoy!
Omen
18
Years of Service
User Offline
Joined: 7th Nov 2006
Location: Maple Grove, MN US
Posted: 18th May 2007 01:28
Oh sure, right after I post is when I find the previous post on this... ::sigh::

http://forum.thegamecreators.com/?m=forum_view&t=5187&b=6

hehe, ah well, just think of it as a bump then
Aralox
17
Years of Service
User Offline
Joined: 16th Jan 2007
Location: Melbourne
Posted: 28th Aug 2007 08:47
I like yours better, its easier to implement

Mr Kohlenstoff
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Germany
Posted: 28th Aug 2007 17:05
Here's a small demonstration code to compare the speed..



I get ~40 ms with vectors and ~70 with SQRT.

Math89
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: UK
Posted: 3rd Sep 2007 17:59 Edited at: 3rd Sep 2007 17:59


Without the '^2', the sqrt distance function is faster than the vectors one .
Oh and you can improve a bit the vector function :
The admiral
22
Years of Service
User Offline
Joined: 29th Aug 2002
Location:
Posted: 5th Sep 2007 06:27
Try this code its faster than your vector function.



The admiral
Ankillito
17
Years of Service
User Offline
Joined: 10th Dec 2006
Location: Litigious California
Posted: 6th Sep 2007 02:06 Edited at: 6th Sep 2007 02:07
Below is a comparing program. Admiral - you're a genius. The new method is definitely faster. However, I'm starting to wonder how much it matters - but, if you know a faster way, why not use it?



http://forum.thegamecreators.com/xt/xt_apollo_pic.php?i=1234759
Atreides
21
Years of Service
User Offline
Joined: 11th Oct 2003
Location: Switzerland (but NOT on a mountain !)
Posted: 11th Sep 2007 19:37
And this one is slightly faster than Admiral's


The sleeper must awaken !
calcyman
17
Years of Service
User Offline
Joined: 31st Aug 2007
Location: The Uncertainty Principle
Posted: 5th Nov 2007 17:27
I've already made some functions (look under the list of threads in my profile) to find distances. The most useful one is EuclidianDistance, which finds the distance between 2 points in 3D space.

Your signature has been erased by a hyper-intelligent pan-dimensional being (a mod)

Login to post a reply

Server time is: 2024-11-22 12:56:50
Your offset time is: 2024-11-22 12:56:50