Nikos123 Posted October 31, 2016 Share Posted October 31, 2016 Where do you guys measure angles from in Games? Ie what is 0 degrees relative to? ATM I am using 0 as from south to North, or straight up. However I'm tempted to making it the +tve x direction. Quote Link to comment Share on other sites More sharing options...
b10b Posted October 31, 2016 Share Posted October 31, 2016 I use clockwise: 0 is 12 o'clock / straight up and 0.5 is 6 o'clock / straight down. I also label positional things in a clockwise fashion, e.g. up right down left controllers, points etc. Clockwise is a convention that is adaptable to many scenarios, easily understood and easily adhered to. Quote Link to comment Share on other sites More sharing options...
stay Posted October 31, 2016 Share Posted October 31, 2016 HTML5 Canvas uses the +x axis as 0 degrees/radians, with positive angles in the anticlockwise direction. That's also the standard in trigonometry: https://en.wikipedia.org/wiki/Angle http://www.regentsprep.org/regents/math/algtrig/ATT3/referenceAngles.htm Using another standard means you'll have to convert frequently if you want to use standard routines like Math.atan2(), which are pretty dang useful. I recommend using +x. Nikos123 1 Quote Link to comment Share on other sites More sharing options...
b10b Posted November 1, 2016 Share Posted November 1, 2016 17 hours ago, stay said: Using another standard means you'll have to convert frequently if you want to use standard routines like Math.atan2(). True, but we usually don't limit our Games to the x-y plane just because Math and Canvas are rooted in 2D trigonometry. So I'm cautious of this being significant. Conversion is almost always necessary at some part of the process irrespective of the trigonometric standard / reference axis. Else we assume that the view's orientation is directly proportional to the model (or global view). The atan2 example is good (because the method documentation specifies input values of "y" and "x"), but I would encourage adoption choices be made based on the cost of conversion of such functions (that probably won't make it into optimised production code as-is) versus the conceptual advantage of the alternatives (specifically for the development of Games). Same applies to units (e.g. degrees vs radians vs the many alternatives). Quote Link to comment Share on other sites More sharing options...
stay Posted November 1, 2016 Share Posted November 1, 2016 1 hour ago, b10b said: I would encourage adoption choices be made based on the cost of conversion of such functions [..] versus the conceptual advantage of the alternatives Makes sense. I confess that in some previous game work I used straight up as 0 degrees, which made more sense for the artists working on our games. They wanted to create art pointing up by default. Similarly, while the programmers used radians internally, we always supported degrees in game-designer-focused tools and data files, and carefully defined places where we'd convert from degrees to radians in the game engine. Since this is an html5-specific forum, I think Math and Canvas standards are particularly relevant, but I admit I'm doing all my coding directly to the canvas API and not using a popular engine. I don't know how other html5 engines approach this. At a quick glance, it looks like Phaser and Pixi both use +x, clockwise rotations, and radians, but I might have read this wrong. b10b 1 Quote Link to comment Share on other sites More sharing options...
Nikos123 Posted November 2, 2016 Author Share Posted November 2, 2016 atm I've been basing all my degrees at starting from 12 oclock, but am still tempted to go back to my Maths roots. I also prefer to work in degrees , not radians. https://github.com/QuantumInformation/youtube-space-invaders/blob/master/src/util/Math.ts#L22 More opinions wanted! Quote Link to comment Share on other sites More sharing options...
Nikos123 Posted November 4, 2016 Author Share Posted November 4, 2016 atan2 is good too, but I convert by adding 90 degrees to the angle to get 0 as north Quote Link to comment Share on other sites More sharing options...
Nikos123 Posted November 4, 2016 Author Share Posted November 4, 2016 I'm gonna switch to working in Radians now instead of degrees, and just have constants for the radians based on human directions Quote Link to comment Share on other sites More sharing options...
marcgfx Posted November 7, 2016 Share Posted November 7, 2016 I work with radians and 0 is on the right. I am very glad about this choice, as it would be a real pain to have to adapt all math functions. having 0 at the top for artists is fine, but there is no need to have to convert anything else imho. my unit images start from the top and rotate clockwise. but this is a pretty simple conversion to find the correct image. if you want to use sin/cos/atan2 its just much more straightforward to have 0 on the right and use the x/y axis as they are used on screen. Quote Link to comment Share on other sites More sharing options...
Fricken Hamster Posted December 14, 2016 Share Posted December 14, 2016 0 is right. Degress go counterclockwise. I read that a lot of rendering engines had it like this because of some implementation in opengl. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.