private void CalculateAxisAndPivot(List <VA_Triangle> tris, ref int axis, ref float pivot) { var min = tris[0].Min; var max = tris[0].Max; var mid = Vector3.zero; foreach (var tri in tris) { min = Vector3.Min(min, tri.Min); max = Vector3.Max(max, tri.Max); mid += tri.A + tri.B + tri.C; } var size = max - min; if (size.x > size.y && size.x > size.z) { axis = 0; pivot = VA_Helper.Divide(mid.x, tris.Count * 3.0f); } else if (size.y > size.x && size.y > size.z) { axis = 1; pivot = VA_Helper.Divide(mid.y, tris.Count * 3.0f); } else { axis = 2; pivot = VA_Helper.Divide(mid.z, tris.Count * 3.0f); } }
protected override void LateUpdate() { base.LateUpdate(); // Make sure the listener exists var listenerPosition = default(Vector3); if (VA_Helper.GetListenerPosition(ref listenerPosition) == true) { UpdateFields(); RebuildMatrix(); var worldPoint = listenerPosition; var localPoint = cachedMatrix.inverse.MultiplyPoint(worldPoint); var scale = transform.lossyScale; var squash = VA_Helper.Divide(scale.y, Mathf.Max(scale.x, scale.z)); var halfHeight = Mathf.Max(0.0f, Height * squash * 0.5f - Radius); if (IsHollow == true) { localPoint = SnapLocalPoint(localPoint, halfHeight); worldPoint = cachedMatrix.MultiplyPoint(localPoint); SetOuterPoint(worldPoint); } else { if (LocalPointInCapsule(localPoint, halfHeight) == true) { SetInnerPoint(worldPoint, true); localPoint = SnapLocalPoint(localPoint, halfHeight); worldPoint = cachedMatrix.MultiplyPoint(localPoint); SetOuterPoint(worldPoint); } else { localPoint = SnapLocalPoint(localPoint, halfHeight); worldPoint = cachedMatrix.MultiplyPoint(localPoint); SetInnerOuterPoint(worldPoint, false); } } } }
protected virtual void OnDrawGizmosSelected() { if (VA_Helper.Enabled(this) == true) { UpdateFields(); RebuildMatrix(); var scale = transform.lossyScale; var squash = VA_Helper.Divide(scale.y, Mathf.Max(scale.x, scale.z)); var halfHeight = Mathf.Max(0.0f, Height * squash * 0.5f - Radius); var point1 = Vector3.up * halfHeight; var point2 = Vector3.up * -halfHeight; Gizmos.color = Color.red; Gizmos.matrix = cachedMatrix; Gizmos.DrawWireSphere(point1, Radius); Gizmos.DrawWireSphere(point2, Radius); Gizmos.DrawLine(point1 + Vector3.right * Radius, point2 + Vector3.right * Radius); Gizmos.DrawLine(point1 - Vector3.right * Radius, point2 - Vector3.right * Radius); Gizmos.DrawLine(point1 + Vector3.forward * Radius, point2 + Vector3.forward * Radius); Gizmos.DrawLine(point1 - Vector3.forward * Radius, point2 - Vector3.forward * Radius); } }