public SmartTriangle(TriangleData triangle, TrianglesPool pool, float minimumArea) { IsSet = false; _triangle = triangle; _currentVertices = _targetVertices = new TriangleVertices(_triangle); _pool = pool; _hasChildren = _targetVertices.GetArea() > minimumArea; if (_hasChildren) { GenerateChildren(minimumArea); } }
private void UpdateSelf() { if (_meshTriangle == null) { _meshTriangle = _pool.GetTriangle(); _meshTriangle.UseTriangle(_triangle); } _currentVertices.Lerp(_targetVertices, Time.deltaTime * SPEED); IsSet = _currentVertices.TheSame(_targetVertices, DELTA); if (IsSet) { _currentVertices = _targetVertices; } _meshTriangle.UpdateVertices(_currentVertices); }
public static bool AllAreAtTheVector(this TriangleVertices a, Vector3 b, float delta) { var sqrDelta = delta * delta; return((a.V0 - b).sqrMagnitude < sqrDelta && (a.V1 - b).sqrMagnitude < sqrDelta && (a.V2 - b).sqrMagnitude < sqrDelta); }
public static bool TheSame(this TriangleVertices a, TriangleVertices b, float delta) { var sqrDelta = delta * delta; return((a.V0 - b.V0).sqrMagnitude < sqrDelta && (a.V1 - b.V1).sqrMagnitude < sqrDelta && (a.V2 - b.V2).sqrMagnitude < sqrDelta); }
public void UpdateVertices(TriangleVertices vertices) { V0 = vertices.V0; V1 = vertices.V1; V2 = vertices.V2; }
public void Lerp(TriangleVertices to, float fraction) { V0 = Vector3.Lerp(V0, to.V0, fraction); V1 = Vector3.Lerp(V1, to.V1, fraction); V2 = Vector3.Lerp(V2, to.V2, fraction); }