Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL rotation in 2D
    primarykey
    data
    text
    <p>I have a simple OpenGL application, which displays a line. I store <code>x1, y1, x2</code> and <code>y2</code> in global variables. </p> <p>The rotation function uses the <code>feedback</code> functionality, discussed <a href="https://stackoverflow.com/questions/3277519/opengl-retrieve-raw-vertex-and-index-buffer-from-displayed-objects-in-opengl">here</a> and the translation to origin method, suggested <a href="https://stackoverflow.com/questions/3442743/opengl-es-rotating-3d-model-around-itself">here</a>. It's intended to rotate a line around it's center.</p> <p>Here's the code: </p> <pre><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(); } </code></pre> <p>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 ).</p> <p>Why doesn't this code work ? How do I rotate a line around it's center ( or any arbitrary point ) in 2D ?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload