示例#1
0
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            base.Update(settings, gameTime);

            PolygonShape shape = new PolygonShape(new Vertices(_points), 0f);

            DrawString("Press g to generate a new random convex hull");

            DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);
            DebugView.DrawPolygon(shape.Vertices.ToArray(), shape.Vertices.Count, new Color(0.9f, 0.9f, 0.9f));

            for (int i = 0; i < _count; ++i)
            {
                DebugView.DrawPoint(_points[i], 0.1f, new Color(0.9f, 0.5f, 0.5f));
                Vector2 position = GameInstance.ConvertWorldToScreen(_points[i]);
                DebugView.DrawString((int)position.X, (int)position.Y, i.ToString());
            }

            DebugView.EndCustomDraw();

            if (_auto)
            {
                Generate();
            }
        }
示例#2
0
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            base.Update(settings, gameTime);

            DebugView.DrawString(50, TextLine, "Press: left mouse button to remove at mouse position.");
            TextLine += 15;
            DebugView.DrawString(50, TextLine, "Press: (A) to decrease the removal radius, (S) to increase it.");
            TextLine += 15;
            // Fighting against float decimals
            float radiusnumber = (float)((int)(Radius * 10)) / 10;

            DebugView.DrawString(50, TextLine, "Radius: " + radiusnumber);

            Color color = new Color(0.4f, 0.7f, 0.8f);

            //Transform shape to mouseposition and then draw
            Vertices tempshape = new Vertices(_clipCircle);

            tempshape.Translate(ref _mousePos);
            DebugView.BeginCustomDraw();
            var ts = tempshape.ToList().Cast <CCVector2>();

            DebugView.DrawPolygon(ts.ToArray(), _clipCircle.Count, color);
            DebugView.EndCustomDraw();
        }
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            Manifold manifold = new Manifold();

            CollidePolygon.CollidePolygons(ref manifold, _polygonA, ref _transformA, _polygonB, ref _transformB);
            WorldManifold.Initialize(ref manifold, ref _transformA, _polygonA.Radius, ref _transformB, _polygonB.Radius, out _, out FixedArray2 <Vector2> points, out _);

            DrawString("Point count = " + manifold.PointCount);

            DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);
            {
                Color     color = new Color(0.9f, 0.9f, 0.9f);
                Vector2[] v     = new Vector2[Settings.MaxPolygonVertices];
                for (int i = 0; i < _polygonA.Vertices.Count; ++i)
                {
                    v[i] = MathUtils.Mul(ref _transformA, _polygonA.Vertices[i]);
                }
                DebugView.DrawPolygon(v, _polygonA.Vertices.Count, color);

                for (int i = 0; i < _polygonB.Vertices.Count; ++i)
                {
                    v[i] = MathUtils.Mul(ref _transformB, _polygonB.Vertices[i]);
                }
                DebugView.DrawPolygon(v, _polygonB.Vertices.Count, color);
            }

            for (int i = 0; i < manifold.PointCount; ++i)
            {
                DebugView.DrawPoint(points[i], 0.1f, new Color(0.9f, 0.3f, 0.3f));
                DrawString(points[i].ToString());
            }
            DebugView.EndCustomDraw();
        }
        public override void Draw(GameTime gameTime)
        {
            DebugView.BeginCustomDraw(Camera.Projection, Camera.View);
            foreach (Polygon p in _farseerPoly.Values)
            {
                DebugView.DrawPolygon(p.Vertices.ToArray(), p.Vertices.Count, Color.Black, p.Closed);
            }
            DebugView.EndCustomDraw();

            base.Draw(gameTime);
        }
