Animation Controllers what to do next!

Started by
0 comments, last by adder_noir 13 years, 7 months ago
Hi, here's some code I've written to perform some animations:

anim_defines.h:
#ifndef ANIM_DEFINES_H_INCLUDED#define ANIM_DEFINES_H_INCLUDED#include <iostream>#include <d3d9.h>#include <d3dx9.h>#include <vector>struct AnimFrame{    D3DXMATRIX localTransMat;    D3DXMATRIX boneOffset;    std::vector<unsigned int> meshContainer;    struct AnimFrame* child;};extern AnimFrame upperRightArmFrame;extern AnimFrame lowerRightArmFrame;#endif // ANIM_DEFINES_H_INCLUDED/


Sets up the struct and declares the anim frame globals with extern to prevent linker errors. I'm only animating two limbs for now.

The present animation recursive function:

void animate_arm_mesh(AnimFrame* frame, D3DXMATRIX* parent)    {        unsigned int i = 0;        D3DXMATRIX local = frame->localTransMat;        D3DXMATRIX combined;        D3DXMATRIX temp;        D3DXMATRIX offsetInverse;        D3DXMATRIX offset = frame->boneOffset;        float doff = D3DXMatrixDeterminant(&frame->boneOffset);        D3DXMatrixInverse(&offsetInverse, &doff, &frame->boneOffset);        ///////////////////////////////////////////////////////////////////////////        D3DXMatrixMultiply(&temp, &offsetInverse, &local);        D3DXMatrixMultiply(&temp, &temp, &offset);        D3DXMatrixMultiply(&combined, &temp, parent);        ///////////////////////////////////////////////////////////////////////////        for(i = 0; i < frame->meshContainer.size(); i++)        {            currentPos.x = vertices[frame->meshContainer].X;            currentPos.y = vertices[frame->meshContainer].Y;            currentPos.z = vertices[frame->meshContainer].Z;            currentNormals.x = vertices[frame->meshContainer].NORMAL.x;            currentNormals.y = vertices[frame->meshContainer].NORMAL.y;            currentNormals.z = vertices[frame->meshContainer].NORMAL.z;            D3DXVec3TransformCoord(&newPos, ¤tPos, &combined);            D3DXVec3TransformNormal(&newNormals, ¤tNormals, &combined);            newVertices[frame->meshContainer].X = newPos.x;            newVertices[frame->meshContainer].Y = newPos.y;            newVertices[frame->meshContainer].Z = newPos.z;            newVertices[frame->meshContainer].NORMAL.x = newNormals.x;            newVertices[frame->meshContainer].NORMAL.y = newNormals.y;            newVertices[frame->meshContainer].NORMAL.z = newNormals.z;        }        ///////////////////////////////////////////////////////////////////////////        AnimFrame* child = frame->child;        if(frame->child != NULL)        {            animate_arm_mesh(child, &combined);        }        ///////////////////////////////////////////////////////////////////////////        VOID* pVoid;        v_buffer->Lock(0, 0, (void**)&pVoid, 0);        memcpy(pVoid, &newVertices[0], newVertices.size() * sizeof(CUSTOMVERTEX));        v_buffer->Unlock();        return;    }


This loops through each limb starting at the designated parent. Performs arbitrary axis transformations (rotations only in this case) and updates the mesh container all in one. I know copying verts is bad but I've yet to implement a HLSL version of this that's for the future.

The code that calls it all:

soldier.load_soldier_hierachy();    soldier.set_poses();    D3DXMATRIX identity;    D3DXMatrixIdentity(&identity);    soldier.animate_arm_mesh(&upperRightArmFrame, &identity);


And the set poses function:

void set_poses(void)    {        D3DXMATRIX matRotate1;        D3DXMATRIX matRotate2;        D3DXVECTOR3 axis;        axis.x = 0.0f; axis.y = 0.0f; axis.z = 1.0f;        D3DXMatrixRotationAxis(&matRotate1, &axis, 0.4);        upperRightArmFrame.localTransMat = matRotate1;        axis.x = 1.0f; axis.y = -1.0f; axis.z = 0.0f;        D3DXMatrixRotationAxis(&matRotate1, &axis, -1.571);        axis.x = 0.0f; axis.y = 0.0f; axis.z =1.0f;        D3DXMatrixRotationAxis(&matRotate2, &axis, 1.571);        D3DXMatrixMultiply(&matRotate2, &matRotate1, &matRotate2);        lowerRightArmFrame.localTransMat = matRotate2;        return;    }


Now I don't expect *anyone* to gleam a damn thing from my source code as it isn't well explained enough in this topic but I reckon you can get a *feel* for what I'm doing.

Well I have two main questions:

1)Is what I've done above carped in some way or is it ok (for a rough start)? It produces proper results - but that's not the point I'm worried about efficiency and structuring.

2)How do I go about arranging all this professionally? Ok so I can animate. Big deal. What I want to know is how is it best to set-up your complete animation layout. Will I need a seperate class for controlling animations? I was thinking of one header file (or cpp file) with all the required poses pre-calced. An animation controller class could then acquire the current pose and slerp it to the next one. Is this a good idea?

Pretty vague topic really sorry. I just want some input on where to go from here. I can provide full source and resources to anyone interested through pm - use at your own risk! ;o) Thanks, *any* input appreciated.
Advertisement
As it happens I've finally compiled and run someone else's engine. I'll be going with that instead - much better decision I think. Thanks anyway guys this topic can be deleted or locked cheers ;o)

*Edit*

Someone on another forum told me I'd be dumb to drop all the work I've done to date so ok I'll continue with this too and if I discover anything useful for other noobs I'll post it. WHy not I suppose.

[Edited by - adder_noir on August 26, 2010 7:58:25 AM]

This topic is closed to new replies.

Advertisement