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.

Dark GDK / how dbRND, dbSIN, dbTimer are implemented

Author
Message
WBB
15
Years of Service
User Offline
Joined: 28th Aug 2009
Location:
Posted: 7th Sep 2009 02:57
I'm teaching a class with Dark GDK, and I usually have them use rand() and srand(int) from cstdlib, and sin, cos, etc., from cmath, and time from ctime. But I see Dark GDK has its own versions. Does it matter which they use? Are they any different?

TIA
jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 7th Sep 2009 18:37 Edited at: 7th Sep 2009 18:39
They are potentially slower. Go for the standard lib functions, as these are specifically optimised for C++ for you compiler.

EDIT: the reason these functions exist at all is because DBPro (from which GDK is basically a port) has no native stdlib to take the rand functions from.

Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 7th Sep 2009 19:53
Yes, they are different:

The sin/cos functions that come with C++ expect the angle in radians, while the dbSin, dbCos functions work with degrees. If you use the GDK object rotation functions, they also expect their parameters in degrees, so I suggest to use the dbSin/dbCos functions because the units match.

When the rand function is used giving it a range, like rand() % 10 for example, as far as I know the value will never be the maximum range you provided, so in this case it will never be 10. But if you use dbRand(10), it will return numbers between 0 and 10 (the maximum range).

dbTimer just returns the system "ticks" in milliseconds.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 7th Sep 2009 23:28
it will return ten. and the equivalent of dbTimer() is time( 0 ) you need to include ctime though. that gets milloseconds since epoc.

New Site! Check it out \/
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 8th Sep 2009 11:22
Good points, also note that, for example, cos and sin functions accept double floats, while dbCos and dbSin use single floats. Somewhat a limitation if to perform very accurate math calculus, that reveals that DBPro is designed, in fact, for game making, where you need speed and not that much accuracy.
WBB
15
Years of Service
User Offline
Joined: 28th Aug 2009
Location:
Posted: 8th Sep 2009 16:56
Thanks, everyone!
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 8th Sep 2009 17:56
Quote: "cos and sin functions accept double floats, while dbCos and dbSin use single floats"


Notably in XNA they only use floats instead of doubles. It probably shows a relative lack of need for precision in the gaming field. After all, we're not modeling atomic particles.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
chunks chunks
17
Years of Service
User Offline
Joined: 2nd Jan 2007
Location: ackworth uk
Posted: 8th Sep 2009 19:24 Edited at: 8th Sep 2009 19:25
does anyone know how dbcos/dbsin actually get there values? because i have just done a test with the cos and sin out of the math.h and converted the radians to degrees like mireben said and still get a completley different value they must do something else prolly why they are slower .

chunks

nvidia geforce 9500gt + amd athlon 64
windows vista ultimate.
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 8th Sep 2009 20:51
Quote: "When the rand function is used giving it a range, like rand() % 10 for example, as far as I know the value will never be the maximum range you provided, so in this case it will never be 10."


Quote: "it will return ten."


No, it won't. I hate it when people say stuff without even testing it first The '%' sign is the MODULUS operator. It returns the remainder when you divide two numbers. The remainder of x/10 can never be 10.

Quote: "cos and sin functions accept double floats, while dbCos and dbSin use single floats"


cos and sin (and the other functions in math.h) are overloaded to accept 'long double', 'double' and 'float' parameters.

Quote: "i have just done a test with the cos and sin out of the math.h and converted the radians to degrees like mireben said and still get a completley different value"


Are you sure? Could you show us the code you are using which shows that?

jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 8th Sep 2009 22:51
Quote: "After all, we're not modeling atomic particles."

I have seriously considered a particle simulator as a project. And with quantum mechanics and all, surely low precision is more realistic?

chunks chunks
17
Years of Service
User Offline
Joined: 2nd Jan 2007
Location: ackworth uk
Posted: 8th Sep 2009 23:10 Edited at: 8th Sep 2009 23:12
@diggsey i`m not entirely sure i just used a calculation from http://www.mathcentre.ac.uk/resources/leaflets/firstaidkits/4_1.pdf ,just thought it might be faster to use the trig from math.h and the calculate it with that , do you know how to do it properly , i suck at math ?

will have another look though .

chunks

nvidia geforce 9500gt + amd athlon 64
windows vista ultimate.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 8th Sep 2009 23:16
Quote: "And with quantum mechanics and all, surely low precision is more realistic?"


I think we need to have a "chaos" variable type available.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 9th Sep 2009 19:15
Quote: "I think we need to have a "chaos" variable type available."


With an automatic conversion from 'void'

Login to post a reply

Server time is: 2024-11-20 15:29:59
Your offset time is: 2024-11-20 15:29:59