public static FindNearestCardinalAxis ( Vector3 testVector ) : Vector3 | ||
testVector | Vector3 |
/// A |
return | Vector3 |
/* * Match this part to another, optionally forcing cardinal axis alignment * */ public void MatchTo(BodyPart other, bool isCardinalAlignment) { // match the parts to each other oppositePart = other; other.oppositePart = this; // error if the bones are on top of each other if ((bone.position - other.bone.position).sqrMagnitude == 0f) { Debug.LogWarning(string.Format("Could not compute corresponding axes for BodyParts {0} and {1} because they are coincident.", name, other.name)); } // compute match axes for each part Vector3 reflectionDirection = (bone.position - other.bone.position).normalized; other.oppositeForward = other.bone.InverseTransformDirection(VectorHelpers.MirrorPointAcrossPlane(bone.forward, reflectionDirection)).normalized; other.oppositeRight = other.bone.InverseTransformDirection(VectorHelpers.MirrorPointAcrossPlane(bone.right, reflectionDirection)).normalized; other.oppositeUp = other.bone.InverseTransformDirection(VectorHelpers.MirrorPointAcrossPlane(bone.up, reflectionDirection)).normalized; oppositeForward = bone.InverseTransformDirection(VectorHelpers.MirrorPointAcrossPlane(other.bone.forward, reflectionDirection)).normalized; oppositeRight = bone.InverseTransformDirection(VectorHelpers.MirrorPointAcrossPlane(other.bone.right, reflectionDirection)).normalized; oppositeUp = bone.InverseTransformDirection(VectorHelpers.MirrorPointAcrossPlane(other.bone.up, reflectionDirection)).normalized; // if isCardinalAlignment, then map the nearest cardinal axis as opposed to the raw axis if (isCardinalAlignment) { other.oppositeForward = VectorHelpers.FindNearestCardinalAxis(other.oppositeForward); other.oppositeRight = VectorHelpers.FindNearestCardinalAxis(other.oppositeRight); other.oppositeUp = VectorHelpers.FindNearestCardinalAxis(other.oppositeUp); oppositeForward = VectorHelpers.FindNearestCardinalAxis(oppositeForward); oppositeRight = VectorHelpers.FindNearestCardinalAxis(oppositeRight); oppositeUp = VectorHelpers.FindNearestCardinalAxis(oppositeUp); } }