Exemplo n.º 1
0
        public ObjectLink(Vector3 position, LinkableObject parent, LinkableObject child)
            : base(position)
        {
            Parent = parent;
            Child  = child;

            Parent.Links.Add(this);
            Child.Links.Add(this);
        }
Exemplo n.º 2
0
        protected override void OnMouseUp(MouseButtonEventArgs e)
        {
            base.OnMouseUp(e);

            _mouseDown = false;

            if (_line != null)
            {
                // you are dragging a line

                if (_line is AttackLine)
                {
                    if (_mouseOver != null)
                    {
                        // you are currently over a planet

                        if (_mouseOver != _attackFrom)
                        {
                            // you are on a different planet

                            LinkObjects(_attackFrom, _mouseOver);
                        }
                    }
                }
                else
                {
                    // do cutting here

                    foreach (ObjectLink link in scene.Objects.Where(o => o is ObjectLink))
                    {
                        var isIntersect
                            = LinesIntersect(_line.Position, _line.To,
                                             link.Parent.Position, link.Child.Position);

                        if (isIntersect)
                        {
                            Console.WriteLine("Intersect");
                        }
                    }
                }

                scene.Remove(_line);
                _line       = null;
                _attackFrom = null;
            }
        }
Exemplo n.º 3
0
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            base.OnMouseDown(e);

            _mouseDown = true;

            if (_mouseOver != null)
            {
                _line       = new AttackLine(_mouseOver.Position, _mouseOver.Position);
                _attackFrom = _mouseOver;
            }
            else
            {
                _line = new CutLine(_mouseWorldLocation, _mouseWorldLocation);
            }
            scene.Add(_line);
        }
Exemplo n.º 4
0
        private void LinkObjects(LinkableObject parent, LinkableObject child)
        {
            bool alreadyLinked = false;

            foreach (var existingLink in parent.Links)
            {
                if (existingLink.Child == child)
                {
                    alreadyLinked = true;
                    break;
                }
            }

            if (!alreadyLinked)
            {
                var newLink = new ObjectLink(
                    Vector3.Zero,
                    _attackFrom,
                    _mouseOver);

                scene.Add(newLink);
            }
        }