示例#5
0
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            foreach (Vertices vertex in _polygons)
            {
                if (vertex != null)
                {
                    Vector2[] array = vertex.ToArray();
                    Color     col   = Color.SteelBlue;
                    if (!vertex.IsCounterClockWise())
                    {
                        col = Color.Aquamarine;
                    }
                    if (vertex == _selected)
                    {
                        col = Color.LightBlue;
                    }
                    if (vertex == _subject)
                    {
                        col = Color.Green;
                        if (vertex == _selected)
                        {
                            col = Color.LightGreen;
                        }
                    }

                    if (vertex == _clip)
                    {
                        col = Color.DarkRed;
                        if (vertex == _selected)
                        {
                            col = Color.IndianRed;
                        }
                    }

                    DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);
                    DebugView.DrawPolygon(array, vertex.Count, col);
                    for (int j = 0; j < vertex.Count; ++j)
                    {
                        DebugView.DrawPoint(vertex[j], .2f, Color.Red);
                    }
                    DebugView.EndCustomDraw();
                }
            }

            DrawString("A,S,D = Create Rectangle");
            DrawString("Q,W,E = Create Circle");
            DrawString("Click to Drag polygons");
            DrawString("1 = Select Subject while dragging [green]");
            DrawString("2 = Select Clip while dragging [red]");
            DrawString("Space = Union");
            DrawString("Backspace = Subtract");
            DrawString("Shift = Intersect");
            DrawString("Holes are colored light blue");
        }
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            base.Update(settings, gameTime);

            DistanceInput input = new DistanceInput();

            input.ProxyA     = new DistanceProxy(_polygonA, 0);
            input.ProxyB     = new DistanceProxy(_polygonB, 0);
            input.TransformA = _transformA;
            input.TransformB = _transformB;
            input.UseRadii   = true;
            SimplexCache cache = new SimplexCache();

            cache.Count = 0;
            DistanceOutput output;

            DistanceGJK.ComputeDistance(ref input, out output, out cache);

            DrawString($"distance = {output.Distance}");

            DrawString($"iterations = {output.Iterations}");

            DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);

            {
                Color     color = new Color(0.9f, 0.9f, 0.9f);
                Vector2[] v     = new Vector2[Settings.MaxPolygonVertices];
                for (int i = 0; i < _polygonA.Vertices.Count; ++i)
                {
                    v[i] = MathUtils.Mul(ref _transformA, _polygonA.Vertices[i]);
                }
                DebugView.DrawPolygon(v, _polygonA.Vertices.Count, color);

                for (int i = 0; i < _polygonB.Vertices.Count; ++i)
                {
                    v[i] = MathUtils.Mul(ref _transformB, _polygonB.Vertices[i]);
                }
                DebugView.DrawPolygon(v, _polygonB.Vertices.Count, color);
            }

            Vector2 x1 = output.PointA;
            Vector2 x2 = output.PointB;

            Color c1 = new Color(1.0f, 0.0f, 0.0f);

            DebugView.DrawPoint(x1, 4.0f, c1);

            Color c2 = new Color(1.0f, 1.0f, 0.0f);

            DebugView.DrawPoint(x2, 4.0f, c2);

            DebugView.EndCustomDraw();
        }
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            //If the message times out, remove it from the list.
            for (int i = _messages.Count - 1; i >= 0; i--)
            {
                _messages[i].ElapsedTime += settings.Hz;
                if (_messages[i].ElapsedTime > 5)
                {
                    _messages.Remove(_messages[i]);
                }
            }

            if (_left != null)
            {
                Vector2[] array = _left.ToArray();
                DebugView.DrawPolygon(ref array, _left.Count, Color.Red);
            }

            if (_right != null)
            {
                Vector2[] array = _right.ToArray();
                DebugView.DrawPolygon(ref array, _right.Count, Color.Red);
            }

            DebugView.DrawString(50, TextLine, "A,S,D = Create Rectangle");
            TextLine += 15;

            DebugView.DrawString(50, TextLine, "Q,W,E = Create Circle");
            TextLine += 15;

            DebugView.DrawString(50, TextLine, "Click to Drag polygons");
            TextLine += 15;

            DebugView.DrawString(50, TextLine, "Space = Union");
            TextLine += 15;

            DebugView.DrawString(50, TextLine, "Backspace = Subtract");
            TextLine += 15;

            DebugView.DrawString(50, TextLine, "Space = Union");
            TextLine += 15;

            DebugView.DrawString(50, TextLine, "Enter = Add to Simulation");
            TextLine += 15;

            for (int i = _messages.Count - 1; i >= 0; i--)
            {
                DebugView.DrawString(50, TextLine, _messages[i].Text);
                TextLine += 15;
            }

            base.Update(settings, gameTime);
        }
        private void DrawVertices(Vertices vertices)
        {
            if (vertices.Count >= 1)
            {
                DebugView.DrawPolygon(vertices.ToArray(), vertices.Count, Color.Red);

                foreach (Vector2 vector2 in vertices)
                {
                    DebugView.DrawPoint(vector2, 0.1f, Color.Yellow);
                }
            }
        }
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            base.Update(settings, gameTime);

            DistanceInput input = new DistanceInput();

            input.ProxyA.Set(_polygonA, 0);
            input.ProxyB.Set(_polygonB, 0);
            input.TransformA = _transformA;
            input.TransformB = _transformB;
            input.UseRadii   = true;
            SimplexCache cache;

            cache.Count = 0;
            DistanceOutput output;

            Distance.ComputeDistance(out output, out cache, input);

            DebugView.DrawString(50, TextLine, "Distance = {0:n7}", output.Distance);
            TextLine += 15;

            DebugView.DrawString(50, TextLine, "Iterations = {0:n0}", output.Iterations);
            TextLine += 15;

            DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);
            {
                Color     color = new Color(0.9f, 0.9f, 0.9f);
                Vector2[] v     = new Vector2[Settings.MaxPolygonVertices];
                for (int i = 0; i < _polygonA.Vertices.Count; ++i)
                {
                    v[i] = MathUtils.Mul(ref _transformA, _polygonA.Vertices[i]);
                }
                DebugView.DrawPolygon(v, _polygonA.Vertices.Count, color);

                for (int i = 0; i < _polygonB.Vertices.Count; ++i)
                {
                    v[i] = MathUtils.Mul(ref _transformB, _polygonB.Vertices[i]);
                }
                DebugView.DrawPolygon(v, _polygonB.Vertices.Count, color);
            }

            Vector2 x1 = output.PointA;
            Vector2 x2 = output.PointB;


            DebugView.DrawPoint(x1, 0.5f, new Color(1.0f, 0.0f, 0.0f));
            DebugView.DrawPoint(x2, 0.5f, new Color(1.0f, 0.0f, 0.0f));

            DebugView.DrawSegment(x1, x2, new Color(1.0f, 1.0f, 0.0f));
            DebugView.EndCustomDraw();
        }
