Thread: natural leg movement

  1. #1
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743

    Question natural leg movement

    Well, I have solved my rotation problem (for anyone who might have been wondering). It was hard to find, but easy to fix once found (as most errors are).

    Anyways, I am wondering about how to do something correctly and efficiently. I am sure I could probably do this some hacked up sort of way, but I was wondering if anybody had done this before and could enlighten me on how they did it.

    I am rotating my legs of my 3d model so that they walk, however, I do not want the legs to stay like stiff boards, I want them to bend at the knee so that it looks like a natural walking movement.

    Rotating the bottom half of the leg from the knee down is not the problem, but making it stay with the top part of the leg as the top part of the leg does its own thing is the hard part. For example, I could easily rotate the bottom part of the leg making it look like it is doing its natural movement, and I could easily rotate the top half of the leg making it look like it is doing its natural movement, but the top and bottom halves need to stay attatched to each other the whole time.....we dont want to have an amputated leg.

    So somehow I guess I need to keep track of the position of the bottom coordinates of the top half of the leg, and then translate the bottom half of the leg up to those bottom coordinates every frame to make sure it stays with the top half of the leg. I dont know...thats what I was thinking.

    Give me your ideas. A picture is below.
    My Website

    "Circular logic is good because it is."

  2. #2
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    You need to implement a skeletal animation system based on joints. Each joint has a 4x4 matrix which has a rotation component and a translation component. In order to get this to work the way you want each joint has a matrix and a parent (except for the root joint). You need to multiply the current matrix by the parent's matrix before multiplying each vertex owned by the joint by the final matrix which represents all of the transformations. If you want super realism you also implement a system of 'weights' based on vertex distances from bones, so that each vertex is affected by *all* joints in the model, but mostly affected by the closest joints (this gives the effects of lucid moving skin over the skeleton).

    skelanim with milkshape3d, doesn't do the weights, but the matrix mathematics stays mostly the same.

    http://rsn.gamedev.net/tutorials/ms3danim.asp

    and you cannot actually build the tutorials he posted on his site, so I had to hack through and make the .net and msvcpp 6 versions work:
    http://www.thedevelopersalliance.com...5/SKELANIM.zip

    http://www.thedevelopersalliance.com...KELANIMNET.zip
    Last edited by Silvercord; 01-10-2004 at 09:23 AM.

  3. #3
    Registered User Aalmaron's Avatar
    Join Date
    Jan 2004
    Location
    In front of a monitor
    Posts
    48
    i'd sugest decompiling a half life model in milkshape, and then looking at the walk animation for it.

  4. #4
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    he's talking about the programming side of it...it's up to the animator to actually make the animation sequences

    and david, something i didn't mention, in your picture above you'd have a joint at the hip, a joint at the knee, and then probably a joint at the ankle.

  5. #5
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    also do a research on "inverse kinematics" on google, it is very useful in figuring out how a movement would affect the different joints.

    also, silvercord, is the reason you have to multiply each joints matrix by the parent matrix is so that you concencate(sp?) the rotations/translations? I can pretty easily figure out what such a matrix would look like, but I dont feel like having to fill several pages worth of paper to solve out a few problems.

    EDIT: what i mean by the above is sort of like if you want to rotate and translate a vector in homogenous space(figured out what that 'w' coordinate was all about ), you would make up a rotation matrix, then make a translate matrix, then multiply them together(in this case is it cummanitive(sp?) no matter the order, as I know regular matrical multiplacation is not), and that will give the proper matrix to convert those vertices points to world space.
    Last edited by EvBladeRunnervE; 01-10-2004 at 02:43 PM.

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Most games do not take this approach. Most of them use actual actors to act out the various sequences in the game, be it running or pulling someone out of a vehicle as in GTA 3. The actor has lights or sensors at each of his/her important joints. A very simple vertex model is then derived from these points. Then the model team goes to work and refines the vertexes into an actual model, skins it, etc. So each frame of animation is skinned and modeled and put into a file. All the game is really doing is replaying that sequence frame by frame. To further illustrate this try to do a second action whilst doing another. The first action usually must complete prior to the second action's animation playing resulting in a bit of lag time between key press and actual execution.

    Most of you who have played FPS's know this because sometimes your character jumps or skips a frame resulting in some odd sequnces being rendered. Most games are getting a lot better at playing transitional frames - the actor acts out what it would look like to transition from jumping to diving, etc. These transition sequences are then played/rendered back.

    Very few developers have the time or manpower required to create each movement from a series of multiplies and equations. Not to mention it would be very hard to do even the simplest animation. Most everything has been pre-rendered, placed into a file and keyframed, and then is played back.

    My advice is to pre-render your characters in an art program like 3D Studio Max, save it to a file and keyframe the animationm and then use Direct3D to "re-play" the sequence. You don't have to use keyframing but this is just one popular method.

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by Bubba
    Most games do not take this approach. Most of them use actual actors to act out the various sequences in the game, be it running or pulling someone out of a vehicle as in GTA 3. The actor has lights or sensors at each of his/her important joints. A very simple vertex model is then derived from these points. Then the model team goes to work and refines the vertexes into an actual model, skins it, etc. So each frame of animation is skinned and modeled and put into a file. All the game is really doing is replaying that sequence frame by frame. To further illustrate this try to do a second action whilst doing another. The first action usually must complete prior to the second action's animation playing resulting in a bit of lag time between key press and actual execution.

    Most of you who have played FPS's know this because sometimes your character jumps or skips a frame resulting in some odd sequnces being rendered. Most games are getting a lot better at playing transitional frames - the actor acts out what it would look like to transition from jumping to diving, etc. These transition sequences are then played/rendered back.

    Very few developers have the time or manpower required to create each movement from a series of multiplies and equations. Not to mention it would be very hard to do even the simplest animation. Most everything has been pre-rendered, placed into a file and keyframed, and then is played back.

    My advice is to pre-render your characters in an art program like 3D Studio Max, save it to a file and keyframe the animationm and then use Direct3D to "re-play" the sequence. You don't have to use keyframing but this is just one popular method.
    We used skeletal animation in our latest game and it worked fine. No problems whatsoever.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  8. #8
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    Bubba, no offense buddy, but what are you talking about? For one, the talk about how professional game studios strap the light bulbs to actors and then use those is pointless because I doubt davidp has the resources to do that. And also, David is talking about doing rotations, not keyframe animations, and subsequently what I said about the skeletal animation and concatenating matrices is the most appropriate.

  9. #9
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I didn't say it couldn't be done, but most are not doing it. Go to GTA 3's website. You can view animations of the characters as well as how they were accomplished. Plus a lot of my game magazines are talking to developers and many of them are using this technique because its quicker and easier.

    Now with real-time skeletal animation you could cause your character to crumple down against a wall or physically react to his/her environment which would be cool, but most don't. Just shoot someone next to a wall and watch what happens. They normally end up lying down in the same position as their other dead companions with one head or both legs sticking through the wall.

    There is a recent game that uses skeletal animation albeit it need a bit of refining since the characters tend to end up in some very...shall we say 'acrobatic'...positions.

  10. #10
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    I respect you as a programmer Bubba, but on this one I completely disagree. Skeletal animation is fine, little problems with a leg sticking into a wall won't totally ruin everything...for crying out loud we're *not* professional game developers, and trying to make everything perfect is too much stress.

  11. #11
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    My point is this: pre-render the people or whatever it is. It's the easiest way to do it. Yes you can use store a matrix for every object and compound the rotations by concatenating on down the line of objects. There is a tutorial about this on gamedev. However, I don't think this is the best way to do it.

    Pre-rendered these walking legs would only take a couple of frames to accomplish some very convincing animation and would take out a whole lot of multiplies in the code - since you are simply rendering another pre-made model instead of mathematically altering one.

    If you really want to do some mathematical stuff then interpolate between two known models to get an intermediate model. This would also produce some very convincing animation.

    And I know we are not professional's, that's why I'm saying pre-render it.

  12. #12
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    Bubba...you do know that skeletal animation is pre-rendered, right?

  13. #13
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    No. I thought skeletal animation consisted of nodes and joints that affected other nodes and joints. In other words I thought it was purely mathematical movement, which would be very hard to simulate a person using this approach.

  14. #14
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    Hell no! An animator goes in there and sets the keyframes of joints and when they get to that keyframe, and all you do is interpolate the angles to produce smooth rotations (esp with quaternions if you've implemented them)

  15. #15
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    Thanks, Silvercord for the links and info about skeletal information.

    Mr. Wizard, you say you used skeletal animation in your last project? Maybe you could help me out?
    My Website

    "Circular logic is good because it is."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Meshes and Movement
    By Dark_Phoenix in forum Game Programming
    Replies: 1
    Last Post: 09-16-2007, 06:26 PM
  2. Opengl walking leg animation
    By Bobby230 in forum C Programming
    Replies: 3
    Last Post: 03-05-2006, 03:41 PM
  3. I need movement...
    By Finchie_88 in forum C++ Programming
    Replies: 1
    Last Post: 10-04-2004, 03:10 PM
  4. same sex marriages
    By major_small in forum A Brief History of Cprogramming.com
    Replies: 159
    Last Post: 11-29-2003, 03:38 PM
  5. New game-Time-based movement?
    By napkin111 in forum Game Programming
    Replies: 6
    Last Post: 01-18-2003, 01:50 AM