Atan2 table c++
<p>I'm trying to calculate the angles of two points in 2D space. It works with the following:</p>

<pre><code>double angle;
x = player-&gt;x - x;
z = player-&gt;z - y;

angle = atan2 (x, y);
angle *= (180.0 / M_PI);
if(angle &lt; 0) angle += 360;
if(angle &gt;= 360) angle -= 360;

return angle;
</code></pre>

<p>However I want to use a table for better results:</p>

<pre><code>x = player-&gt;x - x;
z = player-&gt;y - y;

return atanTable[x+32][y+32];
</code></pre>

<p>With init:</p>

<pre><code>int xp = -32;
int yp = -32;
for (int x = 0; x &lt; 64; x++, xp++)
    for (int y = 0; y &lt; 64; y++, yp++){
        double angle;

        angle = atan2 (xp, yp);
        angle *= (180.0 / M_PI);
        if(angle &lt; 0) angle += 360;
        if(angle &gt;= 360) angle -= 360;
        atanTable[x][y] = angle;
    }
</code></pre>

<p>The angle is only calculated for values -32 to 32 for x and y.</p>

<p>The table is not properly produced however. I get values of only around 359 and 0, while I should get a range of 0 to 360 degrees.</p>

<p>Am I misusing atan2 somehow?</p>