示例#10
0
        public void Draw(SpriteBatch sb, SpriteFont font)
        {
            var projection = Matrix.CreateOrthographicOffCenter(0f, ConvertUnits.ToSimUnits(sb.GraphicsDevice.Viewport.Width), ConvertUnits.ToSimUnits(sb.GraphicsDevice.Viewport.Height), 0f, 0f, 1f);

            _debugView.RenderDebugData(projection, camera.getScaledViewMatrix());


            var projection2 = Matrix.CreateOrthographicOffCenter(0f, sb.GraphicsDevice.Viewport.Width, sb.GraphicsDevice.Viewport.Height, 0f, 0f, 1f);

            _debugView.BeginCustomDraw(projection2, camera.getViewMatrix());

            foreach (var ray in player.controller.castList)
            {
                _debugView.DrawSegment(ray.from, ray.to, Color.Blue);
            }

            foreach (var p in platformList)
            {
                foreach (var ray in p.controller.castList)
                {
                    _debugView.DrawSegment(ray.from, ray.to, Color.White);
                }
            }


            var areaPoints = new Vector2[] {
                ConvertUnits.ToDisplayUnits(new Vector2(camera.focusArea.left, camera.focusArea.top)),
                ConvertUnits.ToDisplayUnits(new Vector2(camera.focusArea.right, camera.focusArea.top)),
                ConvertUnits.ToDisplayUnits(new Vector2(camera.focusArea.right, camera.focusArea.bottom)),
                ConvertUnits.ToDisplayUnits(new Vector2(camera.focusArea.left, camera.focusArea.bottom))
            };

            _debugView.DrawSolidPolygon(areaPoints, 4, Color.Red);

            _debugView.DrawPoint(ConvertUnits.ToDisplayUnits(camera.focusPosition), 3, Color.White);

            _debugView.DrawPoint(camera.Position, 3, Color.Pink);

            var cameraBounds = new Vector2[] {
                new Vector2(camera.Bounds.Left, camera.Bounds.Top),
                new Vector2(camera.Bounds.Right, camera.Bounds.Top),
                new Vector2(camera.Bounds.Right, camera.Bounds.Bottom),
                new Vector2(camera.Bounds.Left, camera.Bounds.Bottom)
            };

            _debugView.DrawPolygon(cameraBounds, 4, Color.Green);

            _debugView.EndCustomDraw();
        }
示例#11
0
        public override void Update(GameSettings settings, float elapsedSeconds)
        {
            base.Update(settings, elapsedSeconds);

            DistanceInput input;

            input.ProxyA     = new DistanceProxy(_polygonA, 0);
            input.ProxyB     = new DistanceProxy(_polygonB, 0);
            input.TransformA = _transformA;
            input.TransformB = _transformB;
            input.UseRadii   = true;
            SimplexCache cache;

            cache.Count = 0;
            DistanceOutput output;

            Distance.ComputeDistance(out output, out cache, input);

            DrawString("Distance = " + output.Distance);
            DrawString("Iterations = " + output.Iterations);

            DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);
            {
                Color     color = ColorHelper.FromPercentages(0.9f, 0.9f, 0.9f);
                Vector2[] v     = new Vector2[Settings.MaxPolygonVertices];
                for (int i = 0; i < _polygonA.Vertices.Count; ++i)
                {
                    v[i] = Transform.Multiply(_polygonA.Vertices[i], ref _transformA);
                }
                DebugView.DrawPolygon(v, _polygonA.Vertices.Count, color);

                for (int i = 0; i < _polygonB.Vertices.Count; ++i)
                {
                    v[i] = Transform.Multiply(_polygonB.Vertices[i], ref _transformB);
                }
                DebugView.DrawPolygon(v, _polygonB.Vertices.Count, color);
            }

            Vector2 x1 = output.PointA;
            Vector2 x2 = output.PointB;

            DebugView.DrawPoint(x1, 0.5f, ColorHelper.FromPercentages(1.0f, 0.0f, 0.0f));
            DebugView.DrawPoint(x2, 0.5f, ColorHelper.FromPercentages(1.0f, 0.0f, 0.0f));

            DebugView.DrawSegment(x1, x2, ColorHelper.FromPercentages(1.0f, 1.0f, 0.0f));
            DebugView.EndCustomDraw();
        }
