We get it. We use ad blockers too. But GameDev.net displays them so we can continue to be a great platform for you.
Please whitelist GameDev.net and our advertisers.
Also consider a GDNet+ Pro subscription to remove all ads from GameDev.net.
GameDev.net Posting Guidelines (please read before posting)
For Beginners Forum FAQs (please read before posting)
Subscribe to GameDev.net's newsletters to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 30 November 2012 - 11:15 AM
Posted 30 November 2012 - 12:48 PM
Posted 30 November 2012 - 01:07 PM
Posted 30 November 2012 - 01:41 PM
enum Direction8 {N,NE,E,SE,S,SW,W,NW}; Direction8 direction8(double x, double y) { static double const Cosine = std::cos(0.5*std::atan(1.0)), Sine = std::sin(0.5*std::atan(1.0)); double rx = x*Cosine - y*Sine; double ry = x*Sine + y*Cosine; int i = 7 - (std::abs(rx) > std::abs(ry)); if (ry < 0.0) i = 11-i; if (rx < 0.0) i = 7-i; return Direction8(i); }
Posted 30 November 2012 - 01:54 PM
Edited by xinfinite33, 30 November 2012 - 02:02 PM.
Posted 30 November 2012 - 02:16 PM
ಠ__ಠ... but i'm trying to find a simpler solution that doesn't use division or other expensive operations, just for the sake of tiny optimizations lol
const char* cardinal_direction(float ang) { // Assuming sane negative numbers, +y is up, 4-byte alignment static const char* label[8][4] = {"E", "NE", "N", "NW", "W", "SW", "S", "SE"}; return label[(int)(fmodf((ang+17*pi/8),2*pi)*4/pi)]; } const char* cardinal_direction(float dy,float dx) { return cardinal_direction(atan2(dy,dx)); }(Though unreadable and perhaps unmaintainable, this was a fun exercise.)
Posted 30 November 2012 - 02:46 PM
Edited by xinfinite33, 30 November 2012 - 02:47 PM.
Posted 30 November 2012 - 03:10 PM
loool I know it Isn't that much of a difference when it comes to optimizing since we can do millions of operations a second. I cant remember where but I read somewhere that division was the slowest operation out of all the others, excluding the case where your'e multiplying numbers less than one, then division is faster. I apologize for my novice assumption as I am still fairly new to programming .
Posted 30 November 2012 - 04:57 PM
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.