Skip to content

Commit

Permalink
Ensure the root part is correctly oriented
Browse files Browse the repository at this point in the history
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...)
  • Loading branch information
taniwha committed Apr 7, 2020
1 parent 1ae35c4 commit fbe29fd
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Source/DisposablePad/DisposablePad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fbe29fd

Please sign in to comment.