示例#12
0
        public override void Update(FarseerPhysicsGameSettings settings)
        {
            base.Update(settings);

            DistanceInput input = new DistanceInput();

            input.ProxyA.Set(_polygonA, 0);
            input.ProxyB.Set(_polygonB, 0);
            input.TransformA = _transformA;
            input.TransformB = _transformB;
            input.UseRadii   = true;
            SimplexCache cache;

            cache.Count = 0;
            DistanceOutput output;

            Distance.ComputeDistance(out output, out cache, input);

            DrawString("Distance = " + output.Distance);
            DrawString("Iterations = " + output.Iterations);


            {
                Color     color = new ColorR(0.9f, 0.9f, 0.9f);
                Vector2[] v     = new Vector2[Alt.FarseerPhysics.Settings.MaxPolygonVertices];
                for (int i = 0; i < _polygonA.Vertices.Count; ++i)
                {
                    v[i] = MathUtils.Mul(ref _transformA, _polygonA.Vertices[i]);
                }
                DebugView.DrawPolygon(v, _polygonA.Vertices.Count, color);

                for (int i = 0; i < _polygonB.Vertices.Count; ++i)
                {
                    v[i] = MathUtils.Mul(ref _transformB, _polygonB.Vertices[i]);
                }
                DebugView.DrawPolygon(v, _polygonB.Vertices.Count, color);
            }

            Vector2 x1 = output.PointA;
            Vector2 x2 = output.PointB;

            DebugView.DrawPoint(x1, 0.5f, new ColorR(1.0f, 0.0f, 0.0f));
            DebugView.DrawPoint(x2, 0.5f, new ColorR(1.0f, 0.0f, 0.0f));

            DebugView.DrawSegment(x1, x2, new ColorR(1.0f, 1.0f, 0.0f));
        }
示例#13
0
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            DebugView.DrawString(50, TextLine, "Melkman: Red");
            TextLine += 15;
            DebugView.DrawString(50, TextLine, "Giftwrap: Green");
            TextLine += 15;
            DebugView.DrawString(50, TextLine, "ChainHull: Blue");
            TextLine += 15;

            DebugView.BeginCustomDraw();
            for (int i = 0; i < 32; i++)
            {
                DebugView.DrawPoint(_pointCloud1[i], 0.1f, Color.Yellow);
                DebugView.DrawPoint(_pointCloud2[i], 0.1f, Color.Yellow);
                DebugView.DrawPoint(_pointCloud3[i], 0.1f, Color.Yellow);
            }

            var vector2List = new List <CCVector2>();

            foreach (var v in _melkman)
            {
                vector2List.Add((CCVector2)v);
            }

            DebugView.DrawPolygon(vector2List.ToArray(), _melkman.Count, Color.Red);

            vector2List.Clear();
            foreach (var v in _giftWrap)
            {
                vector2List.Add((CCVector2)v);
            }
            DebugView.DrawPolygon(vector2List.ToArray(), _giftWrap.Count, Color.Green);

            vector2List.Clear();
            foreach (var v in _chainHull)
            {
                vector2List.Add((CCVector2)v);
            }

            DebugView.DrawPolygon(vector2List.ToArray(), _chainHull.Count, Color.Blue);
            DebugView.EndCustomDraw();

            base.Update(settings, gameTime);
        }
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            DrawString("Melkman: Red");
            DrawString("Giftwrap: Green");
            DrawString("ChainHull: Blue");

            DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);
            for (int i = 0; i < PointCount; i++)
            {
                DebugView.DrawPoint(_pointCloud1[i], 0.1f, Color.Yellow);
                DebugView.DrawPoint(_pointCloud2[i], 0.1f, Color.Yellow);
                DebugView.DrawPoint(_pointCloud3[i], 0.1f, Color.Yellow);
            }

            DebugView.DrawPolygon(_melkman.ToArray(), _melkman.Count, Color.Red);
            DebugView.DrawPolygon(_giftWrap.ToArray(), _giftWrap.Count, Color.Green);
            DebugView.DrawPolygon(_chainHull.ToArray(), _chainHull.Count, Color.Blue);
            DebugView.EndCustomDraw();

            base.Update(settings, gameTime);
        }
