2 using UnityEditor.AnimatedValues;
5 namespace UnityEditor.Rendering.Experimental.LookDev
8 public class ComparisonGizmoState
10 public const float thickness = 0.0028f;
11 public const float thicknessSelected = 0.015f;
12 public const float circleRadius = 0.014f;
13 public const float circleRadiusSelected = 0.03f;
14 public const float blendFactorCircleRadius = 0.01f;
15 public const float blendFactorCircleRadiusSelected = 0.03f;
17 public Vector2 point1 { get; private set; }
18 public Vector2 point2 { get; private set; }
19 [field: SerializeField]
20 public Vector2 center { get; private set; } = Vector2.zero;
21 [field: SerializeField]
22 public float angle { get; private set; }
23 [field: SerializeField]
24 public float length { get; private set; } = 0.2f;
25 public Vector4 plane { get; private set; }
26 public Vector4 planeOrtho { get; private set; }
27 [field: SerializeField]
28 public float blendFactor { get; set; }
30 public float blendFactorMaxGizmoDistance
31 => length - circleRadius - blendFactorCircleRadius;
33 public float blendFactorMinGizmoDistance
34 => length - circleRadius - blendFactorCircleRadiusSelected;
37 => Update(center, length, angle);
40 private Vector4 Get2DPlane(Vector2 firstPoint, float angle)
42 Vector4 result = new Vector4();
43 angle = angle % (2.0f * (float)Math.PI);
44 Vector2 secondPoint = new Vector2(firstPoint.x + Mathf.Sin(angle), firstPoint.y + Mathf.Cos(angle));
45 Vector2 diff = secondPoint - firstPoint;
46 if (Mathf.Abs(diff.x) < 1e-5)
48 result.Set(-1.0f, 0.0f, firstPoint.x, 0.0f);
49 float sign = Mathf.Cos(angle) > 0.0f ? 1.0f : -1.0f;
54 float slope = diff.y / diff.x;
55 result.Set(-slope, 1.0f, -(firstPoint.y - slope * firstPoint.x), 0.0f);
61 float length = Mathf.Sqrt(result.x * result.x + result.y * result.y);
62 result = result / length;
66 public void Update(Vector2 point1, Vector2 point2)
70 center = (point1 + point2) * 0.5f;
71 length = (point2 - point1).magnitude * 0.5f;
73 Vector3 verticalPlane = Get2DPlane(center, 0.0f);
74 float side = Vector3.Dot(new Vector3(point1.x, point1.y, 1.0f), verticalPlane);
75 angle = (Mathf.Deg2Rad * Vector2.Angle(new Vector2(0.0f, 1.0f), (point1 - point2).normalized));
77 angle = 2.0f * Mathf.PI - angle;
79 plane = Get2DPlane(center, angle);
80 planeOrtho = Get2DPlane(center, angle + 0.5f * (float)Mathf.PI);
83 public void Update(Vector2 center, float length, float angle)
89 plane = Get2DPlane(center, angle);
90 planeOrtho = Get2DPlane(center, angle + 0.5f * (float)Mathf.PI);
92 Vector2 dir = new Vector2(planeOrtho.x, planeOrtho.y);
93 point1 = center + dir * length;
94 point2 = center - dir * length;