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.

Newcomers DBPro Corner / distance - camera to object

Author
Message
deaths judge
17
Years of Service
User Offline
Joined: 4th Jan 2007
Location:
Posted: 7th Jul 2009 23:32 Edited at: 7th Jul 2009 23:33
Okay for start ive been away from programing for about a year

How would i measure the distance from the camera to the object as im making a flight game (space) and have the movement figured but i would like it to check if the camera is a curtain distance away from the cube if so it goes towards it.

here is my movement code atm:




[[[[wobble]]]] {{{{wobble}}}}
bobbel
15
Years of Service
User Offline
Joined: 5th Jan 2009
Location: In my DBPro case xD
Posted: 7th Jul 2009 23:35
i have a function here:



it ruturns the distance in a 3d world. here's how u use it in your case:



Your signature was erased by a mod because you copied mine!
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 7th Jul 2009 23:38 Edited at: 7th Jul 2009 23:38

Lol, ninja'ed

"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
deaths judge
17
Years of Service
User Offline
Joined: 4th Jan 2007
Location:
Posted: 8th Jul 2009 00:00
cheers guys im loving the fast rersponse

[[[[wobble]]]] {{{{wobble}}}}
bobbel
15
Years of Service
User Offline
Joined: 5th Jan 2009
Location: In my DBPro case xD
Posted: 8th Jul 2009 08:12
But thats not a function!

Your signature was erased by a mod because you copied mine!
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 8th Jul 2009 21:07
Err, I never said it was Bobbel - just that you had posted while I was typing...i.e. ninja'ed!

"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 9th Jul 2009 23:15
Vector math is so much faster so:



A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 10th Jul 2009 01:45
I can't locate the thread right now, but a while back there were several people in a debate over which method of finding distance is fastest.

It was determined that,



was actually faster.

x# * x# is significantly faster than x#^2

Interestingly enough, no one had suggested using ^0.5 instead of sqrt(), so I put that into the code I used to prove out the results. It turns out, using dist# = dist#^0.5 gives the same answer as sqrt(dist#) and is faster.

So the fastest distance calculation with DBPro would be,



On my machine this runs in 11ms, where the vector length calculation runs in 12ms. Not much difference I know, but when you're talking about calculating possibly hundreds of distances per loop, it adds up.

Enjoy.

Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 10th Jul 2009 02:08
Quote: "Interestingly enough, no one had suggested using ^0.5 instead of sqrt()"
.....err, except me!

"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 10th Jul 2009 18:14
I meant in the other thread. Thanks for bringing that up, because it knocks about 10-15ms off of using sqrt().

Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 13th Jul 2009 15:28 Edited at: 13th Jul 2009 15:28
Don't know if this is the same thread I was in, but i'm pretty sure using vectors were the fastest when it came to larger calculation (though don't hold me to that, I can't quite remember), although I wasn't awhere of (x#*x# + y#*y# + z#*z#)^0.5 being faster than sqrt(), I think I'll have a look at that also i'll look for that thread.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.

Login to post a reply

Server time is: 2024-09-28 08:23:09
Your offset time is: 2024-09-28 08:23:09