示例#15
0
        public override void Update(FarseerPhysicsGameSettings settings)
        {
            DrawString("Melkman: Red");
            DrawString("Giftwrap: Green");
            DrawString("ChainHull: Blue");


            for (int i = 0; i < PointCount; i++)
            {
                DebugView.DrawPoint(_pointCloud1[i], 0.1f, Color.Yellow);
                DebugView.DrawPoint(_pointCloud2[i], 0.1f, Color.Yellow);
                DebugView.DrawPoint(_pointCloud3[i], 0.1f, Color.Yellow);
            }

            DebugView.DrawPolygon(_melkman.ToArray(), _melkman.Count, Color.Red);
            DebugView.DrawPolygon(_giftWrap.ToArray(), _giftWrap.Count, Color.Green);
            DebugView.DrawPolygon(_chainHull.ToArray(), _chainHull.Count, Color.Blue);


            base.Update(settings);
        }
示例#16
0
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            Manifold manifold = new Manifold();

            Collision.Collision.CollidePolygons(ref manifold, _polygonA, ref _transformA, _polygonB, ref _transformB);

            Vector2 normal;
            FixedArray2 <Vector2> points;

            Collision.Collision.GetWorldManifold(ref manifold, ref _transformA, _polygonA.Radius,
                                                 ref _transformB, _polygonB.Radius, out normal, out points);

            DebugView.DrawString(50, TextLine, "Point count = {0:n0}", manifold.PointCount);
            TextLine += 15;
            DebugView.BeginCustomDraw();
            {
                Color     color = new Color(0.9f, 0.9f, 0.9f);
                Vector2[] v     = new Vector2[Settings.MaxPolygonVertices];
                for (int i = 0; i < _polygonA.Vertices.Count; ++i)
                {
                    v[i] = MathUtils.Multiply(ref _transformA, _polygonA.Vertices[i]);
                }
                DebugView.DrawPolygon(v, _polygonA.Vertices.Count, color);

                for (int i = 0; i < _polygonB.Vertices.Count; ++i)
                {
                    v[i] = MathUtils.Multiply(ref _transformB, _polygonB.Vertices[i]);
                }
                DebugView.DrawPolygon(v, _polygonB.Vertices.Count, color);
            }

            for (int i = 0; i < manifold.PointCount; ++i)
            {
                DebugView.DrawPoint(points[i], 0.1f, new Color(0.9f, 0.3f, 0.3f));
            }
            DebugView.EndCustomDraw();
        }
        public override void Update(GameSettings settings, float elapsedSeconds)
        {
            Manifold manifold = new Manifold();

            Collision.Collision.CollidePolygons(ref manifold, _polygonA, ref _transformA, _polygonB, ref _transformB);

            Vector2 normal;
            FixedArray2 <Vector2> points;

            ContactSolver.WorldManifold.Initialize(ref manifold, ref _transformA, _polygonA.Radius, ref _transformB, _polygonB.Radius, out normal, out points);

            DrawString("Point count = " + manifold.PointCount);

            DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);
            {
                Color     color = ColorHelper.FromPercentages(0.9f, 0.9f, 0.9f);
                Vector2[] v     = new Vector2[Settings.MaxPolygonVertices];
                for (int i = 0; i < _polygonA.Vertices.Count; ++i)
                {
                    v[i] = Transform.Multiply(_polygonA.Vertices[i], ref _transformA);
                }
                DebugView.DrawPolygon(v, _polygonA.Vertices.Count, color);

                for (int i = 0; i < _polygonB.Vertices.Count; ++i)
                {
                    v[i] = Transform.Multiply(_polygonB.Vertices[i], ref _transformB);
                }
                DebugView.DrawPolygon(v, _polygonB.Vertices.Count, color);
            }

            for (int i = 0; i < manifold.PointCount; ++i)
            {
                DebugView.DrawPoint(points[i], 0.1f, ColorHelper.FromPercentages(0.9f, 0.3f, 0.3f));
                DrawString(points[i].ToString());
            }
            DebugView.EndCustomDraw();
        }
示例#18
0
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            DebugView.DrawString(50, TextLine, "Melkman: Red");
            TextLine += 15;
            DebugView.DrawString(50, TextLine, "Giftwrap: Green");
            TextLine += 15;
            DebugView.DrawString(50, TextLine, "ChainHull: Blue");
            TextLine += 15;

            DebugView.BeginCustomDraw();
            for (int i = 0; i < 32; i++)
            {
                DebugView.DrawPoint(_pointCloud1[i], 0.1f, Color.Yellow);
                DebugView.DrawPoint(_pointCloud2[i], 0.1f, Color.Yellow);
                DebugView.DrawPoint(_pointCloud3[i], 0.1f, Color.Yellow);
            }

            DebugView.DrawPolygon(_melkman.ToArray(), _melkman.Count, Color.Red);
            DebugView.DrawPolygon(_giftWrap.ToArray(), _giftWrap.Count, Color.Green);
            DebugView.DrawPolygon(_chainHull.ToArray(), _chainHull.Count, Color.Blue);
            DebugView.EndCustomDraw();

            base.Update(settings, gameTime);
        }
