gotmachine / MandatoryRCS

MandatoryRCS plugin for Kerbal Space Program
The Unlicense
7 stars 6 forks source link

Background rotation #13

Closed SirMortimer closed 5 years ago

SirMortimer commented 5 years ago

Since MandatoryRCS preserves rotation in background and rotates a vessel when it comes off rails, this might be relevant for Kerbalism background sim:

For vessels in background, Kerablism looks at all the panels of a vessel, calculates the angle of that panel to the sun and produces EC accordingly. But it can't account for the rotation of the vessel done in background by other mods.

The code in Kerbalism that does that is this:

    // get panel normal/pivot direction in world space
    Transform tr = panel.part.FindModelComponent<Transform>(panel.pivotName);
    Vector3d dir = panel.isTracking ? tr.up : tr.forward;
    dir = (v.transform.rotation * p.rotation * dir).normalized;

    // calculate cosine factor
    // - fixed panel: clamped cosine
    // - tracking panel, tracking pivot enabled: around the pivot
    // - tracking panel, tracking pivot disabled: assume perfect alignment
    double cosine_factor =
        !panel.isTracking
      ? Math.Max(Vector3d.Dot(info.sun_dir, dir), 0.0)
      : Settings.TrackingPivot
      ? Math.Cos(1.57079632679 - Math.Acos(Vector3d.Dot(info.sun_dir, dir)))
      : 1.0;

(Done in Background.cs)

v.transform.rotation isn't being updated for unloaded vessels, for obvious reasons.

The cleanest solution would probably be an API method call that would return the current orientation of a vessel if it was to go off rails at that moment.

This relates to https://github.com/Kerbalism/Kerbalism/issues/382

SirMortimer commented 5 years ago

We now have a solution in Kerbalism: we assume a constant orientation relative to the sun on all unloaded vessels, no matter if there is any mod actually doing that or not. I'm closing this issue.