markusa380/PersistentRotation

Help me with Kerbalism, please

Closed this issue · 4 comments

I just found out that Kerbalism doesn't seem to notice / account for vessel rotations done in the background by PersistentRotation.

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 doesn't seem to notice/account for the rotation of the vessel done in background by PersistentRotation. This is going to be an issue for a lot of RealismOverhaul players.

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

To my untrained eye, it looks like v.transform.rotation isn't correct, and it isn't obvious for me from looking at your code what exactly is happening with unloaded rotating vessels in FixedUupdate. Is there anything I can do about that?

I am currently not actively developing PersistentRotation, but I will adapt it to the latest version soon, then I will be able to figure this out. Stay tuned for more.

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

Looking at my old code I would agree with you.

The orientation is not updated if the vessel is unloaded - which makes a lot of sense.

So we need an API method that retrieves the current rotation, which I will try to implement.

For spinning vessels I would use a static modifier. I would suggest using the following:

average of max(cos(x),0) from 0 to 2 PI = 0.31831...

So the average amount of light that shines on spinning solar panels where 1 is the maximum amount at a 90° angle.

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