From 7a29651f6726574d1ddbb1c7fcf6830780cc3236 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 13 Sep 2020 15:41:09 +0900 Subject: [PATCH] Pre-rotate the anchor transform This is the launch clamp side of the fix for the EL-ReStock launch clamp compatibility issue. The issue was reported in the EL thread and started out as issues with getting the build cost but after fixing that, had issues with the clamps extending properly when built at a survey site. The bulk of the fix for that is (or will be) in EL, but this change is for handling rotated clamps: it points the tower in the correct (editor) direction prior to the tower being extended. --- Source/Restock/ModuleRestockLaunchClamp.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Source/Restock/ModuleRestockLaunchClamp.cs b/Source/Restock/ModuleRestockLaunchClamp.cs index cb07678b..81c1baf3 100644 --- a/Source/Restock/ModuleRestockLaunchClamp.cs +++ b/Source/Restock/ModuleRestockLaunchClamp.cs @@ -22,6 +22,7 @@ namespace Restock public LaunchClampGirderFactory girderFactory; private int _girderSegments; + private Quaternion towerRot; private Material _girderMaterial; private Matrix4x4[] _girderMatrices; @@ -63,12 +64,28 @@ namespace Restock girderFactory.Initialize(girderMesh, girderSegmentHeight, maxSegments); } } + + if (node.HasValue ("towerRot")) + { + string rot = node.GetValue ("towerRot"); + towerRot = KSPUtil.ParseQuaternion (rot); + } _girderSegments = 1; base.OnLoad(node); } + public void RotateTower () + { + // transforms found in OnLoad + float height = Vector3.Distance (towerAnchor.position, towerStretch.position); + //Debug.Log($"[ModuleRestockLaunchClamp] RotateTower: {height} {towerRot}"); + towerPivot.localRotation = towerRot; + towerAnchor.localRotation = towerRot; + towerAnchor.position = towerStretch.position - towerStretch.up * height; + } + public override void OnStart(StartState state) { base.OnStart(state); @@ -144,4 +161,4 @@ namespace Restock girderMeshFilter.mesh = girderFactory.makeGirder(girderSegments); } } -} \ No newline at end of file +}