Results 1 to 3 of 3

Thread: Help with Rotation Algorithm

  1. #1
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    Help with Rotation Algorithm

    Hi All

    Can anyone help with some rotation logic. I have the following code:

    [pascal]procedure DrawRectangle(x,y,w,h:single); Overload;
    begin
    glBegin( GL_TRIANGLE_STRIP ); // Drawing Using Triangles
    glTexCoord2f(0,0);
    glVertex2f( x, y );

    glTexCoord2f(0,1);
    glVertex2f( x, y+H );

    glTexCoord2f(1,0);
    glVertex2f( x+W, y );

    glTexCoord2f(1,1);
    glVertex2f( x+W, y+H );
    glEnd; // Finished Drawing The Triangle
    end; [/pascal]

    Now I would like to add a 'RotateDegrees : Single' parameter and the Image will be drawn rotated by RotateDegrees. If possible I want it rotated around the center of the item.

    I have tried glRotatef(45,1,1,0) and it doesnt work properly. It seems the image is rotated but the left bit is clipped off. Also it draws the image offset as per screen rotation instead of the original location with only an image rotated.

    Thanks
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  2. #2

    Help with Rotation Algorithm

    You should rotate around z axis i.e. glRotatef(45,0,0,1). To rotate around images's center try this code
    Code:
    glPushMatrix;
    glTranslatef(x+W/2,y+H/2,0);  //transate to the center of the image
    glRotatef(45,0,0,1); //rotate
    glBegin(GL_QUADS); //draw
    glVertex2i(-w/2,-h/2);
    glVertex2i(w/2,-h/2);
    glVertex2i(w/2,h/2);
    glVertex2i(-w/2,h/2);
    glEnd;
    glPopMatrix;

  3. #3
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    Help with Rotation Algorithm

    Thanks - I got it working

    [pascal]procedure DrawRectangle(ox,oy,ex,ey,x,y,w,h,a:single); Overload;
    begin
    glPushMatrix;
    glTranslatef(x+W/2,y+H/2,0); //transate to the center of the image
    glRotatef(A,0,0,1); //rotate
    glBegin( GL_TRIANGLE_STRIP ); // Drawing Using Triangles
    glTexCoord2f(ox,oy);
    glVertex2f( -w / 2, -h / 2);
    glTexCoord2f(ox,ey);
    glVertex2f( -w / 2, +H / 2);
    glTexCoord2f(ex,oy);
    glVertex2f( +W / 2, -h / 2);
    glTexCoord2f(ex,ey);
    glVertex2f( +W / 2, +H / 2);
    glEnd; // Finished Drawing The Triangle
    glEnd;
    glPopMatrix;
    end;
    [/pascal]

    Not I have Rotation working. Got Blending Working - and I've learnt a lot about OpenGL and the way it does things this week.

    I am busy getting my wrappers together in a set of documented libraries and will make it publically available again soon. (Probably just after the contest ends)
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

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
  •