public bool Clip(Vertices clipVertices, Vector2 position)
        {
            Rot       rot = new Rot(0);
            Transform t   = new Transform(ref position, ref rot);

            //Transform shape
            Transform thistransform;

            Body.GetTransform(out thistransform);

            //Transform the shape
            Vertices transformedshape = new Vertices(clipVertices.Count);

            foreach (Vector2 v in clipVertices)
            {
                Vector2 newv = v;
                newv = MathUtils.Mul(ref t, ref newv);
                newv = MathUtils.MulT(ref thistransform, ref newv);
                transformedshape.Add(newv);
            }

            PolyClipError   error;
            List <Vertices> result = YuPengClipper.Difference(Vertices, transformedshape, out error);

            if (error != PolyClipError.None)
            {
                return(false);
            }

            //Need to check if the entire shape was cut,
            //so we can destroy/erase it
            if (result.Count == 0)
            {
                return(false);
            }

            //The shape was split up,
            //so create a new DestructableBody for each piece
            if (result.Count > 1)
            {
                //Create a new destructable body for each extra shape
                for (int i = 1; i < result.Count; i++)
                {
                    DestructableBody db = new DestructableBody(_world, result[i]);
                    db.Body.Position = Body.Position;
                }
            }

            //Set Shape
            Vertices newshape = result[0];

            SetShape(newshape);

            return(true);
        }
Пример #2
0
        public override void Keyboard(KeyboardManager keyboardManager)
        {
            // Add Circles
            if (keyboardManager.IsNewKeyPress(Keys.Q))
            {
                AddCircle(3, 8);
            }

            // Add Circles
            if (keyboardManager.IsNewKeyPress(Keys.W))
            {
                AddCircle(4, 16);
            }

            // Add Circles
            if (keyboardManager.IsNewKeyPress(Keys.E))
            {
                AddCircle(5, 32);
            }

            // Add Rectangle
            if (keyboardManager.IsNewKeyPress(Keys.A))
            {
                AddRectangle(4, 8);
            }

            // Add Rectangle
            if (keyboardManager.IsNewKeyPress(Keys.S))
            {
                AddRectangle(5, 2);
            }

            // Add Rectangle
            if (keyboardManager.IsNewKeyPress(Keys.D))
            {
                AddRectangle(2, 5);
            }

            // Perform a Union
            if (keyboardManager.IsNewKeyPress(Keys.Space))
            {
                if (_subject != null && _clip != null)
                {
                    DoBooleanOperation(YuPengClipper.Union(_subject, _clip, out _err));
                }
            }

            // Perform a Subtraction
            if (keyboardManager.IsNewKeyPress(Keys.Back))
            {
                if (_subject != null && _clip != null)
                {
                    DoBooleanOperation(YuPengClipper.Difference(_subject, _clip, out _err));
                }
            }

            // Perform a Intersection
            if (keyboardManager.IsNewKeyPress(Keys.LeftShift))
            {
                if (_subject != null && _clip != null)
                {
                    DoBooleanOperation(YuPengClipper.Intersect(_subject, _clip, out _err));
                }
            }

            // Select Subject
            if (keyboardManager.IsNewKeyPress(Keys.D1))
            {
                if (_selected != null)
                {
                    if (_clip == _selected)
                    {
                        _clip = null;
                    }

                    _subject = _selected;
                }
            }

            // Select Clip
            if (keyboardManager.IsNewKeyPress(Keys.D2))
            {
                if (_selected != null)
                {
                    if (_subject == _selected)
                    {
                        _subject = null;
                    }

                    _clip = _selected;
                }
            }
        }
Пример #3
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            // Add Circles
            if (e.KeyCode == Keys.Q)
            {
                AddCircle(3, 8);
            }

            // Add Circles
            if (e.KeyCode == Keys.W)
            {
                AddCircle(4, 16);
            }

            // Add Circles
            if (e.KeyCode == Keys.E)
            {
                AddCircle(5, 32);
            }

            // Add Rectangle
            if (e.KeyCode == Keys.A)
            {
                AddRectangle(4, 8);
            }

            // Add Rectangle
            if (e.KeyCode == Keys.S)
            {
                AddRectangle(5, 2);
            }

            // Add Rectangle
            if (e.KeyCode == Keys.D)
            {
                AddRectangle(2, 5);
            }

            // Perform a Union
            if (e.KeyCode == Keys.Space)
            {
                if (_subject != null && _clip != null)
                {
                    PolyClipError _err;
                    DoBooleanOperation(YuPengClipper.Union(_subject, _clip, out _err));
                }
            }

            // Perform a Subtraction
            if (e.KeyCode == Keys.Back)
            {
                if (_subject != null && _clip != null)
                {
                    PolyClipError _err;
                    DoBooleanOperation(YuPengClipper.Difference(_subject, _clip, out _err));
                }
            }

            // Perform a Intersection
            if (e.KeyCode == Keys.LeftShift)
            {
                if (_subject != null && _clip != null)
                {
                    PolyClipError _err;
                    DoBooleanOperation(YuPengClipper.Intersect(_subject, _clip, out _err));
                }
            }

            // Select Subject
            if (e.KeyCode == Keys.D1)
            {
                if (_selected != null)
                {
                    if (_clip == _selected)
                    {
                        _clip = null;
                    }

                    _subject = _selected;
                }
            }

            // Select Clip
            if (e.KeyCode == Keys.D2)
            {
                if (_selected != null)
                {
                    if (_subject == _selected)
                    {
                        _subject = null;
                    }

                    _clip = _selected;
                }
            }
        }