示例#19
0
        public override void Update(FarseerPhysicsGameSettings settings)
        {
            base.Update(settings);

            PolygonShape shape = new PolygonShape(new Vertices(_points), 0f);

            DrawString("Press g to generate a new random convex hull");


            DebugView.DrawPolygon(shape.Vertices.ToArray(), shape.Vertices.Count, new ColorR(0.9, 0.9, 0.9));

            for (int i = 0; i < _count; ++i)
            {
                DebugView.DrawPoint(_points[i], 0.1f, new ColorR(0.9, 0.5, 0.5));
                Vector2 position = ConvertWorldToScreen(_points[i]);
                DebugView.DrawString((int)position.X, (int)position.Y, i.ToString());
            }


            if (_auto)
            {
                Generate();
            }
        }
示例#20
0
        public override void Update(FarseerPhysicsGameSettings settings)
        {
            Manifold manifold = new Manifold();

            Alt.FarseerPhysics.Collision.Collision.CollidePolygons(ref manifold, _polygonA, ref _transformA, _polygonB, ref _transformB);

            Vector2 normal;
            FixedArray2 <Vector2> points;

            ContactSolver.WorldManifold.Initialize(ref manifold, ref _transformA, _polygonA.Radius, ref _transformB, _polygonB.Radius, out normal, out points);

            DrawString("Point count = " + manifold.PointCount);


            {
                Color     color = new ColorR(0.9, 0.9, 0.9);
                Vector2[] v     = new Vector2[Alt.FarseerPhysics.Settings.MaxPolygonVertices];
                for (int i = 0; i < _polygonA.Vertices.Count; ++i)
                {
                    v[i] = MathUtils.Mul(ref _transformA, _polygonA.Vertices[i]);
                }
                DebugView.DrawPolygon(v, _polygonA.Vertices.Count, color);

                for (int i = 0; i < _polygonB.Vertices.Count; ++i)
                {
                    v[i] = MathUtils.Mul(ref _transformB, _polygonB.Vertices[i]);
                }
                DebugView.DrawPolygon(v, _polygonB.Vertices.Count, color);
            }

            for (int i = 0; i < manifold.PointCount; ++i)
            {
                DebugView.DrawPoint(points[i], 0.1f, new ColorR(0.9f, 0.3f, 0.3f));
                DrawString(points[i].ToString());
            }
        }
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            for (int i = 0; i < _polygons.Count; ++i)
            {
                if (_polygons[i] != null)
                {
                    CCVector2[] array = new CCVector2[_polygons.Count];
                    for (int p = 0; p < _polygons[i].Count; p++)
                    {
                        array[p] = (CCVector2)_polygons[i][p];
                    }

                    Color col = Color.SteelBlue;
                    if (!_polygons[i].IsCounterClockWise())
                    {
                        col = Color.Aquamarine;
                    }
                    if (_polygons[i] == _selected)
                    {
                        col = Color.LightBlue;
                    }
                    if (_polygons[i] == _subject)
                    {
                        col = Color.Green;
                        if (_polygons[i] == _selected)
                        {
                            col = Color.LightGreen;
                        }
                    }
                    if (_polygons[i] == _clip)
                    {
                        col = Color.DarkRed;
                        if (_polygons[i] == _selected)
                        {
                            col = Color.IndianRed;
                        }
                    }
                    DebugView.BeginCustomDraw();
                    DebugView.DrawPolygon(array, _polygons[i].Count, col);
                    for (int j = 0; j < _polygons[i].Count; ++j)
                    {
                        DebugView.DrawPoint(_polygons[i][j], .2f, Color.Red);
                    }
                    DebugView.EndCustomDraw();
                }
            }

            DebugView.DrawString(500, TextLine, "A,S,D = Create Rectangle");
            TextLine += 15;

            DebugView.DrawString(500, TextLine, "Q,W,E = Create Circle");
            TextLine += 15;

            DebugView.DrawString(500, TextLine, "Click to Drag polygons");
            TextLine += 15;

            DebugView.DrawString(500, TextLine, "1 = Select Subject while dragging [green]");
            TextLine += 15;

            DebugView.DrawString(500, TextLine, "2 = Select Clip while dragging [red]");
            TextLine += 15;

            DebugView.DrawString(500, TextLine, "Space = Union");
            TextLine += 15;

            DebugView.DrawString(500, TextLine, "Backspace = Subtract");
            TextLine += 15;

            DebugView.DrawString(500, TextLine, "Shift = Intersect");
            TextLine += 15;

            DebugView.DrawString(500, TextLine, "Holes are colored light blue");
            TextLine += 15;
        }
