Example #1
0
        private void HandKeyboardInput(InputState input)
        {
            if (input.OneOfKeysPressed(Keys.Q, Keys.W, Keys.E, Keys.A, Keys.S, Keys.D))
                if (_leftGeom == null || _rightGeom == null)
                {
                    // Add Circles
                    if (input.IsNewKeyPress(Keys.Q))
                    {
                        AddCircle(50, 8);
                    }

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

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

                    // Add Rectangle
                    if (input.IsNewKeyPress(Keys.A))
                    {
                        AddRectangle(100, 100);
                    }

                    // Add Rectangle
                    if (input.IsNewKeyPress(Keys.S))
                    {
                        AddRectangle(100, 50);
                    }

                    // Add Rectangle
                    if (input.IsNewKeyPress(Keys.D))
                    {
                        AddRectangle(50, 100);
                    }
                }
                else
                {
                    WriteMessage("Only 2 polygons allowed at a time.");
                }

            // Perform a Union
            if (input.IsNewKeyPress(Keys.Space))
            {
                if (_leftGeom != null && _rightGeom != null)
                {
                    DoUnion();
                }
            }

            // Perform a Subtraction
            if (input.IsNewKeyPress(Keys.Back))
            {
                if (_leftGeom != null && _rightGeom != null)
                {
                    DoSubtract();
                }
            }

            // Simplify
            if (input.IsNewKeyPress(Keys.Tab))
            {
                if (_leftGeom != null && _rightGeom == null)
                {
                    Vertices simple = new Vertices(_leftGeom.WorldVertices);
                    simple = Vertices.Simplify(simple);

                    SetProduct(simple);
                }
            }

            // Add to Simulation
            if (input.IsNewKeyPress(Keys.Enter))
            {
                if (_leftGeom != null)
                {
                    Body body = BodyFactory.Instance.CreatePolygonBody(_leftGeom.LocalVertices, 1.0f);
                    body.Position = _leftGeom.Position;

                    Geom geom = GeomFactory.Instance.CreatePolygonGeom(body, _leftGeom.LocalVertices, 0);

                    PhysicsSimulator.Add(body);
                    PhysicsSimulator.Add(geom);

                    _simulatedPolyBrushes.Add(new PolygonBrush(_leftGeom.LocalVertices, Color.Red, Color.DarkRed, 1.5f, 0.2f));
                    _simulatedPolyBrushes[_simulatedPolyBrushes.Count - 1].Load(ScreenManager.GraphicsDevice);
                    _simulatedPolyBodies.Add(body);

                }
            }
        }