Results 1 to 2 of 2

Thread: rotate 2D texture/stack of 2D textures

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2014

    rotate 2D texture/stack of 2D textures

    I'm trying to apply rotations to stack of textures (working on volume rendering project). My rendering code looks like that:
    Code :
    static void RenderSceneCB()
        float viewPortSize = 1.0;
        for (int i = 0; i < z; ++i)
            glRotatef(angleX, 1.0, 0.0, 0.0);
            glRotatef(angleY, 0.0, 1.0, 0.0);
            glRotatef(angleZ, 0.0, 0.0, 1.0);
            glBindTexture(GL_TEXTURE_2D, texturesObjects[i]);
            glTexCoord2f(0.0f, 0.0f);
            glVertex3f(-viewPortSize, -viewPortSize, 2 * i / static_cast<float>(z)-1);
            glTexCoord2f(1.0f, 0.0f);
            glVertex3f(viewPortSize, -viewPortSize, 2 * i / static_cast<float>(z)-1);
            glTexCoord2f(1.0f, 1.0f);
            glVertex3f(viewPortSize, viewPortSize, 2 * i / static_cast<float>(z)-1);
            glTexCoord2f(0.0f, 1.0f);
            glVertex3f(-viewPortSize, viewPortSize, 2 * i / static_cast<float>(z)-1);
            glBindTexture(GL_TEXTURE_2D, 0);

    Those rotations seem to even work, however while rotating along X axis the object after 90 degrees flips and starts to rotate the other way. Secondly, the object magically stretches and does not fit in viewport sometimes. Additionally, I drew 3 vectors imitating axises, and I see that while rotating along X axis or Y axis all of them are floating. Only while rotating along Z axis that vector representing Z axis stands still like it should. I cannot figure out why is this happening.

  2. #2
    Member Newbie
    Join Date
    Apr 2014
    What you are experiencing is called "Gimbal Lock" since you are doing "roll/pitch/yaw" with Euler Angles. Because the rotations are done in turn, when one axis causes a rotation which aligns itself parallel another axes you lose control along the second axis. For other rotation options, there's a lot of good work on quaternions you can use if you google for it. I would guess in your project you probably want user interaction, so researching "track ball rotations" might be the best fit for you.

    If the object stretches near the edge of the frame, your perspective is experiencing bending due to effects of the field of view angle. Lowering your field of view angle for your camera can compensate for this. If you post a picture you can help us a lot here.

Similar Threads

  1. Using matrix stack - my code seems to modify the whole stack
    By chromosom in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-04-2014, 03:12 AM
  2. Moving Texture and Stack Order
    By VASIMR in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 04-30-2011, 02:03 PM
  3. 3D Texture or stack of 2D Textures
    By iris_raj in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 05-02-2007, 05:21 AM
  4. Texture Matrix - one stack for each unit?
    By Robbo in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 07-31-2002, 04:42 AM
  5. Replies: 6
    Last Post: 10-09-2000, 09:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean