4 ms·
I’m surprised game engines do conversion from degrees to radian to call trigonometric functions. I would have called that bad code in an industrial context. We
by WastingMyTime89 4y ago
I’m surprised game engines do conversion from degrees to radian to call trigonometric functions. I would have called that bad code in an industrial context. We did everything in radians and converted to degrees only for displaying and input.
It was a lot more natural from us because we are a lot more familiar with radians anyway. I don’t think I have used degrees often since starting high school twenty years ago.
- qwery 4y ago> We did everything in radians and converted to degrees only for displaying and input. This is generally how game (engine) code works as well. The example in the article is an example of performing that conversion, except with turns instead of degrees.
- codeflo 4y agoI consider APIs that use degrees essentially broken. (And similarly, APIs that express ratios as numbers in [0, 100].) But you have to consider that a lot of game engines and related tools are intended for an audience without a strong programming background. You wouldn’t expect a 3D modeling tool to display radians. And if the UI shows degrees, the file format would better use degrees as well to avoid rounding errors. And then maybe you want the scripting layer to use the same values that the UI does. And so on.
- anonymoushn 4y agoThe post says that programmers convert to radians to call APIs that take radians and then immediately divide by pi before computing the sine. So doing everything in radians would still involve an extra floating point divide compared to the alternative.
- WastingMyTime89 4y agoNo, you are confused. That’s a conversion back to degree after computing the sine. You don’t randomly divide by pi for no reason.
- anonymoushn 4y agoso you're telling me 4/pi is the conversion ratio between degrees and radians, and i am confused? If you would be so kind, point out the part of the sine implementation that works in degrees: https://github.com/reyoung/avx_mathfun/blob/be617bbcf66993c4f7e7d267ed9926cd8e7d4f02/avx_mathfun.h#L355 https://github.com/reyoung/avx_mathfun/blob/be617bbcf66993c4...
- meheleventyone 4y agoMost game engines work in radians under the hood and expose degrees in the UI but still need to glue the UI values to the API which is the code seen in Casey’s Godot example the full context of which is a color picker and h has already been converted from degrees. Godot itself has a bunch of the API in degrees which is pretty bleugh.
- shadowgovt 4y agoIt's for convenience of developing tooling. Because the only thing harder than re-framing all of mathematics so that sine and cosine are properly defined in terms of turns would be teaching artists and level designers to believe that a full turn is 2π radians instead of 360 degrees.
- meheleventyone 4y agoYeah tooling is fine in degrees, which is what I was saying in the first part off my post. It’s more mixing it in the API rather than at the boundaries that is bleugh.
- shadowgovt 4y agoThe API is intended to directly support tooling (which is, generally, just another app running atop the same engine).
- meheleventyone 4y agoMost APIs are intended to be used, doesn’t mean you need to mix units, particularly when they both use the same basic type and thus are easy to muddle up. That’s why you keep the API consistent and deal with conversion at the edges. I get you’re probably very keen on Godot but it’s definitely one of the weird warts that all engines accumulate and my intention isn’t to say it’s bad because of this choice. Just that I don’t like that choice and the reason why.
- 4y ago