API Question OAPI animations

MJR

C++ developer in the mix
Addon Developer
Tutorial Publisher
Donator
Joined
Mar 19, 2008
Messages
2,460
Reaction score
5
Points
0
Location
United States
This is what I have so far added to my future animation that I am making.

Code:
int Spacecraft::clbkConsumeBufferedKey (DWORD key, bool down, char *kstate)
{
    if (!down) return 0; // only process keydown events

    if (KEYMOD_SHIFT (kstate)) {

    } else { // unmodified keys
        switch (key) {
        case OAPI_KEY_E:  // "Engines"
            if (!Playback()) StartEngines ();
            return 1;
        }
    }
    return 0;
}

Code:
class Spacecraft: public VESSEL3 {
public:
    Spacecraft (OBJHANDLE hVessel, int flightmodel);
    ~Spacecraft ();
    void clbkSetClassCaps (FILEHANDLE cfg);
    int  clbkConsumeBufferedKey (DWORD key, bool down, char *kstate);

I am wondering what I would put to link it to the key command of "E". What type of commands would be involved because I know have done control surface animations which are automatic (basically). However I am not sure how to actually do it as of like this, press E, turbines start to spin, and press E to revert the action to stop the animation.
 

Xyon

Puts the Fun in Dysfunctional
Administrator
Moderator
Addon Developer
Webmaster
GFX Staff
Donator
Beta Tester
Joined
Aug 9, 2009
Messages
6,804
Reaction score
505
Points
203
Location
10.0.0.1
Website
www.orbiter-radio.co.uk
Preferred Pronouns
she/her
Given the code as you currently have it, making the "E" key toggle your animation would be handled by the StartEngines() function. However, since this would make the StartEngines() a daft name for it (Since it would both stop and start the engines), simply check against a flag for engines running or not and conditionally switch between a StartEngines() and a StopEngines() within your case statement there.
 

MJR

C++ developer in the mix
Addon Developer
Tutorial Publisher
Donator
Joined
Mar 19, 2008
Messages
2,460
Reaction score
5
Points
0
Location
United States
Let me see if I understand.

Start with the
Code:
class Spacecraft: public VESSEL3 {
public:
    Spacecraft (OBJHANDLE hVessel, int flightmodel);
    ~Spacecraft ();
    void clbkSetClassCaps (FILEHANDLE cfg);
    int  clbkConsumeBufferedKey (DWORD key, bool down, char *kstate);

private:
    void StartEngines();
    void StopEngines();
    static MGROUP_ROTATE Engine

Put the work into action by, StartEngine() and StopEngine().
Under those I would put
Code:
static UINT GRP_Engine = x,x,x,x,x,;
static VECTOR3 Engine_REF  = {x,x,x};
static VECTOR3 Engine_AXIS = {x,x,x};
static float Engine_RANGE = (float)(1.0*RAD);
MGROUP_ROTATE Spacecraft::trans_Engine (0, &GRP_Engine, 1, x, x, x);

Something along the lines if that? I just want to make sure that I understand it.
 
Last edited:

Wishbone

Clueless developer
Addon Developer
Joined
Sep 12, 2010
Messages
2,421
Reaction score
1
Points
0
Location
Moscow
Code:
if (EnginesRunning) 
     StopEngines();
else
{
 StartEngines();
}
 

MJR

C++ developer in the mix
Addon Developer
Tutorial Publisher
Donator
Joined
Mar 19, 2008
Messages
2,460
Reaction score
5
Points
0
Location
United States
Code:
if (EnginesRunning) 
     StopEngines();
else
{
 StartEngines();
}
That is the animation flag correct? But can anyone tell me in the previous post if the code I gave for those functions were right?
 

Wishbone

Clueless developer
Addon Developer
Joined
Sep 12, 2010
Messages
2,421
Reaction score
1
Points
0
Location
Moscow
Am not an animation guy, so cannot help you there. From my scripts (no add-ons yet) I only call SetThrusterGroupLevel, relying on :hail: you folks to do the actual running :tiphat:
 

MJR

C++ developer in the mix
Addon Developer
Tutorial Publisher
Donator
Joined
Mar 19, 2008
Messages
2,460
Reaction score
5
Points
0
Location
United States
Well, this animation is for the turbines to start spinning from the "E" action simulating start up. Then a noise plays and yada yada yada. I probably could use that one, but it wouldn't fit my purpose.

---------- Post added at 05:17 PM ---------- Previous post was at 06:52 AM ----------

At a bit of a stand still.

Code:
void Spacecraft::StartEngines()
{
static UINT GRP_Engine = 24;
static VECTOR3 Engine_REF  = {0,1,1};
static VECTOR3 Engine_AXIS = {2,3,4};
static float Engine_RANGE = (float)(1.0*RAD);
MGROUP_ROTATE Spacecraft::trans_Engine (0, &GRP_Engine, 1, Engine_REF, Engine_AXIS, Engine_RANGE);
}

Code:
class Spacecraft: public VESSEL3 {
public:
    Spacecraft (OBJHANDLE hVessel, int flightmodel);
    ~Spacecraft ();
    void clbkSetClassCaps (FILEHANDLE cfg);
    int  clbkConsumeBufferedKey (DWORD key, bool down, char *kstate);

private:
    void StartEngines();
    void StopEngines();

Would that even work? StartEngines is defined. When I press E it should reference itself to that function. I just get two errors.

Code:
1>..\..\TransportVehicle\TransportVehicle\Spacecraft.cpp(106) : error C2655: 'Spacecraft::trans_Engine' : definition or redeclaration illegal in current scope
1>        ..\..\TransportVehicle\TransportVehicle\Spacecraft.cpp(81) : see declaration of 'Spacecraft::trans_Engine'
1>..\..\TransportVehicle\TransportVehicle\Spacecraft.cpp(106) : error C2086: 'MGROUP_ROTATE Spacecraft::trans_Engine' : redefinition
1>        ..\..\TransportVehicle\TransportVehicle\Spacecraft.cpp(81) : see declaration of 'trans_Engine'
 

orb

O-F Administrator,
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
Code:
void Spacecraft::StartEngines()
{
static UINT GRP_Engine = 24;
static VECTOR3 Engine_REF  = {0,1,1};
static VECTOR3 Engine_AXIS = {2,3,4};
static float Engine_RANGE = (float)(1.0*RAD);
[color=red]MGROUP_ROTATE Spacecraft::trans_Engine (0, &GRP_Engine, 1, Engine_REF, Engine_AXIS, Engine_RANGE);[/color]
}

Why did you put the line marked with red color in that method, and also why are you defining those static variables inside that method?
 

MJR

C++ developer in the mix
Addon Developer
Tutorial Publisher
Donator
Joined
Mar 19, 2008
Messages
2,460
Reaction score
5
Points
0
Location
United States
That is the only logical way with my limited experience. I strongly felt it was wrong, but I just experimented which I don't think does any harm.

What type of animation handle could I use to place in that function? The way I set it up I don't think mine would work for this.
 

orb

O-F Administrator,
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
I don't see Spacecraft::trans_Engine declaration in the class. Is this method declared and defined somewhere?
What you've written looks like half declaration and half calling of trans_Engine method.

Putting local static variables doesn't make sense inside that method. Did you want them to be used by only this method as constants?

I would gladly help you, but I think you need to read a little more about C++ first.
 

MJR

C++ developer in the mix
Addon Developer
Tutorial Publisher
Donator
Joined
Mar 19, 2008
Messages
2,460
Reaction score
5
Points
0
Location
United States
I declared it under the vessel class. I am guessing I didn't paste it here.

Code:
class Spacecraft: public VESSEL3 {
public:
    Spacecraft (OBJHANDLE hVessel, int flightmodel);
    ~Spacecraft ();
    void clbkSetClassCaps (FILEHANDLE cfg);
    int  clbkConsumeBufferedKey (DWORD key, bool down, char *kstate);

private:
    void StartEngines();
    void StopEngines();
    static MGROUP_ROTATE trans_Engine;

I did in fact want to use it only in that "method", but you already know the outcome.
 

orb

O-F Administrator,
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
Now I don't know what kind of class member is Spacecraft::trans_Engine. Is it a method or a variable?
 

MJR

C++ developer in the mix
Addon Developer
Tutorial Publisher
Donator
Joined
Mar 19, 2008
Messages
2,460
Reaction score
5
Points
0
Location
United States
Now I don't know what kind of class member is Spacecraft::trans_Engine. Is it a method or a variable?
You know, I am going to look at the HST code real quick and see how they do it. Don't know why I didn't think of this before. I'll be back to state my progress. Thanks for the help so far.
 
Last edited:

Hielor

Defender of Truth
Donator
Beta Tester
Joined
May 30, 2008
Messages
5,580
Reaction score
2
Points
0
Code:
    static MGROUP_ROTATE trans_Engine;
I'm fairly sure you don't want that to be static--do you even know what the static keyword does?

In this case (static member of a class), there will only ever be one variable instantiated, which means that all instances of that class will share the same value. In some cases that might make sense, but something like an animation progress indicator, it absolutely doesn't.
 

MJR

C++ developer in the mix
Addon Developer
Tutorial Publisher
Donator
Joined
Mar 19, 2008
Messages
2,460
Reaction score
5
Points
0
Location
United States
I reconfigured some parts of it with the help of HST. I only get three errors compared to the 40 I just fixed. These are the errors and parts of the codes concerning them.

Code:
void Spacecraft::DefineAnimations (void)
{
    static UINT ENGINEGrp[1] = {24};
    int static MGROUP_ROTATE_ENGINE (0, ENGINEGrp, 1, _V(0,0,0), _V(-1,0,0), (float)(PI*0.50));
    anim_eng = CreateAnimation (0.5);
    AddAnimationComponent (anim_eng, 0, 1, &ENGINEGrp);

}

Code:
1>------ Rebuild All started: Project: Lucia-1, Configuration: Release Win32 ------
1>Deleting intermediate and output files for project 'Lucia-1', configuration 'Release|Win32'
1>Compiling...
1>Spacecraft.cpp
1>..\..\TransportVehicle\TransportVehicle\Spacecraft.cpp(115) : error C2078: too many initializers
1>..\..\TransportVehicle\TransportVehicle\Spacecraft.cpp(115) : warning C4244: 'initializing' : conversion from 'float' to 'int', possible loss of data
1>..\..\TransportVehicle\TransportVehicle\Spacecraft.cpp(117) : error C2664: 'VESSEL::AddAnimationComponent' : cannot convert parameter 4 from 'UINT (*)[1]' to 'MGROUP_TRANSFORM *'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

I know what the errors mean, but I done I all I could up to this point.
 
Last edited:

Hielor

Defender of Truth
Donator
Beta Tester
Joined
May 30, 2008
Messages
5,580
Reaction score
2
Points
0
I
I know what the errors mean, but I done I all I could up to this point.
If you know what they mean, can't you fix them?
 

orb

O-F Administrator,
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
I don't understand what is this:
Code:
    int static MGROUP_ROTATE_ENGINE (0, ENGINEGrp, 1, _V(0,0,0), _V(-1,0,0), (float)(PI*0.50));
Is MGROUP_ROTATE_ENGINE a type, or a variable, or a function, or something defined by preprocessor directive?
 

MJR

C++ developer in the mix
Addon Developer
Tutorial Publisher
Donator
Joined
Mar 19, 2008
Messages
2,460
Reaction score
5
Points
0
Location
United States
Earlier it said that just with the static that it could not determine what it was which didn't make any sense to me. Something about couldn't tell whether it was an integer (int) or other. So I put int to fix it. I believe that MGROUP_ROTATE is a function. It isn't pre-defined either.
 

orb

O-F Administrator,
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
MGROUP_ROTATE_ENGINE != MGROUP_ROTATE, if you didn't do something like "#define MGROUP_ROTATE_ENGINE MGROUP_ROTATE". MGROUP_ROTATE is a subclass of MGROUP_TRANSFORM defined by Orbiter API. Did you subclass MGROUP_ROTATE with MGROUP_ROTATE_ENGINE, or something?

Are you creating yours, or editing someone's sources?
Have you seen how it's done in the Orbitersdk samples?
 

MJR

C++ developer in the mix
Addon Developer
Tutorial Publisher
Donator
Joined
Mar 19, 2008
Messages
2,460
Reaction score
5
Points
0
Location
United States
It was somewhat similar to the HST animation sequence. Besides that, I got it to work.
I originally had this...

Code:
void Spacecraft::DefineAnimations (void)
{
    static UINT ENGINEGrp[1] = {24};
    int static MGROUP_ROTATE_ENGINE (0, ENGINEGrp, 1, _V(0,0,0), _V(-1,0,0), (float)(PI*0.50));
    anim_eng = CreateAnimation (0.5);
    AddAnimationComponent (anim_eng, 0, 1, &ENGINEGrp);

}

Changed it to this...

Code:
void Spacecraft::DefineAnimations (void)
{
    static UINT EngineGrp[1] = {23};
    static MGROUP_ROTATE Engine (0, EngineGrp, 2, _V(0,0,2), _V(-1,0,0), (float)(PI*0.50));
    anim_eng = CreateAnimation (0.5);
    AddAnimationComponent (anim_eng, 0, 0.5, &Engine);
}


---------- Post added at 04:24 PM ---------- Previous post was at 03:48 PM ----------

BTW, is this the right code for looping it so it keeps spinning?

Code:
void Spacecraft::clbkPostStep (double simt, double simdt, double mjd)
{
    
    if (engine_status >= ENGINE_STOPPING) {
        double da = simdt * ENGINE_SPEED;
        if (engine_status == ENGINE_STOPPING) {
            if (eng_proc > 0.0) eng_proc = max (0.0, eng_proc-da);
            else                engine_status = ENGINE_IDLE;
        } else {
            if (eng_proc < 1.0) eng_proc = min (1.0, eng_proc+da);
            else                engine_status = ENGINE_ON;
        }
        SetAnimation (anim_eng, eng_proc);
    }

Well, apparently not, because in Orbiter it just moved once and stopped. What values would I change to do any indefinite loop until the command of SHIFT-E?
 
Last edited:
Top