Open Draknek opened 13 years ago
OMG, and I thought I was doing my trigonometry wrong all this time...
FlashPunk was based off GameMaker, and I believe that's where the degrees over radians came into play.
I was talking with Chevy Ray and Matt Thorson about angles in Ogmo and Chevy admitted to having done them wrong. They're fine if you assume the stage axes are centered at the bottom left (like a graph you'd draw in class), but since the positive y axis is downward and centered at the top left, the angles are incorrect.
I think we should definitely change this for FlashPunk 2.0, correct them.
Also, I'd make them radians. You only need to type degrees when manually setting an angle or displaying an angle, and the conversion should happen there.
Most people are used to working with degrees, as are most graphics programs. If you look at Photoshop (or a similar tool), all the angles are given in degrees, with 0° being along the positive X-axis. While radians are great for math nerds (and programmers), are they the best choice for FlashPunk?
I do believe any exposed API for FlashPunk involving rotation should have congruent units, as well as utilities for unit conversion.
Math
library uses radians.Thing is, when using utils functions, they are all converting the given angle to rads and the result back to degrees. This means, if you're using multiple util functions you're converting back and forth from degs to rads all the time, which is useless.
Thing is, when using utils functions, they are all converting the given angle to rads and the result back to degrees.
This should not happen. When you say "they should be radians," I'm not sure what you're referring to. When developing an API, you just need to consider the user.
If the user sets an angle as 90°, then adds 10°, when he looks at the angle, it should return 100°. If there are optimizations we as developers can do in the backend to improve performance (like storing 90° as 90 * Math.PI / 180
or performing all internal calculations without conversions back and forth), we should do that.
My big question is this: What will the user work with? Is it better for the user to work with degrees or radians?
@Rolpege You're overthinking this. The overhead of converting between degrees and radians is minimal. The programmer overhead of being confused about units is potentially high.
I vote for "good old radians". I used angles in flashpunk for the first time today and was completely baffled by both the negation and my values < PI only very slightly rotating my sprite, as pretty much everything in programming uses radians, including AS3's math library.
So I guess the degrees thing is personal preference, and it's admittedly sometimes more convenient to type 90 rather than Math.PI*0.5.
But the fact that they're negated has on a few occasions led to some really avoidable issues.
Is there anything that can be done about this without breaking a lot of code?