How do you rotate a sprite around its center by caclulating a new x and y position?
<p>I'm using Dark GDK and C++ to create a simple 2d game. I'm rotating an object but it rotates from the top left corner of the sprite.</p>

<p>I have the following variables available:</p>

<ul>
<li>PlayerX </li>
<li>PlayerY</li>
<li>PlayerWidth</li>
<li>PlayerHeight </li>
<li>RotateAngle (360 > x > 0)</li>
</ul>

<p>Is there an algorithm that will modify the pivot point of the sprite, preferable to the center?</p>

<p>Here is a <em>small</em> code sample:</p>

<pre><code>void Player::Move( void )
{

    if ( checkLeft() )
    {
     PlayerX -= PlayerSpeed;
     if ( PlayerX &lt; 0 )
      PlayerX = 0;
    }

    if ( checkRight() )
    {
     PlayerX += PlayerSpeed ;
     if ( PlayerX &gt; 800 - PlayerWidth )
      PlayerX = 800 - PlayerWidth;
    }

    if ( checkUp())
    {
     PlayerY -= PlayerSpeed;
     if ( PlayerY &lt; 0 )
      PlayerY = 0;
    }

    if ( checkDown())
    {
     PlayerY += PlayerSpeed;
     if ( PlayerY &gt; 600 -  PlayerHeight)
      PlayerY = 600 - PlayerHeight;
    }

    RotateAngle += 5;
    if(RotateAngle &gt; 360)
     RotateAngle -=360;

    dbRotateSprite(Handle,RotateAngle);
    dbSprite ( 1 , PlayerX , PlayerY , Handle );
}
</code></pre>

<p><strong>Edit</strong></p>

<p>I'm considering opening up some reputation for this question, I have yet to be provided with an answer that works for me. If someone can provide an actual code sample that does the job, I'd be very happy. </p>

<p>The problem with Blindy's answer is that no matter how much I simply translate it back or forth, the spirte still rotates around the top left hand corner and moving it somewhere rotating around the top left corner, then moving it back to the same position accomplishes nothing. Here is what I believe to be going on:</p>

<p><img src="http://img248.imageshack.us/img248/6717/36512474.png" alt="alt text" /></p>

<p>Just so there is no confusion I have created a an image of what is going on. The left shows what is actually happening and the right shows what I need to happen.</p>

<p><img src="http://img101.imageshack.us/img101/1593/36679446.png" alt="alt text" /></p>
