I’m facing a huge problem and I have no idea what’s causing it and how to fix this. I’m creating a game where I draw objects in Java. For drawing I use linear interpolation which uses ‘alpha’ value to move the object with a specific time value in one frame.
Here is how the interpolation algorithm looks like:
draw.x = current.getX() * alpha + previous.getX() * (1.0f - alpha);
Let’s assume that I’m standing in place and my positions: current and previous are 100 and 100.
No matter what ‘alpha’ is (0.234234, 0.9994234, 0.324235325) it should always return draw.x == 100.
But it doesn’t cause the compiler sometimes cuts 0.00000001 from the value and draw.x becomes 99.99999999.
Next, I need to use it to render the object and I don’t know what to do (round or cast) that it doesn’t break in the future.
If I cast it to INT (cause I can’t render objects on floats) - it becomes ‘99’ which makes the jerk (animation jumps).
If course I could round it to 100, but wouldn’t it break the app when moving (make unexpected jerks later?)?
If someone could help me - this is the last thing that I can’t handle!
Thanks