Sign in to follow this  

2D rotation issues

This topic is 4110 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);
    
    if(disableBlending)
        glDisable(GL_BLEND);
    
    if(tint.additive)
        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
    
    glBegin(GL_QUADS);
        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);
    
    if(tint.additive)
        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.

GOODLUCK!

Share this post


Link to post
Share on other sites

This topic is 4110 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this