示例#22
0
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            base.Update(settings, gameTime);

            Sweep sweepA = new Sweep();

            sweepA.C0          = new Vector2(24.0f, -60.0f);
            sweepA.A0          = 2.95f;
            sweepA.C           = sweepA.C0;
            sweepA.A           = sweepA.A0;
            sweepA.LocalCenter = Vector2.Zero;

            Sweep sweepB = new Sweep();

            sweepB.C0          = new Vector2(53.474274f, -50.252514f);
            sweepB.A0          = 513.36676f; // - 162.0f * b2_pi;
            sweepB.C           = new Vector2(54.595478f, -51.083473f);
            sweepB.A           = 513.62781f; //  - 162.0f * b2_pi;
            sweepB.LocalCenter = Vector2.Zero;

            //sweepB.a0 -= 300.0f * b2_pi;
            //sweepB.a -= 300.0f * b2_pi;

            TOIInput input = new TOIInput();

            input.ProxyA.Set(_shapeA, 0);
            input.ProxyB.Set(_shapeB, 0);
            input.SweepA = sweepA;
            input.SweepB = sweepB;
            input.TMax   = 1.0f;

            TOIOutput output;

            TimeOfImpact.CalculateTimeOfImpact(out output, input);

            DrawString("TOI = " + output.T);
            DrawString(string.Format("Max TOI iters = {0:n}, Max root iters = {1:n}", TimeOfImpact.TOIMaxIters, TimeOfImpact.TOIMaxRootIters));

            Vector2[] vertices = new Vector2[Settings.MaxPolygonVertices];

            DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);
            Transform transformA;

            sweepA.GetTransform(out transformA, 0.0f);
            for (int i = 0; i < _shapeA.Vertices.Count; ++i)
            {
                vertices[i] = MathUtils.Mul(ref transformA, _shapeA.Vertices[i]);
            }
            DebugView.DrawPolygon(vertices, _shapeA.Vertices.Count, new Color(0.9f, 0.9f, 0.9f));

            Transform transformB;

            sweepB.GetTransform(out transformB, 0.0f);

            for (int i = 0; i < _shapeB.Vertices.Count; ++i)
            {
                vertices[i] = MathUtils.Mul(ref transformB, _shapeB.Vertices[i]);
            }
            DebugView.DrawPolygon(vertices, _shapeB.Vertices.Count, new Color(0.5f, 0.9f, 0.5f));

            sweepB.GetTransform(out transformB, output.T);
            for (int i = 0; i < _shapeB.Vertices.Count; ++i)
            {
                vertices[i] = MathUtils.Mul(ref transformB, _shapeB.Vertices[i]);
            }
            DebugView.DrawPolygon(vertices, _shapeB.Vertices.Count, new Color(0.5f, 0.7f, 0.9f));

            sweepB.GetTransform(out transformB, 1.0f);
            for (int i = 0; i < _shapeB.Vertices.Count; ++i)
            {
                vertices[i] = MathUtils.Mul(ref transformB, _shapeB.Vertices[i]);
            }
            DebugView.DrawPolygon(vertices, _shapeB.Vertices.Count, new Color(0.9f, 0.5f, 0.5f));
            DebugView.EndCustomDraw();
        }
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            base.Update(settings, gameTime);

            Sweep sweepA = new Sweep();

            sweepA.C0          = new Vector2(24.0f, -60.0f);
            sweepA.A0          = 2.95f;
            sweepA.C           = sweepA.C0;
            sweepA.A           = sweepA.A0;
            sweepA.LocalCenter = Vector2.Zero;

            Sweep sweepB = new Sweep();

            sweepB.C0          = new Vector2(53.474274f, -50.252514f);
            sweepB.A0          = 513.36676f; // - 162.0f * MathConstants.Pi;
            sweepB.C           = new Vector2(54.595478f, -51.083473f);
            sweepB.A           = 513.62781f; //  - 162.0f * MathConstants.Pi;
            sweepB.LocalCenter = Vector2.Zero;

            //sweepB.a0 -= 300.0f * MathConstants.Pi;
            //sweepB.a -= 300.0f * MathConstants.Pi;

            TOIInput input = new TOIInput();

            input.ProxyA = new DistanceProxy(_shapeA, 0);
            input.ProxyB = new DistanceProxy(_shapeB, 0);
            input.SweepA = sweepA;
            input.SweepB = sweepB;
            input.TMax   = 1.0f;

            TOIOutput output;

            TimeOfImpact.CalculateTimeOfImpact(ref input, out output);

            DrawString("toi = " + output.T);
            DrawString($"max toi iters = {TimeOfImpact.TOIMaxIters}, max root iters = {TimeOfImpact.TOIMaxRootIters}");

            Vector2[] vertices = new Vector2[Settings.MaxPolygonVertices];

            DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);

            Transform transformA;

            sweepA.GetTransform(out transformA, 0.0f);
            for (int i = 0; i < _shapeA.Vertices.Count; ++i)
            {
                vertices[i] = MathUtils.Mul(ref transformA, _shapeA.Vertices[i]);
            }
            DebugView.DrawPolygon(vertices, _shapeA.Vertices.Count, new Color(0.9f, 0.9f, 0.9f));

            Transform transformB;

            sweepB.GetTransform(out transformB, 0.0f);

            //b2Vec2 localPoint(2.0f, -0.1f);

            for (int i = 0; i < _shapeB.Vertices.Count; ++i)
            {
                vertices[i] = MathUtils.Mul(ref transformB, _shapeB.Vertices[i]);
            }
            DebugView.DrawPolygon(vertices, _shapeB.Vertices.Count, new Color(0.5f, 0.9f, 0.5f));

            sweepB.GetTransform(out transformB, output.T);
            for (int i = 0; i < _shapeB.Vertices.Count; ++i)
            {
                vertices[i] = MathUtils.Mul(ref transformB, _shapeB.Vertices[i]);
            }
            DebugView.DrawPolygon(vertices, _shapeB.Vertices.Count, new Color(0.5f, 0.7f, 0.9f));

            sweepB.GetTransform(out transformB, 1.0f);
            for (int i = 0; i < _shapeB.Vertices.Count; ++i)
            {
                vertices[i] = MathUtils.Mul(ref transformB, _shapeB.Vertices[i]);
            }
            DebugView.DrawPolygon(vertices, _shapeB.Vertices.Count, new Color(0.9f, 0.5f, 0.5f));

            DebugView.EndCustomDraw();

