C++ Question Best way to learn C++ just for add-on developing

Kind of a backward clam.
 
Kind of a backward clam.

So just two meshgroups doing a rotation around the hinge axis?

Do you know how to set up an animation in an Orbiter module? If not I can PM you the basic idea along with how to trigger the animation on command. Let me know. :thumbup:
 
I have a .dll converted by the SC3converter. I can open the Goose.cpp and Goose.h files in the compiler. I can make sense of a some things, but others seem very strange. How would I make it so, when I press the retro thust keypad "-", it activates the reverse thruster animation, and closes it when released ?

Orbiter will call clbkConsumeBufferedKey on keyboard events.
 
Orbiter will call clbkConsumeBufferedKey on keyboard events.

Yeah, but I think he wants to set it up so that it opens and closes depending on the throttle level.

Roughly speaking, there are two ways to do this:

The animation can depend on the throttle level, which is a little rougher than I like.

or

The retro engines can be controlled based on the animation state, something like setting their thrust to 0 if the doors are not open, (seems like good engineering practice to me :lol:) and setting it to the right value once the animation is in its open state. The only hitch with this solution is the reaction of the Orbiter API to checking the numpad minus key, but I'm pretty sure that should be fine. The only thing that might mess with it would be the state of the throttle: if the user keeps mashing control-minus while the animation is happening, the throttle will be open to full retro once the engines thrust values are set back to normal; a rather nasty surprise if you only wanted a little MCC burn, but thats how it goes.
 
I's actually an air breather carrier jet. Would it be better o reverse the mains, instead of using retros, which is the hack now?
 
I's actually an air breather carrier jet. Would it be better o reverse the mains, instead of using retros, which is the hack now?

Can I see a picture of what you're working on/thinking?
 

So...

Its like you're taking the exhaust & deflecting it forwards? Thats, um rather unorthodox, but certainly interesting. Are the engines airbreathing, or straight-up rockets?

If you want to do this as an experimental DLLed vessel, you can probably do the retros & mains as separate engines, but link them to the same propellant handles, at least for each wing anyways. The exhausts shouldn't be too difficult to place...

Anyways, send me a PM in the morning & I'll get you started with a rough outline of how it can be done. Not out of this world tricky, but animations are often tough for beginners with Orbiter coding, so the help will probably be good.

:hailprobe:
 
They are airbreathing (supposed to be anyway). Thanks for the help.
 
I have a .dll converted by the SC3converter. I can open the Goose.cpp and Goose.h files in the compiler. I can make sense of a some things, but others seem very strange. How would I make it so, when I press the retro thust keypad "-", it activates the reverse thruster animation, and closes it when released ?

I would rather link this to another key (toggle thruster reversers) and then implement the action like that:

First of all, you implement the keyhandler in clbkConsumeBufferedKey. My personal preference is to only analyse what Orbiter tells you there and then implement the actual action for that key in a new function ("void toggleReserveThrust()"). This way you can find the right place in your source code much faster in Visual Studio.

For handling the animation, I would use the AnimState class that Orbiter already provides. So, you need to add an attribute to your vessel like

Code:
AnimState thrustReserver;

Like every attribute, you should initialize it in the constructor of the vessel. The constructor is a function with the same name as the vessel class name and has the special duty to help creating your vessel. This initialization is a simple statement in the constructor body:

Code:
thrustReverser.Set(AnimState::CLOSED, 0.0);

Now, if you want to toggle the animation in your action function (toggleThrustReverser), you need to toggle the action state of this thrustReverser attribute:

Code:
if (thrustReverser.Closed() || thrustReverser.Closing())
                thrustReverser.action = AnimState::OPENING;
            else 
                thrustReverser.action = AnimState::CLOSING;

Now, it would be fun if this would be all about it, right? Still, there is one task needed: Giving the animation time to move and moving the animation visibly. This is done either in clbkPreStep and clbkPostStep. I personally prefer clbkPostStep for the animations, but that is just for keeping clbkPreStep smaller. There, you have to add a line to give the animation some time:

Code:
if (thrustReverser.Moving()) {
            thrustReverser.Move(0.1 * fDeltaT);
            SetAnimation(animThrustReverser, thrustReverser.pos);
        }

animThrustReverser is the animation handle of the thrust reverser Animation. I am not knowing how the SC3 converter defines it.

Now you have the animation in your spacecraft starting with the keypress... now the hard work: How to implement a thrust reverser in Orbiter?

In deep dark theory, a thrust reverser like that splits the exhaust stream and directs some or all of it forward. The thrust of the thrust reverser depends on the thrust level of the thruster that powers it. So, you define one new thruster for each reverse of the engine, but give it zero thrust, and connect it to the same propellant resource as the main engines, even add it to the same thruster group (main) as the main engine (so a throttle controller has proper effect on it).

Lets say, you want to blend the thrust from full forward to full reverse. Then you have a function:

effectiveMaximumThrustMain = (1-thrustReverser.pos) * MaximumThrustMain
effectiveMaximumThrustReverse = thrustReverser.pos * MaximumThrustReverse

That is something you can also tell Orbiter via "SetThrusterMax0()". And you can still implement something like a airbreathing engine simulation in front of it, calculating what maximumThrustMain, etc actually is. But thats something much more advanced than that.
 
Last edited:
What I would like, would be just to change the direction of the thrust. When landing the thrust would be quite low anyway, which would be good when activating the reverse mechanism, an inhibiter would also be good. Then apply full thrust to stop.
 
Last edited:
What I would like, would be just to change the direction of the thrust. When landing the thrust would be quite low anyway, which would be good when activating the reverse mechanism, an inhibiter would also be good. Then apply full thrust to stop.

What do you mean by inhibiter?
 
Something that wouldn't allow the thruster to operate, unless the thrust was under a certain percent.
 
Back
Top