예제 #1
0
        // отложенная обработка нажатия по точке
        private IEnumerator PointView_MouseDown_Coroutine(CVPoint point)
        {
            switch (CurState)
            {
            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 (Physics.Raycast(ray, out raycastHit))
                {
                    CVPoint correctPoint = raycastHit.transform.gameObject.GetComponent <CVPoint>();
                    if (correctPoint != null)
                    {
                        activePoints.ToXor(correctPoint);
                        if (activePoints.Count == activePoints.MaxCount)
                        {
                            curAction = new CBuildLineAction(this, activePoints.Bottom, correctPoint);
                            curAction.Do();
                            activePoints.Remove(correctPoint);
                        }
                    }
                }

                break;
            }

            yield return(null);
        }
예제 #2
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);
        }
예제 #3
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);
 }
예제 #4
0
        // обработчик события создания точки модели
        private void Model_PointCreated(CMShape shape, CMPoint point)
        {
            // создание вида для очередной точки
            const string letters   = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789";
            string       pointName = letters[pointViewDict.Count].ToString();
            CVPoint      pointView = CVPoint.Create(pointName, point, pointsObj, nextPointsPos.Dequeue());

            pointView.MouseDown += PointView_MouseDown;
            pointViewDict.Add(point.Id, pointView);
        }
예제 #5
0
        public void InsertPoint(CVPoint point, int segmentIndex)
        {
            Vector3 startPos = points[segmentIndex].Position;
            Vector3 endPos   = points[segmentIndex + 1].Position;

            Model.Insert(segmentIndex + 1, point.Model);
            points.Insert(segmentIndex + 1, point);

            segments[segmentIndex].SetPositions(startPos, point.Position); // modify segment like part 1
            CreateSegment(point.Position, endPos, segmentIndex + 1);       // create segment like part 2
        }
예제 #6
0
 public void AddPoint(CVPoint point)
 {
     if (point.Model.Id != Model.PointAt(points.Count).Id)
     {
         throw new Exception("line model doesn't contain this point (line id: "
                             + Model.Id + ", point id: " + point.Model.Id);
     }
     points.Add(point);
     if (points.Count > 1)
     {
         CreateSegment(points[points.Count - 2].Position, point.Position);
     }
 }
예제 #7
0
        public void RemovePoint(CVPoint point)
        {
            int pointInd = points.IndexOf(point);

            if (pointInd < 0)
            {
                throw new Exception("CLineView hasn't CPointView (line model id: "
                                    + Model.Id + ", point model id" + point.Model.Id + ")");
            }

            Model.Detach(point.Model);
            points.RemoveAt(pointInd); // индексы и количество сдвинулись на один!
            if (points.Count == 0)
            {
                return;
            }

            RemoveSegment(pointInd - (pointInd == points.Count ? 1 : 0)); // если точка последняя, удалить отрезок перед ней
            if (pointInd > 0 && points.Count > 1)
            {
                segments[pointInd - 1].SetPositions(points[pointInd - 1].Position, points[pointInd].Position);
            }
        }
예제 #8
0
 public CBuildLineAction(CVShape owner, CVPoint point1, CVPoint point2) : base(owner)
 {
     this.point1 = new CVPointWrap(owner, point1);
     this.point2 = new CVPointWrap(owner, point2);
 }
예제 #9
0
 public CVPointWrap(CVShape owner, CVPoint point) : this(owner, point.Model.Id)
 {
 }
예제 #10
0
 public void InsertPoint(CVPoint point, int segmentIndex, float ratio)
 {
     point.Position = Vector3.Lerp(points[segmentIndex].Position, points[segmentIndex + 1].Position, ratio);
     InsertPoint(point, segmentIndex);
 }