#if false
            for (float t = 0.0f; t < 1.0f; t += 0.1f)
            {
                sweepB.GetTransform(&transformB, t);
                for (int i = 0; i < _shapeB.m_count; ++i)
                {
                    vertices[i] = MathUtils.Mul(transformB, _shapeB.m_vertices[i]);
                }
                DebugView.DrawPolygon(vertices, _shapeB.m_count, b2Color(0.9f, 0.5f, 0.5f));
            }
#endif
        }
示例#24
0
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            base.Update(settings, gameTime);

            ShapeCastInput input = new ShapeCastInput();

            input.ProxyA       = new DistanceProxy(_vAs, _radiusA);
            input.ProxyB       = new DistanceProxy(_vBs, _radiusB);
            input.TransformA   = _transformA;
            input.TransformB   = _transformB;
            input.TranslationB = _translationB;

            ShapeCastOutput output;
            bool            hit = DistanceGJK.ShapeCast(ref input, out output);

            Transform transformB2;

            transformB2.q = _transformB.q;
            transformB2.p = _transformB.p + output.Lambda * input.TranslationB;

            DistanceInput distanceInput = new DistanceInput();

            distanceInput.ProxyA     = new DistanceProxy(_vAs, _radiusA);
            distanceInput.ProxyB     = new DistanceProxy(_vBs, _radiusB);
            distanceInput.TransformA = _transformA;
            distanceInput.TransformB = transformB2;
            distanceInput.UseRadii   = false;
            SimplexCache   simplexCache;
            DistanceOutput distanceOutput;

            DistanceGJK.ComputeDistance(ref distanceInput, out distanceOutput, out simplexCache);

            DrawString($"hit = {(hit ? "true" : "false")}, iters = {output.Iterations}, lambda = {output.Lambda}, distance = {distanceOutput.Distance}");

            Vector2[] vertices = new Vector2[Settings.MaxPolygonVertices];

            for (int i = 0; i < _countA; ++i)
            {
                vertices[i] = MathUtils.Mul(ref _transformA, _vAs[i]);
            }

            DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);

            if (_countA == 1)
            {
                DebugView.DrawCircle(vertices[0], _radiusA, new Color(0.9f, 0.9f, 0.9f));
            }
            else
            {
                DebugView.DrawPolygon(vertices, _countA, new Color(0.9f, 0.9f, 0.9f));
            }

            for (int i = 0; i < _countB; ++i)
            {
                vertices[i] = MathUtils.Mul(ref _transformB, _vBs[i]);
            }

            if (_countB == 1)
            {
                DebugView.DrawCircle(vertices[0], _radiusB, new Color(0.5f, 0.9f, 0.5f));
            }
            else
            {
                DebugView.DrawPolygon(vertices, _countB, new Color(0.5f, 0.9f, 0.5f));
            }

            for (int i = 0; i < _countB; ++i)
            {
                vertices[i] = MathUtils.Mul(ref transformB2, _vBs[i]);
            }

            if (_countB == 1)
            {
                DebugView.DrawCircle(vertices[0], _radiusB, new Color(0.5f, 0.7f, 0.9f));
            }
            else
            {
                DebugView.DrawPolygon(vertices, _countB, new Color(0.5f, 0.7f, 0.9f));
            }

            if (hit)
            {
                Vector2 p1 = output.Point;
                DebugView.DrawPoint(p1, 10.0f, new Color(0.9f, 0.3f, 0.3f));
                Vector2 p2 = p1 + output.Normal;
                DebugView.DrawSegment(p1, p2, new Color(0.9f, 0.3f, 0.3f));
            }

            DebugView.EndCustomDraw();
        }