C++ Question [Solved] AddAnimationComponent & parent inheritance...

N_Molson

Addon Developer
Addon Developer
Donator
Joined
Mar 5, 2010
Messages
10,002
Reaction score
4,418
Points
203
Location
Toulouse
Hi, :tiphat:

I'm trying to code a complex animation (well, the most complex I ever did), and I'm kinda stucked. I've seen other thread on a similar subject, but it doesn't help me, I'm missing something.

The object I want to animate is an antenna, or rather the arm under it. There are 4 articulated segments that I want to deploy at the same time (not in sequence). This lead us to the parent/child problem. No problem for the first segment, the rotation axis is static. But the three other segments are another story. As the first segment moves, it moves the rotation axis of the second segment, and so on...

So I looked at the Atlantis.cpp code, because the RMS arm is a more complex application of the same idea. But I get lost somewhere. Also I want a reversible animation, which doesn't make things easier.

I get weird results ; in fact the last 3 segments don't seem to inherit the rotation axis reference correctly from their respective parents.

In "DefineAnimations" :

Code:
    ANIMATIONCOMPONENT_HANDLE parent;

    static UINT AntGrp_01[15] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,16}; 
    MainAnt[0] = new MGROUP_ROTATE (2, AntGrp_01, 15, _V(-1.08,2.23,-0.975), _V(0,0,1), (float)(RAD*90));
    anim_ant_1 = CreateAnimation (0);
    parent = AddAnimationComponent (anim_ant_1, 0, 1, MainAnt[0]);

    static UINT AntGrp_02[13] = {1,2,3,5,6,8,9,10,11,12,13,14,16};
    MainAnt[1] = new MGROUP_ROTATE (2, AntGrp_02, 13, _V(-0.77,2.24,-0.955), _V(0,0,-1), (float)(RAD*175));
    anim_ant_2 = CreateAnimation (0);
    parent = AddAnimationComponent (anim_ant_2, 0, 1, MainAnt[1], parent);

    static UINT AntGrp_03[11] = {1,2,3,8,9,10,11,12,13,14,16};
    MainAnt[2] = new MGROUP_ROTATE (2, AntGrp_03, 11, _V(-1.08,2.29,-0.955), _V(0,0,1), (float)(RAD*175));
    anim_ant_3 = CreateAnimation (0);
    parent = AddAnimationComponent (anim_ant_3, 0, 1, MainAnt[2], parent);

    static UINT AntGrp_04[9] = {2,3,8,10,11,12,13,14,16};
    MainAnt[3] = new MGROUP_ROTATE (2, AntGrp_04,  9, _V(-0.77,2.32,-0.955), _V(0,0,-1), (float)(RAD*145));
    anim_ant_4 = CreateAnimation (0);
    parent = AddAnimationComponent (anim_ant_4, 0, 1, MainAnt[3], parent);

Then the structure that allows reversibility (triggered by a key) :

Code:
void RLM::ActivateAntenna (DoorStatus action)
{
    ant_status = action;
}

void RLM::RevertAntenna (void)
{
    ActivateAntenna ((ant_status == DOOR_CLOSED || ant_status == DOOR_CLOSING) ?
        DOOR_OPENING : DOOR_CLOSING);
}

Finally, in ClbkPostStep (animation/time relation):

Code:
    if (ant_d_status >= DOOR_CLOSING) {
        double da = simdt * ANTENNA_OPERATING_SPEED;
        if (ant_d_status == DOOR_CLOSING) {
            if (ant_d_proc > 0.0) ant_d_proc = max (0.0, ant_d_proc-da);
            else                ant_d_status = DOOR_CLOSED;
        } else {
            if (ant_d_proc < 1.0) ant_d_proc = min (1.0, ant_d_proc+da);
            else                ant_d_status = DOOR_OPEN;
        }

        SetAnimation (anim_ant_1, ant_d_proc);
        SetAnimation (anim_ant_2, ant_d_proc);
        SetAnimation (anim_ant_3, ant_d_proc);
        SetAnimation (anim_ant_4, ant_d_proc);
    }

Thanks for reading this and thanks even more if you can do something for me. I don't pretend to understand the detail of everything posted above, but I think I have the big picture. I'm an amateur, but still have to carry on my projects, y'see. :cheers:
 
Last edited:
I could do it for you in SC3. Then you would need to code it.
 
When you define the animations groups, you shouldn't be repeating the groups in every line.

At the moment, the code you have is
Code:
static UINT AntGrp_01[15] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,16};
...
static UINT AntGrp_02[13] = {1,2,3,5,6,8,9,10,11,12,13,14,16};
...
static UINT AntGrp_03[11] = {1,2,3,8,9,10,11,12,13,14,16};
...
static UINT AntGrp_04[9] = {2,3,8,10,11,12,13,14,16};
It should be more like
Code:
static UINT AntGrp_01[2] = {4,7};
...
static UINT AntGrp_02[2] = {5,6};
...
static UINT AntGrp_03[2] = {1,9};
...
static UINT AntGrp_04[9] = {2,3,8,10,11,12,13,14,16};
I'm guessing at the group numbers, but hopefully you get the idea. Because of the parent, groups 5 and 6 will automatically be rotated in Animation 1.
 
Last edited:
Brillant, that did it perfectly !!! :speakcool: :jj:

Thank you very much !! :cheers: :thankyou:
 
Thanks! This solved my wobbly wheels problem.
 
Back
Top