Ejemplo n.º 1
0
        public static CVAngle Create(CMAngle model, Transform parent,
                                     CVLineSegment segment1, CVLineSegment segment2)
        {
            var name = string.Format("angle {0}: {1} <-> {2}", model.Id, segment1.Model.Id, segment2.Model.Id);

            return(new GameObject(name).AddComponent <CVAngle>().Init(model, parent, segment1, segment2));
        }
Ejemplo n.º 2
0
 public CBuildLineAction(CVShape owner, CVPoint point, CVLineSegment segment, Vector3 hitPos) : base(owner)
 {
     point1       = new CVPointWrap(owner, point);
     this.segment = new CVSegmentWrap(owner, segment);
     this.hitPos  = segment.Owner.CalcHitPosition(this.segment.Index, hitPos);
     divideAction = new CDivideLineAction(Owner, segment.Owner, this.segment.Index, this.hitPos);
 }
Ejemplo n.º 3
0
        private CVAngle Init(CMAngle model, Transform parent,
                             CVLineSegment segment1, CVLineSegment segment2)
        {
            CVPoint point = segment1.GetCommonPoint(segment2);
            // функция вычисления направлений линий, образующих угол
            Func <CVLineSegment, Vector3> getDir
                = segment => segment.RealDirection.normalized * (point == segment.FirstPoint ? 1 : -1);
            // создание обозначения угла
            const float radius = 0.2f;

            Vector3[] positions = null;
            if (model.IsRightAngle)
            {
                positions = CalcRightAngleContour(radius, getDir(segment1), getDir(segment2));
            }
            else
            {
                positions = CalcAngleContour(radius, getDir(segment1), getDir(segment2));
            }
            CreateLineRenderer(transform, positions);

            // привязка обозначения угла к месту угла
            transform.parent        = parent;
            transform.localPosition = point.RealPosition;
            transform.localRotation = Quaternion.identity;
            transform.localScale    = Vector3.one;

            Model = model;

            return(this);
        }
Ejemplo n.º 4
0
        private void CreateSegment(Vector3 startPos, Vector3 endPos, int index)
        {
            var segment = CVLineSegment.Create(this, SegmentsOwner, startPos, endPos);

            segment.MouseDown += Segment_MouseDown;
            segments.Insert(index, segment);
        }
Ejemplo n.º 5
0
 public CVPoint GetCommonPoint(CVLineSegment segment)
 {
     if (FirstPoint == segment.FirstPoint || FirstPoint == segment.LastPoint)
     {
         return(FirstPoint);
     }
     if (LastPoint == segment.FirstPoint || LastPoint == segment.LastPoint)
     {
         return(LastPoint);
     }
     return(null);
 }
Ejemplo n.º 6
0
        // отложенная обработка события выбора отрезка
        private IEnumerator LineView_Selected_Coroutine(CVLine view, CVLineSegment segment)
        {
            switch (CurState)
            {
            case State.SetAngle:
                if (activeSegments.Count != 0 && segment.GetCommonPoint(activeSegments.Top) == null)
                {
                    activeSegments.Clear();
                }
                activeSegments.ToXor(segment);
                break;

            case State.BuildLine:
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                if (curAction != null && curAction.IsDone)
                {
                    curAction.Undo();
                    yield return(null);
                }
                RaycastHit raycastHit = new RaycastHit();
                if (activePoints.Top != null && Physics.Raycast(ray, out raycastHit))
                {
                    CVLineSegment correctSegment = raycastHit.transform.gameObject.GetComponent <CVLineSegment>();
                    curAction = new CBuildLineAction(this, activePoints.Top, correctSegment, raycastHit.point);
                    curAction.Do();
                }
                break;

            case State.DivideLine:
                activeSegments.ToXor(segment);
                break;

            case State.Static:
                break;
            }
            yield return(null);
        }
Ejemplo n.º 7
0
 // обработчик события выбора отрезка
 private void LineView_Selected(CVLine view, CVLineSegment segment)
 {
     StartCoroutine(LineView_Selected_Coroutine(view, segment));
 }
Ejemplo n.º 8
0
 public CAngleSettingAction(CVShape owner, CVLineSegment segment1, CVLineSegment segment2, int?angle = null) : base(owner)
 {
     this.segment1 = new CVSegmentWrap(Owner, segment1);
     this.segment2 = new CVSegmentWrap(Owner, segment2);
     this.angle    = angle;
 }
Ejemplo n.º 9
0
 public CDivideLineAction(CVShape owner, CVLineSegment segment, Vector3 pointPosition)
     : this(owner, segment.Owner, segment.IndexInLine, pointPosition)
 {
 }
Ejemplo n.º 10
0
 public CDivideLineAction(CVShape owner, CVLineSegment segment, float ratio)
     : this(owner, segment.Owner, segment.IndexInLine, ratio)
 {
 }
Ejemplo n.º 11
0
 public CVSegmentWrap(CVShape owner, CVLineSegment segment)
     : this(owner, segment.Model.Id, segment.IndexInLine)
 {
 }
Ejemplo n.º 12
0
 public int SegmentIndex(CVLineSegment lineSegment)
 {
     return(segments.IndexOf(lineSegment));
 }