Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Keyframe animation

  1. #1
    Guest

    Keyframe animation

    Hi, I need to learn about keyframe animation and linearly interpolating between keyframes, but I've been unable to find any tutorials or examples around the net.

    Can anyone point me to a good example of keyframe animations (source code, obviously)?

    Thanks.

  2. #2

  3. #3
    Guest

    Re: Keyframe animation

    Thanks for the link. Here's another question:

    I have a text file which my program uses to build a table (there are 10 pieces of the table, and the file contains tranlation and scaling information for its corresponding glut cube.) I need to animate the legs, which are made of 2 pieces with a joint in the middle (like the knee of a leg.) Basically, I want to rotate the upper leg around the joint it makes with the table top (that works fine), but then I want to rotate the lower leg around the joint it makes with the upper leg, but in the opposite direction.

    How do I get the location of the "knee" joint after a rotation has been applied to it? I can get the original locations from the text file, but when the leg rotates, the location of the joint obviously changes.

    Thanks.

  4. #4
    Intern Contributor nemesis's Avatar
    Join Date
    Nov 2001
    Posts
    92

    Re: Keyframe animation

    Apply the rotation to the "knee" joint coordinates as well. This is:

    If the rotation center is not (0,0,0), which probably isn't, you will have to translate the local system to the center of the scene, apply the rotation, and translate it back to its original position. Then you will get the coordinates of the rotated "knee".

    Er... was that what you were asking? Ô_ô

  5. #5
    Guest

    Re: Keyframe animation

    You may very well be giving me the right information, but let me just clarify (for both of us) what I mean to make sure of it. I have a leg made up of two parts. The upper leg (the thigh of a real leg) rotates at an angle 'a' (through an animation, not all at once) around the joint it makes with the table top, and conversely, the lower leg (the calf of a real leg) rotates at an angle -a around the joint it makes with the upper leg.

    Basically, I think I need to make the joint point (in other words, the bottom middle point on the upper leg) the 0,0,0 point for which to rotate the lower leg around.

    Does this make sense (I'm very beginner at this)? Are you suggesting that I move the entire scene such that the knee joint is at 0,0,0 in the coordinate system, rotate the lower leg, and then translate back? That makes sense, and it's what I've been trying to do, however, as the upper leg rotates, I lose the new coordinates of the knee joint. I can easily rotate the lower leg around where the knee was originally.

    Thanks a ton for your help.

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,096

    Re: Keyframe animation

    You can use the glPush/pop to creat joints for motion.

    //Object
    glPushMatrix(); // Save matrix 1
    glTranslate // Location of object
    glRotate // Rotation of object
    Draw_base();
    //Build first arm
    glPushMatrix() // Save matrix 2
    glTranslate //Location of arm in relation to base object.
    glRotate //Rotation of arm in relation to base object.
    Draw_arm_section();
    // Draw joint for next section of arm
    glPushMatrix(); // Save matrix 3
    glTranslate // Location of second section relative to first arm section.
    glRotate // Rotate joint select axis of motion relative to first section
    Draw_arm_section();
    glPopMatrix();
    glPopMatrix();
    //Here we would start with another arm

    glPopMatix(); // Restore matrix to before drawing this object.

    A good example is my clock demo on my website, www.angelfire.com/linux/nexusone/


    Originally posted by NeoBender:
    You may very well be giving me the right information, but let me just clarify (for both of us) what I mean to make sure of it. I have a leg made up of two parts. The upper leg (the thigh of a real leg) rotates at an angle 'a' (through an animation, not all at once) around the joint it makes with the table top, and conversely, the lower leg (the calf of a real leg) rotates at an angle -a around the joint it makes with the upper leg.

    Basically, I think I need to make the joint point (in other words, the bottom middle point on the upper leg) the 0,0,0 point for which to rotate the lower leg around.

    Does this make sense (I'm very beginner at this)? Are you suggesting that I move the entire scene such that the knee joint is at 0,0,0 in the coordinate system, rotate the lower leg, and then translate back? That makes sense, and it's what I've been trying to do, however, as the upper leg rotates, I lose the new coordinates of the knee joint. I can easily rotate the lower leg around where the knee was originally.

    Thanks a ton for your help.


    [This message has been edited by nexusone (edited 04-25-2003).]

  7. #7
    Guest

    Re: Keyframe animation

    Unfortunately, that doesn't work. If I rotate the upper leg, then the lower leg rotates with it, but then rotating the lower leg skews it terribly.

  8. #8
    Guest

    Re: Keyframe animation

    Let me explain better. When I click the button to have the rotation, the following happens to the top leg:

    glPushMatrix();
    glTranslatef(//whatever the file says)
    glScalef(//whatever the file says)
    ...
    glTranslatef(0.0,0.0,0.5); //trans to joint
    glRotatef(45.0,0.0,1.0,0.0); //rotate about joint
    glTranslatef(0.0,0.0,-0.5); //trans back
    ...
    glutSolidCube(...);

    Now, how would I make an opposite rotation to the bottom leg? Just putting -90 for the rotation angle doesn't work.

  9. #9
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,096

    Re: Keyframe animation

    Did you understand my code example, also did you look at my clock example of push/pop useage?

    Also remember rotations and translations work in reverse order....

    glTranslate
    glRotate

    is not the same as

    glRotate
    glTranslate

    The order in which you do things is very important!!!!


    Originally posted by NeoBender:
    Let me explain better. When I click the button to have the rotation, the following happens to the top leg:

    glPushMatrix();
    glTranslatef(//whatever the file says)
    glScalef(//whatever the file says)
    ...
    glTranslatef(0.0,0.0,0.5); //trans to joint
    glRotatef(45.0,0.0,1.0,0.0); //rotate about joint
    glTranslatef(0.0,0.0,-0.5); //trans back
    ...
    glutSolidCube(...);

    Now, how would I make an opposite rotation to the bottom leg? Just putting -90 for the rotation angle doesn't work.


    [This message has been edited by nexusone (edited 04-25-2003).]

  10. #10
    Guest

    Re: Keyframe animation

    I can draw the table just fine using the technique you described. But when I start the rotations (by clicking a piece), it messes up.

    So, bascially, if I rotate the upper leg 45 degrees, then the lower leg goes with it 45 degrees, and changes from:

    |
    |

    to

    \
    \

    Then, if I apply a rotation directly to the lower leg, it doesn't rotate correctly. I need it to look like:

    \
    /

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •