Results 1 to 5 of 5

Thread: Rotating one of a set of double doors 90 degrees

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    5

    Rotating one of a set of double doors 90 degrees

    Hi there,

    I'm currently making a gallery and at the moment I'm having trouble with Rotatef() and rotating one of my doors (set of double doors) 90 degrees so its open.

    Basically I've created 1 door in the door function in my program then I have a builddoor function which can calls the door function to translate and rotate the other door.

    Ive tried using:
    glRotatef(90.0f,0.0f,1.0f,0.0f);

    But it sends the door completely out of the gallery in random directions.

    Can anyone help?

    My code
    ----



    void door()
    {

    //front of door texture
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, DoorID);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    // Door Front Quad
    glBegin(GL_QUADS);
    glNormal3f(0.0, 0.0f, -1.0f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f(20.0f, -7.0f, -49.8f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f(20.0f, 10.0f, -49.8f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(30.0f, 10.0f, -49.8f);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(30.0f, -7.0f, -49.8f);
    glEnd();
    glDisable(GL_TEXTURE_2D);

    // Door Back Texture
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, DoorID);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    // Door Back Quad
    glBegin(GL_QUADS);
    glNormal3f(0.0, 0.0f, -1.0f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f(20.0f, -7.0f, -50.2f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f(20.0f, 10.0f, -50.2f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(30.0f, 10.0f, -50.2f);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(30.0f, -7.0f, -50.2f);
    glEnd();
    glDisable(GL_TEXTURE_2D);


    // Door End Texture

    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, Door2ID);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    // Door End Quad
    glBegin(GL_QUADS);
    glNormal3f(-1.0, 0.0f, 0.0f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 30.0f, -7.0f, -49.8f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 30.0f, 10.0f, -49.8f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f( 30.0f, 10.0f, -50.2f);
    glTexCoord2f(0.0f, 0.0f); glVertex3f( 30.0f, -7.0f, -50.2f);
    glEnd();
    glDisable(GL_TEXTURE_2D);


    // Door End Texture
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, Door2ID);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    // Door End Quad
    glBegin(GL_QUADS);
    glNormal3f(-1.0, 0.0f, 0.0f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 20.0f, -7.0f, -49.8f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 20.0f, 10.0f, -49.8f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f( 20.0f, 10.0f, -50.2f);
    glTexCoord2f(0.0f, 0.0f); glVertex3f( 20.0f, -7.0f, -50.2f);
    glEnd();
    glDisable(GL_TEXTURE_2D);
    }

    void builddoor()

    {

    glPushMatrix();
    door(); // first door
    glPopMatrix();


    glPushMatrix();
    glTranslatef(10.0, 0.0, 00.0);// places 2nd door by the other
    //so the doors appear closed
    glRotatef(90.0f,0.0f,1.0f,0.0f); // ????????
    door();
    glPopMatrix();

    }


    Any help is greatly appreciated! Thanks

  2. #2
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,672

    Re: Rotating one of a set of double doors 90 degrees

    What is the origin point of your doors in model space? That's the coordinate system that the Y-axis rotation will be rotating around. So you need to make sure that the door's model space puts the pivot point at zero in the Y direction.

    Or, if you're unwilling to change your model, you can translate the doors to a coordinate system where the pivot point is at zero.

    Oh, and texture objects store their texture parameters. So unless some other code actually changes the texture parameters, you only need to set them once.

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    5

    Re: Rotating one of a set of double doors 90 degrees

    Hi there, thanks for the reply.

    Just trying to understand what you mean by origin point? In my first function void door() the 4 quads created there that make up the door are not translated so they contain the origin point on the first door. (theres no top side or underside to the door as its not visible)

    In builddoor() I use translatef and call door() to position the second door of the double doors + 10.0 on the x axis. (effectively creating the doors 'shut')

    ---
    glPushMatrix();
    glTranslatef(10.0, 0.0, 00.0);// places 2nd door by the other
    //so the doors appear closed
    glRotatef(90.0f,0.0f,1.0f,0.0f); // ????????
    door();
    glPopMatrix();
    ---


    The pivot point on the second door 'opening' door would be (40.0(x ,-49.8 (z))

    Thanks for the tip on texture parameters, yeah I need to remove certain bits form my code like this still. ( i realized this the other day)

    In reading you message do I understand correctly that I need to translate the door where Y would be 0....rotate the door and use translatef again back to the position required?

  4. #4
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,672

    Re: Rotating one of a set of double doors 90 degrees

    Just trying to understand what you mean by origin point?
    The origin is the (0, 0, 0) point of a coordinate system. All rotations are defined to happen around this point. You provide an axis of rotation, but the coordinate system's origin is the point that is rotated around.

    Therefore, if you want to rotate around a different point, you must first use a translation to move that object to a coordinate system where that point is the origin, do your rotation, and then move it back.

    For example:

    Code :
    glTranslatef(pivotX, pivotY, pivotZ); //return to original coordinate system.
    glRotatef(angle, 0.0f, 1.0f, 0.0f);
    glTranslatef(-pivotX, -pivotyY, -pivotZ); //Transform to coordinate system where pivot is at the origin.

  5. #5
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    5

    Re: Rotating one of a set of double doors 90 degrees

    WOO problem solved based on your original answer. Thanks. I repositioned the door so it was drawn from 0.0,0.0,0.0. Then called it twice...like so


    glPushMatrix();
    glTranslatef(20.0, -7.0, -49.;
    door();
    glPopMatrix();


    glPushMatrix();
    glTranslatef(39.9, -7.0, -49.;
    glRotatef(90.0f,0.0f,1.0f,0.0f);
    door();
    glPopMatrix();

    Cheers Alfonse

Similar Threads

  1. rotating objects in a double orbit
    By debinair in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-11-2013, 12:08 PM
  2. Rotating a directional light 360 degrees about a single axis
    By kevinfishburne in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 09-01-2012, 02:21 AM
  3. Walls, windows, and doors?
    By mikeleblanc in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 12-15-2008, 02:41 PM
  4. rotating object 90 degrees using a matrix and glMultMatrix(R);
    By TheBlackAdder in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 10-18-2005, 07:46 AM
  5. 6 Degrees of Freedon
    By Running_Wolf in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 01-09-2001, 10:20 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