Results 1 to 3 of 3

Thread: Rotate image around an arbitrary point in OpenGL?

  1. #1

    Rotate image around an arbitrary point in OpenGL?

    Ok, one of my developers thought if funny to pose this question to me. I thought I had the answer and once I showed him the code it didn't work at all . This made me think quite a bit and I still can't come up with an answer (other then switching from QUAD rendering to triangle rendering and using the triangle center point as the image 0 point).

    Given:
    Code:
          glBegin(GL_QUADS);
            glTexCoord2f( textLeft, textTop );
            glVertex2f( 0, 0 );
    
            glTexCoord2f( textLeft, textBottom );
            glVertex2f( 0, dstH);
    
            glTexCoord2f( textRight, textBottom );
            glVertex2f( dstW, dstH);
    
            glTexCoord2f( textRight, textTop );
            glVertex2f( dstW, 0 );
          glEnd;
    where dstH and dstW are the Height and Width of the pattern being displayed (not the image but the pattern within the image).

    You translate by simply adding glTranslatef(dstX, dstY) easy enough.

    But, if I want to rotate the image around the point (17, 34) how do I do it?

    My initial answer was simply translate to -point rotate translate to dst+point. This of course doesn't work. Neither does any combination of this . So I'm guessing that you have to perform the matrix translation by hand and then render the quad in the appropriate rotation. Is there a pure OpenGL way to handle this besides moving to Triangle rendering?

  2. #2

    Rotate image around an arbitrary point in OpenGL?

    Your first logics are correct actually, just fine tuning.

    1) Move view to wanted center point, place that image rotates around
    2) Rotate
    3) Move to the inverse coordinates of image rotate point
    4) Draw normally (0,0,Width,Height)

  3. #3

    Rotate image around an arbitrary point in OpenGL?

    Thanks for the answer. After looking back through the sample I gave him I had my translations in the wrong order . Now everything is working just fine and I look like I know something again .

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •