Irrelon / ige

The Isogenic Game Engine
523 stars 139 forks source link

tweening delta calculation minor error, what to do? #208

Closed Doidel closed 11 years ago

Doidel commented 11 years ago

Hey Rob and all who want to participate in this discussion

While the delta tweening allows some cool stuff I encountered an issue that puts it a bit in question: Like all coding languages big numbers suffer from imprecision, e.g. leading to the following output on console from the last step of a tween...

old val 0.0029999999999996696
difference -0.0030000000000000027 
new Value -3.3306690738754696e-16

...with the goal of tweening to 0. While such entirely small differences do not matter e.g. with tweening _translate, it definitely does matter with opacity: If opacity == 0 then it's fully transparent BUT if opacity ==-3.3306690738754696e-16 (i.e. almost 0) the engine has no clue what to do with that and the opacity goes to default 1, being fully opaque.

I won't write down the choices how to handle this 'cause they are more or less obvious, but what would you (Rob & guys) choose to do?

(Hint: Math.round() can't be used because it would break the tween combining. You'd like 'round the other tween too' that is running the same time.)

Thanks in advance for some assistance!

Irrelon commented 11 years ago

I suggest something like toFixed(2) rather than rounding? Or maybe not. I don't know.

I guess that an internal value could be kept that if the (time * delta value) is > than the internal value, to round it before applying it to the tween? Or something like that.

Doidel commented 11 years ago

I changed the delta correction at the end of the tween to perform a rounding according to the number of digits. We'll discuss it per Skype. But I guess this version works, it has good performance but will cut the floating point precision to about 15 digits (yet 15 is quite a lot, I guess that will do...) Anyway. Skype.

Irrelon commented 11 years ago

Yay! Ok we can discuss further via Skype :) I am back to work on Monday after a much needed Christmas break, although so much went wrong this holiday it's been pretty stressful.

Someone smashed into my car while it was parked and I was 150 miles from home, damaging the alloy wheel and breaking the rear axel, then drove away without leaving any details. Then I borrowed my parents car to get home, arrived and realised the keys to the house were in my car so had to hire a 24 hr lock smith to get in, then once we were in, realised that the central heating had stopped working because our boiler was broken!

Crazy.

Doidel commented 11 years ago

Oh dear... That's some bad luck x/

Yes sure, Monday will do!

Irrelon commented 11 years ago

For the log, we discussed this via Skype and @Doidel has come up with a solution and pushed the update to the repo.

Mavor commented 11 years ago

cool beans :)