Hi
FLOATING POINT MOVEMENT
I’ve been using MMF2 for quite some time now.
MMF2s 'Coordinate System' and 'Angle System' works with Integers ( whole numbers ), meaning you can’t apply decimal speeds or rotation speeds like, 0.45 pixels per frame, or 1.75 Angle increase per Frame.
You can however work with AlterableValues like FloatX_, FloatY_, Angle_ to achieve Floating Point ( decimal coordinates and speeds ) movements and Angles.
I find creating Floating Point Movements and Angles ( as opposed to just using the X Y and Angle variables directly ) giving your creation a much smoother look and fell.
For those who are not familiar with the difference, here is a simple example showing the basic difference between the methods:
https://dl.dropbox.com/u/3537859/Int...cimalSpeed.mfa
Here is also an old example of a Custom Spaceship Movement which uses both Floating Point Coordinates/ Speeds and Angle:
https://dl.dropbox.com/u/3537859/Cus...ipMovement.mfa
As you can assume from the first example, making this Spaceship Movement without using Floating Point variables would not be as smooth.
THE PROBLEM WITH DECIMALS
So here I am today, and when creating Apps using MMF2 I highly prefer using FloatingPoint Coordinates and Angles
But as I discovered, apparently, computers in general ( MMF2 also ) don’t handle decimal number very well.
You might not know about this, but this very simple example illustrates this:
https://dl.dropbox.com/u/3537859/DecimalProblem.mfa
Explanation:
- There is a Counter at value 0
- SPACE increase Counter by 0.1
- If Counter is 0.3 it should destroy
If you ran the example, you have already noticed that the Counter does not destroy although the Counter is clearly equal to 0.3
This is how computers have problems with decimal numbers, apparently for a computer 0.1 is not exactly 0.1
So when adding 0.1 + 0.1 + 0.1 the result is apparently not exactly 0.3
I’ve been using MMF2 for quite some time and I see myself embarking on big and complex projects/ game project in the future.
I feel my experience with MMF is good enough for this, and further more I can tell right away that I will want to use Custom Floating Point Movements for such projects because of the increase quality and feel this gives.
But because of this Computer Decimal issue, I can smell trouble from afar and am stalling and maybe a little reluctant to start planning for such big projects.
So my problem is I don’t know how to deal with this Decimal Issue.
In a big project there may be numerous decimal variables like Coordinates, Speeds, Angles, Acceleration, Deceleration, Scale and so on.
I want to create Apps/ games which are smooth all around and as best they can be, but the trouble with the Decimals seem to be an unsolvable troublemaker which can easily crash big and complex projects.
SOLUTION A: PLAN CAREFULLY
An apparent solution is to plan your design very well, so for example instead of doing 'If Counter equals 0.3' you could do 'If Counter is greater or equal to 0.3'
But this again makes the design process more difficult, and can cause problems if you want to experiment or add new features which were not in the original design.
Failing to recognize the Decimal Precision issue for a feature can cause a lot of confusion, stress and lost time along the road.
SOLUTION B: INTEGER TO DECIMAL METHOD
Another theoretic solution which probably would work is to use Integer Numbers and divide them when you need to to create decimal numbers, for example:
DECIMAL SOLUTION
You want to increase an Objects Speed by 0.1, and destroy it when it reaches 0.3
- By holding a button, you increase Speed by 0.1
- Object moves, ObjecX = ObjectX + Speed
- If Speed is equal to 0.3, Object destroy
0.1 + 0.1 + 0.1 = 0.3 ( as stated above this is not accurate and the Condition will not trigger )
INTEGER SOLUTION
You want to increase an Objects Speed by 0.1, and destroy it when it reaches 0.3
- By holding a button, you increase Speed by 1
- Object moves, ObjecX = ObjectX + Speed/ 10
- If Speed is equal to 3, Object destroy
1 + 1 + 1 = 3 ( Integers are not problematic and the Condition will trigger )
...
For this 'Integer to Decimal' method you would probably need to plan how many decimals you are going to use, for example:
If you want your Speed to have 1 decimal place, you need to divide the Speed by 10
8 / 10 = 0.8
133 / 10 = 13.3
1456 / 10 = 145.5
If you want your Speed to have 4 decimal places, you need to divide the Speed by 10000
8 / 10000 = 0.0008
133 / 10000 = 0.0133
1456 / 10000 = 0.1455
So this is another problem, as you can see from above we use the number 1456 to generate a number below 0.2
If this method would to be used for a coordinate system, you can imagine it would be impossible to use a single Integer as an Xposition coordinate for an Object in a Frame of 2000x2000 ( since the Integer would reach its maximum value at some point )
So here this method falls short since you have to be very thorough in planning what you’re going to use the decimal number for and limit it to a number of decimals.
END
So what can be done about this unfortunate little issue, surely there is something that can be done?
Is this an unsolvable unfortunate problem which can’t be overcome?
Is this issue present across all programming platforms like JAVA and C, if not how do they overcome it?
Is there any decent way of handling this, or a good way of solving this in MMF2?











Reply With Quote









