Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3486756
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:04:06+00:00 2026-05-18T11:04:06+00:00

I have a simple OpenGL application, which displays a line. I store x1, y1,

  • 0

I have a simple OpenGL application, which displays a line. I store x1, y1, x2 and y2 in global variables.

The rotation function uses the feedback functionality, discussed here and the translation to origin method, suggested here. It’s intended to rotate a line around it’s center.

Here’s the code:


void rotate( float theta )
{

    GLfloat* buff = new GLfloat[5];
    glFeedbackBuffer( 5, GL_2D, buff );
    glRenderMode( GL_FEEDBACK );

    int center_x = x1 + ( x2 - x1 )/2;
    int center_y = y1 + ( y2 - y1 )/2;

    glPushMatrix();
        glTranslatef( -center_x, -center_y, 0 );
        glRotatef( theta, 0, 0, 1 );
        glTranslatef( center_x, center_y, 0 );
        line();
    glPopMatrix();

    x1 = (int)buff[1];
    y1 = (int)buff[2];
    x2 = (int)buff[3];
    y2 = (int)buff[4];

    delete[] buff;
    glutPostRedisplay();
}

However, the two translations seem to have little effect – the line still rotates around the lower-left corner of the window. In addition, the line gets clipped if it doesn’t fit on the visible surface ( this doesn’t happen with the translations commented out – the line simply refuses to move if it would fall outside the visible surface ).

Why doesn’t this code work ? How do I rotate a line around it’s center ( or any arbitrary point ) in 2D ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:04:07+00:00Added an answer on May 18, 2026 at 11:04 am

    Looks to me like you’re translating in the wrong direction and the origin is being placed outside your viewport in the lower-left. You want to move the origin to the point you want to translate around–so if the origin is in the lower-left, you need to translate +center_x, +center_y. Rotate, translate back (-center_x, -center_y), then draw.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple iPhone application which uses OpenGL ES (v1) to draw a
I have written a simple OpenGL program in C++ that displays a line joining
I have a simple OpenGL application where I have 2 objects displayed on screen:
I am new to OpenGL. I have to develop a simple 3D application. I
I wrote a simple opengl application in C which plots sin(x). This is my
I have a simple solid modeling application in which I want to implement several
I have been writing an OpenGL game engine for a while which uses SDL
I am creating a simple opengl application which obviously includes some 3d-objects and textures.
I have an application that uses OpenGL on a GLSurfaceView. The problem is that
I have a simple OpenGL drawing. When the user changes the window's size, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.