• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

questions on parsing mdl files and animating

Status
Not open for further replies.
Level 2
Joined
Jan 27, 2008
Messages
5
I'm working on parsing mdl files for rendering them using opengl. I've already gotten the simple stuff done, vertices, normals, textures, etc. are all being parsed and I can render them correctly.

Right now I'm stuck on the animation. I have several questions and if anyone can help with any of them I'd greatly appreciate it.

I'm updating all of the vertices by:

1. translating them by their pivot point (given by their vertex group)
2. applying the transformation from the attached bone
3. adding back the translation from the pivot point.

The above is probably wrong, so please help if it is...

I guess my first question is what should I be doing when there is more than one matrix for the vertex group? Does this mean that I have to deal with more than one pivot point? Should I apply the same 3 steps above multiple times (once for each matrix entry / bone)?

Also is it true that the position of a pivot point changes as the parent bone/helper is moved/rotated
?

Thanks in advance for any help!
 
1rst when a vertex is linked to a matrix with more than 1 bones, the affects of the bones redestribut proportionally. So if a vertex is linked to bone1 and bone2, and bone 1 moves 50 units towards X, the vertex will move (moving units/ number of bones) in other words 50/2: 25. Same happens with scale and rotation (be carefull with rotations, though)

2nd Yes, it's true. If the parent bone moves, the children move too, unless they have the tag "DoesnotInheritTranslation" or something like it. In the case of rotation, the pivot rotates according to the parent's pivot point, think of the parent's pivot as the center of a circle and child's of a vertex, when you rotate the center 45º, the vertex rotates along the axis, but keeps the same radius distance.
 
Level 2
Joined
Jan 27, 2008
Messages
5
Thanks for the help!

You really seem to know what you're talking about, so if you don't mind helping me out again I'd really appreciate it....

I'm still a little curious about rotations. It seems that using a the same method for hermite interpolation that I'm using for translations and scaling does not also work in interpolating rotations. Do I have to use slurp to interpolate rotations?

Also you mentioned that the scale and rotation of a vertex is also divided by the number of attached bones, does this mean that if I have a 360 degree rotation around the x axis and the vertex is linked to three bones then the resulting rotation is only 120 degrees? I can see how this would be a bit more difficult with quaternions...

Thanks again!
 
Level 2
Joined
Jan 27, 2008
Messages
5
Thanks for the quick reply.

Sorry I don't think I was too clear in my last post. I was just curious about what you meant by "Same happens with scale and rotation (be carefull with rotations, though)" in your first post.

Anyway, thanks! I'd really appreciate seeing your code.

I'm still a little confused. I may have made a mistake somewhere else in my code, so I just want to clarify... Do I use the same hermite and bezier interpolation method for interpolating quaternions that I do for interpolating translations?

Sorry, I should maybe explain what I'm trying to do, in case anyone is interested. I'm just taking a break from my research in Augmented Reality stuff to make a quick AR port of a chess game (sorta like sony's eye of judgement game but with chess) I'm just doing it for fun, and don't plan on distributing it or anything. Anyway, I can do all of the user interaction and AR stuff, tracking the board, etc, but I wanted to add some animated models (sorta like the old battle chess game), and that's why I'm interested in using warcraft 3 models, I think they'd make an awesome chess set:)
 
you know, is hard for me to tell you. I've never tried interpolating a quaternion. I know that they use a special system, and they are only interpolated in linear and hermite. For hermite we use a very special system for building the tangents, which is based in the famous TCB convination (Tention, Continuity, Bias).

JASS:
library Interpolation

    function Linear_Intp takes real a, real b, real t returns real
        return a + (b - a)*t
    endfunction

    function Bezier_Intp takes real a, real b, real c, real d, real t returns real
    local real ab = a + (b - a)*t
    local real bc = b + (c - b)*t
    local real cd = c + (d - c)*t
    local real m = ab + (bc - ab)*t
    local real n = bc + (cd - bc)*t
        return  m + (n - m)*t
    endfunction

    function Bezier_Intp_Alt takes real a, real b, real c, real d, real t returns real
    local real m = t*t
        return  a + 3*t*(b - a) + 3*m*(c - 2*b + a) + m*t*(3*(b-c) + d - a)
    endfunction

    function Power takes real n, integer pow returns real
    if pow > 0 then
       return n*Power(n,pow-1)
    endif
    return 1.0
    endfunction

    function GetCardTan takes real p1, real p3 returns real
       return 0.5*(p3-p1)
    endfunction

// t = tension, c = continuety, b = bias
// tension is how sharply the curve makes turns.
// continuety specifies the rate of change between speed and direction.
// bias specifies the direction of the curve.
// sidenote: specify p1 as 0, when working with 2 points

// the next function returns the intan of p2

    function InTan takes real p1, real p2, real p3, real t, real c, real b returns real
           return (1.0-t)*(1.0-c)*(1.0+b)*(p2-p1)/2 + (1.0-t)*(1.0+c)*(1.0-b)*(p3-p2)/2
    endfunction

// the next function returns the outtan of p2

    function OutTan takes real p1, real p2, real p3, real t, real c, real b returns real
           return (1.0-t)*(1.0+c)*(1.0+b)*(p2-p1)/2 + (1.0-t)*(1.0-c)*(1.0-b)*(p3-p2)/2
    endfunction

    function Hermite_Intp takes real p1, real p2, real t1, real t2, real s returns real
    local real s2 = s*s
    local real h1 = 8.0*s*s2 - 9.0*s2
    local real h2 = h1*(-1)
    local real h3 = s2*(s - 2.0) + s
    local real h4 = s2*(s - 1.0)
    set h1 = h1 + 1
    return h1*p1 + h2*p2 + h3*t1 + h4*t2
    endfunction

endlibrary

use TCB for correct interpolation.
 
Status
Not open for further replies.
Top