Jump to content

Symmetric Mirrored Control Surfaces


Recommended Posts

Any part willing to use ModuleControlSurface needs to be aware of the following features:

  • PartModule
    • OnEditorAttach event handler
    • symMethod field
    • symmetryCounterparts field
  • ModuleControlSurface
    • usesMirrorDeploy field
    • mirrorDeploy field
    • partDeployInvert field

Your part module must hook a EventHandler to the OnEditorAttach:

	part.OnEditorAttach += new Callback(UpdateOnEditorAttach);

So, everytime the user attaches something with your module on another part on the Editor, you will be notified.

On the event handler, you need to check the Symmetry Method - on this case, we need to check for the Mirror one. And then set some ModuleControlSurface flags, as follows:

  1. Check if the part has any Counter Parts on the Symmetry - no need to waste time when the part has no mirrored part! (technically, a bug but whatever - better safe than sorry).
    • To be really pick, one should check if the Count is exactly one, but if you get a situation where a mirrored part has more than one, the user have a lot of worse problems to cope wth. :)
  2. Get a pointer to the ModuleControlSurface instance of the part.
  3. Get a pointer to the mirror counterpart's ModuleControlSurface of this part.
  4. set usesMirrorDeploy to TRUE
  5. set mirrorDeploy differently for each part using some criteria (any one fits, the important part is that one gets TRUE and the other gets FALSE)
  6. For a reason beyond my grasp, on B9 Procedural Control Surfaces you need to set partDeployInvert to the negation of the mirrorDeploy. Stock Control Surfaces doesn't use that.

And that's it. :) 

Here is the code I used on my pull request to B9's Procedural Wings (released under the MIT, by the way):

public void Start(
{
	part.OnEditorAttach += SetupMirroredCntrlSrf;
}
	
private void SetupMirroredCntrlSrf()
{
	if (part.symMethod == SymmetryMethod.Mirror && part.symmetryCounterparts.Count > 0)
		if (this.part.Modules.Contains<ModuleControlSurface>())
		{ 
			ModuleControlSurface m = this.part.Modules.GetModule<ModuleControlSurface>();
			m.usesMirrorDeploy = true;
			{
			    Part other = part.symmetryCounterparts[0];
			    m.mirrorDeploy = this.part.transform.position.x > other.transform.position.x;
			    m.partDeployInvert = !m.mirrorDeploy;
			}
		}
}

And that's it! Any part willing to implement mirrored behaviours (as elevons and flaps) and uses ModuleControlSurfaceonly need to do this, and that's it!

Edited by Lisias
Eternal typos from the englishless mind.
Link to comment
Share on other sites

I found an issue with Atmospheric Autopilot. The first time you load your pre-existent (or downloaded) crafts, you loose the Control Surfaces configurations, as AA changes the name of that module to SyncModuleControSurface, and then the data under the ModuleControlSurface are lost. :( 

This used to work fine until 2014 more or less (see here), but obviously something changed in the mean time.

AA made a "hack" by resetting the mirror info by brute-force, but that way doesn't works with B9's control surfaces. So, currently, I'm trying to figure out a way to overcome that.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...