useflashpunk / FlashPunk

A free ActionScript 3 library designed for developing 2D Flash games. It provides you with a fast, clean framework to prototype and develop your games in. This means that most of the dirty work (timestep, animation, input, and collision to name a few) is already coded for you and ready to go, giving you more time and energy to concentrate on the design and testing of your game.
http://useflashpunk.net
MIT License
390 stars 134 forks source link

Angles are negated (and in degrees, but we'll let that one slide) #22

Open Draknek opened 13 years ago

Draknek commented 13 years ago

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?

dabrorius commented 11 years ago

OMG, and I thought I was doing my trigonometry wrong all this time...

zachwlewis commented 11 years ago

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.

AbelToy commented 11 years ago

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.

zachwlewis commented 11 years ago

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.

Things To Consider

AbelToy commented 11 years ago

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.

zachwlewis commented 11 years ago

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?

Draknek commented 11 years ago

@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.

BNeutral commented 10 years ago

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.