Problem Can't make animation work

DesideriusPapp

New member
Joined
May 23, 2009
Messages
21
Reaction score
0
Points
0
Hi all. I wonder if someone can give me a hint on the following.

I'm trying to set up a simple animation, and tried to follow the API documentation and sample code for ShuttleA. This is what I did:


Code:
Strelka::Strelka (OBJHANDLE hVessel, int fmodel)
: VESSEL2 (hVessel, fmodel)
{
    DefineAnimations();
    BayStatus = CLOSED;
    DoorProc = 0.0;
    DoorSpeed = 0.1;
}
 
...
 
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Strelka::DefineAnimations()[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]   static[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] UINT bay_a_grps [1] = {61};[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]   static[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MGROUP_ROTATE bay_a (0, bay_a_grps, 1, _V(7.08,7.08,184.9467), _V(-1,1,0), ([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]float[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) (PI*2/3));[/SIZE]
 
[SIZE=2][COLOR=#0000ff]    [/COLOR]BayAnimation = CreateAnimation (0.0);[/SIZE]
[SIZE=2][COLOR=#0000ff]    [/COLOR]AddAnimationComponent (BayAnimation, 0, 1, &bay_a);[/SIZE]
[SIZE=2]}[/SIZE]
void Strelka::OperateBayDoor (double simt)
{
    if (BayStatus == CLOSING || BayStatus == OPENING)
    {
        double da = oapiGetSimStep()*DoorSpeed;
        if (BayStatus == CLOSING)
        {
            if (DoorProc > 0.0) DoorProc = max (0.0, DoorProc-da);
            else BayStatus = CLOSED;
        }
        else
        {
            if (DoorProc < 1.0) DoorProc = min (1.0, DoorProc+da);
            else BayStatus = OPEN;
        }
        SetAnimation (BayAnimation, DoorProc);
    }
}
 
void Strelka::RevertBayDoor()
{
    ActivateBayDoor (BayStatus == CLOSED || BayStatus == CLOSING ? OPENING : CLOSING);
}
 
void Strelka::ActivateBayDoor(BayDoorStatus action)
{
    BayStatus = action;
}
 
int Strelka::clbkConsumeBufferedKey(DWORD key, bool down, char *keystate)
{
    if (!down) return 0;
    if (KEYMOD_SHIFT (keystate)) {}
    else
    {
        if (KEYMOD_CONTROL (keystate))
        {
            switch (key)
            {
            case OAPI_KEY_K:
                RevertBayDoor();
                return 1;
             }
        }
    }
    return 0;
}

The mesh index should be ok as I checked with MeshDebug, and the code compiles. I noticed ShuttleA uses clbkPostState, which I tried, compiled, but got no result whatsoever. I also tried SetAnimState in place of SetAnimation, and RegisterAnimSequence in place of CreateAnimation.

What is it I am missing? I've no C++ experience, so please be patient.

Thank you!
 
When are you calling OperateBayDoor?
 
That's quite the issue, I guess: where should I call it? From what I can tell, the ShuttleA code calls e.g.: the RotatePod function on mouse click, while I can't make out any reference to a call when pressing a key (but I assume that's my (lack of) ability in reading code). I tried calling it from clbkConsumeBufferedKey after RevertBayDoor but got no result. Then I tried, as I said, to use clbkPostEvent which I understand should run with every state update - with no success.

I must apologize if I'm asking something obvious but this is my first coding experience and I can't seem to find a way out without bothering.

-------------FIXED--------------------------------------------------------------------------------------------------------

I'm a bit embarassed. To anyone interested, moved into clbkPostEvent, and it works. Reason why it didn't before is... actually, as I've coded it, I should have pressed CTRL+K, not just K.

Sorry.
 
Last edited:
Back
Top