CAP5937 - Realtime Graphics for Simulation and Games

Lecture 11: Direct3D Frames and Animation

J. Michael Moshell

This lesson is based on Trujillo's Chapter 7.

Basic recursive frames. Pretty simple; examplified by MOLECULES demo. Read pages 253-265.

Query 11.1. Develop a function B(c,d) which computes the number of balls in a tree with 'children' parameter c and 'depth' parameter d.

ANSWER

Draw a few trees. For the tree where (c,d) = 2,3 we have a tree with depth 3, and each node has two children at each stage. So the layers contain 1, 2 and 4 balls and B(2,3) = 7. For a tree with (c,d) = 3,4 we can see that the layers would contain 1, 3, 9 and 27 balls and so B(3,4) = 40.

From this pattern with (c,d)=3,4  it is obvious that each layer adds c times as many children as the layer above it. Layer 1 adds c0=1; layer 2 adds c1=c=3; layer 3 adds c2=9. So the amount added at each layer k is ck-1. We can write the whole expression as

I. B(c,d) = SUM for i=0 to d-1 of c = 1 + c + c2 +...+cd-1

We need a closed form for this. Remembering or reinventing the old shift-technique for summing series:

II. c*B(c,d) = c  + c2 +...+cd-1 + cd

We subtract I from II, yielding

(c-1)*B(c,d) = cd - 1

So B(c,d) = (cd - 1)/(c-1)

We try a few values from our samples above.B(3,4) = (34 -1)/(3-1) = (81-1)/2 = 40. Hurrah.

/ANSWER

Key-Framing. D3D can do it linearly or with splines - for the smoooooth effect.

The animation object stores a list of rotate and position keys, each associated with a time value. These value sequences were simply stored in an array by the program's author.

On text page 275, the UpdatateScene callback function is added to the 'meshframe' object by

    meshframe->AddMoveCallback( UpdateScene, animation);

Then, this meshframe is provided to the animation object:

    animation->SefFrame (meshframe);

This UpdateScene is the heart of the stepping-forward process for the animation (page 276).

void RocketWin::UpdateScene(LPDIRECT3DFRMFRAME, void* p, D3DVALUE)
{
    LPDIRECT3DRMANIMATION animation=(LPDIRECT3DRMANIMATION) p;
    static D3DVALUE time;
    time+=speed;
    animation->SetTime( time );
}

So, we can see that the animation object's behavior is directly analogous to that of a VRML interpolator. When its time index marches forward, it interpolates the appropriate values from its rotate and position keys. What range of values corresponds to the range of the keys?

Here are three logical possibilities; there are others.

(1) the index might run from 0 to k, if k is highest index in the arrays of keys. In the example, there are eleven keys defining ten interpolation regions.

(2) the index might be normalized to run from 0 to 1 across the entire animation, as it is in VRML.

(3) the animation object might accept parameters specifying the lowest and highest index values for the animation.

Query 11.2: Study the Rocket example and determine which of these methods (or possibly some other one)  is used.

ANSWER

Actually the method used is a hybrid of (1) and (3), because you actually store time index values into the keys. Close study of the loop on page 272/273, repeated on 274, shows that key values are being inserted for each value of i in the loop. But you could in fact be stuffing any values you'd like in there, so we aren't tied down to the strict range of rule (1) above. We have the flexibility of rule (3) but in this case it is being implemented like rule (1).

/ANSWER

Linear and Splined Animation.

on page 277 we see how an options variable is managed when using the menu,  by fetching the current value:

void RocketWin::OnUpdateAnimationLinear(CCmdUI* pCmdUI)
{
    D3DRMANIMATIONOPTIONS options;
    options = animation -> GetOptions();
    pCmdUI -> SetCheck( options & D3DRMANIMATION_LINEARPOSITION);
}

There is also acontrol for whether the animation is closed (thus recycles repeatedly by taking the index modulo its largest value) versus just freezing at the last keyframe for any index values larger than the maximum index (and equivalently for index values below the minimum.)

Query 11.3: Explain the operation of the LookAt function on page 288.

ANSWER

It works almost exactly like the LOOKAT function in OpenGL. Namely, it generates the necessary transformation matrix on top of the Current Transform Matrix stack to rotate the local coordinate system (which would be the camera system, in OpenGL) so that its z axis points at the specified location. This would imply, by the way, that the rocket's long axis is modeled along z in its coordinate system, since this seems to be the way the rocket points.

/ANSWER

Unanswered Questions.

What kind of splines are used, and what degree of control over the smoothness is available? Answering these questions would require going deeply into the D3D API. Instead, let's go get a paper about splines and use this lesson time to do some useful spline exercises.
 
 

To the syllabus
To lecture 10
To lecture 12