Created
August 17, 2013 11:15
-
-
Save quakeboy/6256434 to your computer and use it in GitHub Desktop.
Converting angle to indexes, or vector -> angle -> indexes.. I have done this at least 4 times in my life for various games/projects before, yet have to do it each time again. So here is a gist for it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float degangle = atan2f(t_dir.x, t_dir.y)*180/M_PI; | |
//pushing it down, so that -22.5 becomes the new 0 | |
degangle += 22.5f; | |
//now making the final range as 0 - 360 | |
if (degangle < 0) degangle += 360; | |
//now this var is ranged 0 - 7, with -22.5f to 22.5f being 0 and so on... | |
m_DirectionIndex = (int)floorf(degangle/22.5f); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment