From fbe29fd8be7dd6042bfac9ff42524ec3d4c84394 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 7 Apr 2020 18:41:16 +0900 Subject: [PATCH] Ensure the root part is correctly oriented This works when the root part's forward axis is at least 30 degrees away from the node axis (forward (+Z) is towards the VAB north wall, thus is many parts' ventral side). This means that when the bottom node is used, the ventral side aligns with the micro-pad's blue diamond and the starboard side aligns with the red diamond (hmm... that's a bit off since red is port and green is starboard...) --- Source/DisposablePad/DisposablePad.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Source/DisposablePad/DisposablePad.cs b/Source/DisposablePad/DisposablePad.cs index 4869b733..8ea3719d 100644 --- a/Source/DisposablePad/DisposablePad.cs +++ b/Source/DisposablePad/DisposablePad.cs @@ -242,12 +242,25 @@ public void SetShipTransform (Transform shipTransform, Part rootPart) var pos = Vector3.zero; if (n != null) { Vector3 nodeAxis = rootXform.TransformDirection(n.orientation); - rot = Quaternion.FromToRotation (nodeAxis, Vector3.up); + Vector3 forward = rootXform.forward; + float fwdDot = Vector3.Dot (forward, nodeAxis); + if (Mathf.Abs (fwdDot) < 0.866f) { + Debug.Log ($"[EL] nodeAxis: {nodeAxis}"); + Debug.Log ($"[EL] rotation: {rootXform.rotation} right:{rootXform.right} forward:{rootXform.forward} up:{rootXform.up}"); + rot = Quaternion.LookRotation (nodeAxis, forward); + rot = Quaternion.Inverse (rot); + Debug.Log ($"[EL] {rot}"); + rot = Quaternion.LookRotation (Vector3.up, -Vector3.forward) * rot; + Debug.Log ($"[EL] {Quaternion.LookRotation (Vector3.up, -Vector3.forward)}"); + } else { + rot = Quaternion.FromToRotation (nodeAxis, Vector3.up); + } pos = rootXform.TransformVector (n.position); } Debug.Log ($"[EL] pos: {pos} rot: {rot}"); shipTransform.position = rot * -pos; shipTransform.rotation = rot * shipTransform.rotation; + Debug.Log ($"[EL] position: {shipTransform.position} rotation: {shipTransform.rotation} right:{shipTransform.right} forward:{shipTransform.forward} up:{shipTransform.up}"); } public Transform PlaceShip (Transform shipTransform, Box vessel_bounds)