I'm having an issue here with rotation in OpenGL. Before I changed my rendering function the rotation I had for my object worked fine, but now it seems to be messed up.
I changed my rendering function because I wanted to be able to clip the image (render frames of the image), whereas before I was just rendering things on a 1 object, 1 image basis.
The rendering is fine, just the rotation to clarify that. Here's my current rendering code:
void DrawRotateAdv(int x, int y, int width, int height, float sourceX, float sourceY, float imageWidth, float imageHeight,
GLuint texture, float angle, bool blendFlag)
{
glTranslatef((GLfloat) x + (width / 2), (GLfloat) y + (height / 2), 0.0);
glRotatef(angle, 0.0, 0.0, 1.0);
if (blendFlag)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
glBindTexture(GL_TEXTURE_2D, texture);
float texscaleX = 1.0f / (float)(imageWidth / width);
float texscaleY = 1.0f / (float)(imageHeight / height);
sourceX = sourceX / (float)imageWidth;
sourceY = sourceY / (float)imageHeight;
glBegin(GL_QUADS);
// Top-left vertex (corner)
glTexCoord2f(sourceX, sourceY);
glVertex2i( (-width / 2), (-height / 2));
//Bottom-left vertex (corner)
glTexCoord2f(sourceX, sourceY + texscaleY);
glVertex2i( (width / 2), (-height / 2));
//Bottom-right vertex (corner)
glTexCoord2f(sourceX + texscaleX, sourceY + texscaleY);
glVertex2i( (width / 2), (height / 2));
//Top-right vertex (corner)
glTexCoord2f( sourceX + texscaleX, sourceY);
glVertex2i( (-width / 2) , (height / 2));
glEnd();
glLoadIdentity();
}
I think that perhaps my translation is wrong? Unsure though, guess that's a stab in the dark on my part. As for the getting the angle:
angle = atan2((cEnemy->position.y - (float)position.y), cEnemy->position.x - (float)position.x) / 3.14159265f * 180;
But I don't think that's the issue, like I said it worked before-hand perfectly. Screenshot of the output:
