Page 1 of 2

Should I modify SFML???

Posted: Sun Feb 06, 2011 4:29 pm
by THe Floating Brain
Okay so I finally think I have a rough idea of vectors and I wrote these functions
(Calculates a vector)
http://pastebin.com/h6KqWVKu
("Lightning" is the version of my engine)
(Moves a object along a vector)
http://pastebin.com/3dXv5WfQ
Problem being... despite all the long double variables I put the movement of a object along a vector is inaccurate (just slightly).
HELP!.jpg
HELP!.jpg (10.51 KiB) Viewed 2361 times
The reason is that when I pass the "GotoX", and "GotoY" variables (from my function above) into SFML's .Move function the data is corrupted because .Move takes float variables instead of long double variables. So I am wondering if I should go through the trouble of changing SFML's .Move function to take long double's instead of float and possibly other functions and also compromise SFML's performance?

P.s Language = C++
P.s.s I know I sometimes have a hard time getting my point across so if any clarification is needed let me know :-)

Re: Should I modify SFML???

Posted: Sun Feb 06, 2011 5:21 pm
by GroundUpEngine
Sometimes we should keep it simple, if you wanna use the SFML API as is.. just use float (up to 7 digits i believe, which is not bad) variables for your maths ;)

Re: Should I modify SFML???

Posted: Sun Feb 06, 2011 5:34 pm
by Ginto8
... The fact that you're using long doubles when floats are all you need (and, more to the point, you're using an api that focuses on floats) proves that you are not yet at the level where you'd be capable of modifying SFML, disregarding that it really shouldn't be necessary at all.

It may interest you to know that SFML uses OpenGL for a backend, and OpenGL, although you can pass it doubles, converts everything to floats internally, so there really isn't much point anyway.

Re: Should I modify SFML???

Posted: Sun Feb 06, 2011 5:36 pm
by GroundUpEngine
Ginto8 wrote:It may interest you to know that SFML uses OpenGL for a backend, and OpenGL, although you can pass it doubles, converts everything to floats internally, so there really isn't much point anyway.
I was about to address that! Good point.

Re: Should I modify SFML???

