• Advertisement
Sign in to follow this  

2D rotation issues

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

If you intended to correct an error in the post then please contact us.

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);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    glBindTexture(GL_TEXTURE_2D, texture);
    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);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);		

Share this post

Link to post
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.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement