I have a function to perform sprite rotation :
void Sprite::rotateSprite(float angle){
//Making an array of vertices - 6 for 2 triangles
Vector2<gamePos> halfDims(_rect.w / 2, _rect.h /2);
Vector2<gamePos> bl(-halfDims.x,-halfDims.y);
Vector2<gamePos> tl(-halfDims.x,halfDims.y);
Vector2<gamePos> br(halfDims.x,-halfDims.y);
Vector2<gamePos> tr(halfDims.x,halfDims.y);
bl = rotatePoint(bl,angle) + halfDims;
br = rotatePoint(br,angle) + halfDims;
tl = rotatePoint(tl,angle) + halfDims;
tr = rotatePoint(tr,angle) + halfDims;
/**
1st triangle
**/
//Top right
_dataPointer.vertices[0].setPosition(_rect.x+tr.x,_rect.y+tr.y);
//Top left
_dataPointer.vertices[1].setPosition(_rect.x+tl.x,_rect.y+tl.y);
//Bottom left
_dataPointer.vertices[2].setPosition(_rect.x+bl.x,_rect.y+bl.y);
/**
2nd triangle
**/
//Bottom left
_dataPointer.vertices[3].setPosition(_rect.x+bl.x,_rect.y+bl.y);
//Bottom right
_dataPointer.vertices[4].setPosition(_rect.x+br.x,_rect.y+br.y);
//Top right
_dataPointer.vertices[5].setPosition(_rect.x+tr.x,_rect.y+tr.y);
}
Vector2<gamePos> Sprite::rotatePoint(Vector2<gamePos> pos, float& angle){
Vector2<gamePos> newv;
newv.x = pos.x * cos(angle) - pos.y * sin(angle);
newv.y = pos.y * cos(angle) + pos.x * sin(angle);
return newv;
}
Am i doing something wrong ? It happens also when i put small angle (even if i put here angle 1 )
Thanks for help.