Posted: Sun Feb 06, 2011 7:46 pm
by THe Floating Brain
Ginto8 wrote:... The fact that you're using long doubles when floats are all you need (and, more to the point, you're using an api that focuses on floats) proves that you are not yet at the level where you'd be capable of modifying SFML,
I know how :| (change the function args in the source and in bolth copies of the headers in VC++ and in C: if any warnings come up according to that also change them to long doubles)
Ginto8 wrote:It may interest you to know that SFML uses OpenGL for a backend, and OpenGL, although you can pass it doubles, converts everything to floats internally, so there really isn't much point anyway.
(I did know that SFML used openGL) So it realy doesent matter 0.0. Thing is though it is even less acurate when I dont use doubles so I am not sure what to do. Poeple told me that my vector calculation function is correct. :/ Not sure were to go here.
GroundUpEngine wrote:I was about to address that! Good point.
+1
GroundUpEngine wrote:just use float (up to 7 digits i believe,
actually its 6 :mrgreen:

Re: Should I modify SFML???

Posted: Sun Feb 06, 2011 9:20 pm
by pritam
There is a good reason using floats for movement, it's a lot smoother. If you need to run an if statement where your x/y variables reaches 300, use typecasting:

Code: Select all

if( (int)playerX )
Don't bother changing SFML, the effort is not worth it by far, there would hardly be improvement and you're not considering events where floats are necessary.

Edit: Actually typecasting doesn't round nicely, use this instead:

Code: Select all

(int) floor( f + 0.5f );

Re: Should I modify SFML???

Posted: Sun Feb 06, 2011 9:35 pm
by THe Floating Brain
But if it never equils the desired position that wont work.

Re: Should I modify SFML???

Posted: Sun Feb 06, 2011 9:47 pm
by pritam
THe Floating Brain wrote:But if it never equils the desired position that wont work.
Well, that's entirely up to you, use other operators.

Re: Should I modify SFML???

Posted: Sun Feb 06, 2011 11:43 pm
by JesseGuarascia
Hold on, let me get this straight. You want to change an entire API that is revolved around the float data type, because you want to use long doubles instead? :roll:

Also, Pritam's got it right. If you really desire a whole 300 constant value, just floor/ceil the thing. SFML's amazing; don't go breaking it because you're too lazy to change a long double to a float. :P

Re: Should I modify SFML???

Posted: Mon Feb 07, 2011 6:02 am
by GroundUpEngine
THe Floating Brainquote wrote:
GroundUpEngine wrote:just use float (up to 7 digits i believe,
actually its 6 :mrgreen:

Code: Select all

float lol = 1.234567;
JesseGuarascia wrote: :roll:
+1

Re: Should I modify SFML???

Posted: Mon Feb 07, 2011 7:12 am
by MrDeathNote
GroundUpEngine wrote:
THe Floating Brainquote wrote:
GroundUpEngine wrote:just use float (up to 7 digits i believe,
actually its 6 :mrgreen:

Code: Select all

float lol = 1.234567;
:lol: lol.
JesseGuarascia wrote: :roll:
+2

This is a really odd thread, I find it really hard to believe that you're actually considering changing the SFML API for no good reason, a float should be more than enough to work with. If the values aren't being set right then you're doing something wrong. But the short answer to "Should I modify SFML???" is NO!!

Re: Should I modify SFML???

Posted: Mon Feb 07, 2011 12:24 pm
by xiphirx
I'm really confused....

How big are your input values? Do you know what the range of a long is?...

Code: Select all

//Calculate Magnitude.//
						GotoX -= Object.GetPosition().x;
						GotoY -= Object.GetPosition().y;
						long double Magnitude;
Why do you need a long double? float is fine...

Code: Select all

Magn(GotoX, GotoY, Magnitude);
Curious to see what that does... and why you couldn't just write the Pythagorean theorem out instead of having an odd function for it.

Code: Select all

//Go The Desired Speed.//
                                                GotoX *= Speed;
                                                GotoY *= Speed;
This is where your values are messed up, I think...

Just to note, it looks like you don't have a good grasp on vectors. If you did, you would have probably used SFML's own vector2f class :P

Re: Should I modify SFML???

Posted: Tue Feb 08, 2011 8:21 am
by N64vSNES
xiphirx wrote:If you did, you would have probably used SFML's own vector2f class :P
:lol:

So...You want to fuck with SFML's source because you want to use a double over a float? :shock:

Re: Should I modify SFML???

Posted: Tue Feb 08, 2011 12:00 pm
by Falco Girgis
THe Floating Brain wrote:Okay so I finally think I have a rough idea of vectors and I wrote these functions
(Calculates a vector)
http://pastebin.com/h6KqWVKu
("Lightning" is the version of my engine)
(Moves a object along a vector)
http://pastebin.com/3dXv5WfQ
Problem being... despite all the long double variables I put the movement of a object along a vector is inaccurate (just slightly).
HELP!.jpg
The reason is that when I pass the "GotoX", and "GotoY" variables (from my function above) into SFML's .Move function the data is corrupted because .Move takes float variables instead of long double variables. So I am wondering if I should go through the trouble of changing SFML's .Move function to take long double's instead of float and possibly other functions and also compromise SFML's performance?

P.s Language = C++
P.s.s I know I sometimes have a hard time getting my point across so if any clarification is needed let me know :-)
Honestly, why in fuck's name would you be using doubles? Why would you EVER need that kind of precision? That's only for exact numbers and scientific calculations.

And keep in mind that there is not a 1-to-1 relationship between an IEEE 32-bit single precision float (the variable you know as "float") and an integer. How many bytes are used to represent both? Float = 4 bytes. Integer = 4 bytes. They are literally the same size. They are literally both only capable of holding a permutation of their number of bits. So you are going to be missing some "exact" values that exist in an integer with a float. That's how it works.

You have no IDEA what the performance implications of using doubles usually is. Modern GPUs are only NOW starting to hardware accelerate doubles. A lot of the time the routines are written completely and software for GIGANTIC performance drops (because there's no support for the IEEE 64-bit float in hardware). We don't EVER use double precision floats in game development...

Re: Should I modify SFML???

Posted: Tue Feb 08, 2011 5:08 pm
by THe Floating Brain
God I feel realy embaressed :oops: :oops: :oops:
GyroVorbis wrote: Honestly, why in fuck's name would you be using doubles? Why would you EVER need that kind of precision? That's only for exact numbers and scientific calculations.

And keep in mind that there is not a 1-to-1 relationship between an IEEE 32-bit single precision float (the variable you know as "float") and an integer. How many bytes are used to represent both? Float = 4 bytes. Integer = 4 bytes. They are literally the same size. They are literally both only capable of holding a permutation of their number of bits.
Damn C++ book lied to me :nono:
N64vSNES wrote:So...You want to fuck with SFML's source because you want to use a double over a float? :shock:
Not any more I did though beacuse I am apparently a terrible programmer :lol:
xiphirx wrote:I'm really confused....
How big are your input values? Do you know what the range of a long is?...
19 digets.
xiphirx wrote:

Code: Select all

//Go The Desired Speed.//
GotoX *= Speed;
GotoY *= Speed;
This is where your values are messed up, I think...
Why do you think that?
xiphirx wrote: Just to note, it looks like you don't have a good grasp on vectors. If you did, you would have probably used SFML's own vector2f class :P
hence...
Okay so I finally think I have a rough idea of vectors and I wrote these functions