Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think that you may be trying to transfer your learning of mathematical transformations too directly to OpenGL. Interpreting what you've written literally, you're translating away from the origin, applying the rotation, and then attempting to undo both of those towards the bottom, in reverse order. It looks like you're trying to "undo" the transformations for some other transformation to happen later.</p> <p>When we talk about transformations mathematically this makes sense, but in code we have a nice shortcut in <code>glPushMatrix()</code> and <code>glPopMatrix()</code>, where you can use both to "wrap" your transformations in a specific scope. It is very similar to a function scope, or a loop scope -- whatever transformations happen within this block won't influence anything outside of that scope.</p> <p><strong>The good:</strong></p> <pre><code>GL11.glTranslatef(centerX, centerY, centerZ); GL11.glRotatef(rot, 0f, 0f, 1f); </code></pre> <p>This applies your transformations to centerX, centerY, and centerZ, and then applies your rotation about the z-axis.</p> <p><strong>The bad:</strong></p> <pre><code>GL11.glRotatef(-rot, 0f, 0f, 1f); GL11.glTranslatef(-centerX, -centerY, -centerZ); </code></pre> <p>The <code>glRotatef</code> and <code>glTranslatef</code> here are unnecessary and can be commented out or removed. </p> <p>This is how you would define the scope of a single "object" using your code:</p> <pre><code>GL11.glPushMatrix(); // Apply transformations here GL11.glBegin(GL11.GL_QUADS); // Draw object here GL11.glEnd(); GL11.glPopMatrix(); </code></pre> <p>So if you want to include other objects that won't be influenced by the transformation and rotation of your cube, you would wrap those transformations in a Push/Pop block. Here's another <a href="https://stackoverflow.com/questions/7031842/how-do-glpushmatrix-and-glpopmatrix-keep-the-scene-the-same">question</a> that covers pushing and popping a bit better than I have here.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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