# 2D rotation issues

This topic is 4421 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm trying to do the typical 'pivot rotation' with opengl (as well as d3d) but I cant seem to get the math right. I know I should be using matrices but I'm not very good with them so I thought I would try solving it with trig. Aparently I cant do that either. Would someone be able to point me in the right direction? I've been googling for days but can't find a tutorial that I can understand :\. Heres my opengl pivot rotation function that isnt working:
void Bitmap::pivotBlitToScreenHardware(int screenX, int screenY, int bitmapX, int bitmapY, float rotation, const Tint &tint, bool disableBlending)
{
glColor4f(tint.r, tint.g, tint.b, tint.a);

if(disableBlending)
glDisable(GL_BLEND);

glBlendFunc(GL_SRC_ALPHA, GL_ONE);

glBindTexture(GL_TEXTURE_2D, texture);

glPushMatrix();

glTranslatef(screenX, screenY, 0);
glRotatef(rotation * 360 + 180, 0, 0, 1);

// u and v specify the size of the actual image inside the texture
// 1, 1 would mean the image is taking up the full texture size
// w and h are the size of the whole texture

glTexCoord2f(0.0f, 0.0f);
glVertex2f(-bitmapX, -bitmapY);
glTexCoord2f(0.0f, v);
glVertex2f(-bitmapX, h - bitmapY);
glTexCoord2f(u, v);
glVertex2f(w - bitmapX, h - bitmapY);
glTexCoord2f(u, 0.0f);
glVertex2f(w - bitmapX, -bitmapY);
glEnd();

glPopMatrix();

if(disableBlending)
glEnable(GL_BLEND);

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}



##### Share on other sites
Im assuming that the problem you are having is that you are able to move your object back and forth, but when it comes to turing, its flying all over the screen in a circle? i had a similar problem, and it turned out to be what was happening was i was rotating it in WORLD space and not in the objects space. also make sure what you are doing in your matrix transformations you are doing the following:

WorldMatrix = rotateMatrix * translationMatrix * scalingMatrix.

now i was doing that and was still running into your problem ,but what solved my problem was when i was moving, i updated my x and y coordinate i did this:

x = x *sin(angle);
y = y *cos(angle);

i dont have the code in front of me so i might have hte cos/sin backwards, but give that a shot.

GOODLUCK!

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632993
• Total Posts
3009762
• ### Who's Online (See full list)

There are no registered users currently online

×