Skip to content

Commit

Permalink
Fix #122
Browse files Browse the repository at this point in the history
Mirror Z axis of the attach node orientation to stop "back' and "front"
nodes looking inside the part.
  • Loading branch information
ihsoft committed Apr 29, 2016
1 parent edf221a commit ebc6afc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions Plugins/Source/CHANGES.txt
@@ -1 +1,2 @@
Pre-release changes:
- [Fix] #122: For some parts attach point is wrongly detected.
8 changes: 6 additions & 2 deletions Plugins/Source/KISAddonPointer.cs
Expand Up @@ -681,8 +681,12 @@ public enum PointerState {

/// <summary>Sets pointer origin to the current attachment node</summary>
private static void UpdatePointerAttachNode() {
pointerNodeTransform.localPosition = GetCurrentAttachNode().position;
pointerNodeTransform.localRotation = KIS_Shared.GetNodeRotation(GetCurrentAttachNode());
var node = GetCurrentAttachNode();
pointerNodeTransform.localPosition = node.position;
// HACK(ihsoft): For some reason Z orientation axis is get mirrored in the parts. It results in
// a weird behavior when aligning parts in "back" or "front" node attach modes. It may be a
// KIS code bug but I gave up finding it.
pointerNodeTransform.localRotation = KIS_Shared.GetNodeRotation(node, mirrorZ: true);
}

/// <summary>Destroyes object(s) allocated to represent a pointer.</summary>
Expand Down
16 changes: 12 additions & 4 deletions Plugins/Source/KIS_Shared.cs
Expand Up @@ -495,8 +495,7 @@ public enum MessageAction {
Quaternion adjust) {
Vector3 refDir = hit.transform.TransformDirection(Vector3.up);
Quaternion rotation = Quaternion.LookRotation(hit.normal, refDir);
source.rotation = (rotation * adjust) * childNode.localRotation;
source.position = source.position - (childNode.position - hit.point);
MoveAlign(source, childNode, hit.point, rotation * adjust);
}

public static void MoveAlign(Transform source, Transform childNode, Transform target,
Expand Down Expand Up @@ -549,8 +548,17 @@ public enum MessageAction {
return null;
}

public static Quaternion GetNodeRotation(AttachNode attachNode) {
return Quaternion.LookRotation(attachNode.orientation);
/// <summary>Returns a rotation for the attach node.</summary>
/// <param name="attachNode">A node to get orientation from.</param>
/// <param name="mirrorZ">If <c>true</c> then Z axis in the node's orientation will be mirrored.
/// E.g. <c>(1, 1, 1)</c> will be translated into <c>(1, 1, -1)</c>.</param>
/// <returns>Rotation quaternion.</returns>
public static Quaternion GetNodeRotation(AttachNode attachNode, bool mirrorZ = false) {
var orientation = attachNode.orientation;
if (mirrorZ) {
orientation.z = -orientation.z;
}
return Quaternion.LookRotation(orientation);
}

public static void AssignAttachIcon(Part part, AttachNode node, Color iconColor,
Expand Down

0 comments on commit ebc6afc

Please sign in to comment.