Exemplo n.º 1
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();
        }
Exemplo n.º 2
0
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            DrawString("Use the mouse to create a polygon.");
            DrawString("Simple: " + _vertices.IsSimple());
            DrawString("Convex: " + _vertices.IsConvex());
            DrawString("CCW: " + _vertices.IsCounterClockWise());
            DrawString("Area: " + _vertices.GetArea());

            PolygonError returnCode = _vertices.CheckPolygon();

            if (returnCode == PolygonError.NoError)
                DrawString("Polygon is supported in Velcro Physics");
            else
                DrawString("Polygon is NOT supported in Velcro Physics. Reason: " + returnCode);

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

            for (int i = 0; i < _vertices.Count; i++)
            {
                Vector2 currentVertex = _vertices[i];
                Vector2 nextVertex = _vertices.NextVertex(i);

                DebugView.DrawPoint(currentVertex, 0.1f, Color.Yellow);
                DebugView.DrawSegment(currentVertex, nextVertex, Color.Red);
            }

            DebugView.DrawPoint(_vertices.GetCentroid(), 0.1f, Color.Green);

            AABB aabb = _vertices.GetAABB();
            DebugView.DrawAABB(ref aabb, Color.HotPink);

            DebugView.EndCustomDraw();
            base.Update(settings, gameTime);
        }
        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();
        }
Exemplo n.º 4
0
        public void RenderDebug(DebugView debugView, Matrix view, Matrix projection)
        {
            foreach (Car car in cars)
            {
                foreach (CastedRay ray in car.Rays)
                {
                    debugView.BeginCustomDraw(projection, view);

                    if (ray.Hit)
                    {
                        debugView.DrawPoint(ray.P1, .25f, new Color(0.9f, 0.4f, 0.4f));
                        debugView.DrawSegment(ray.P2, ray.P1, new Color(0.8f, 0.4f, 0.4f));
                    }
                    else
                    {
                        debugView.DrawPoint(ray.P1, .25f, new Color(0.4f, 0.9f, 0.4f));
                        debugView.DrawSegment(ray.P2, ray.P1, new Color(0.8f, 0.8f, 0.8f));
                    }
                    debugView.EndCustomDraw();
                }

                car.Rays.Clear();
            }
        }
Exemplo n.º 5
0
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            DrawString("Press A,S,W,D move endpoint");

            DrawString("Press Enter to cut");

            DrawString("Press TAB to change endpoint");


            DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);
            DebugView.DrawSegment(_start, _end, Color.Red);
            DebugView.EndCustomDraw();

            List <Fixture> fixtures    = new List <Fixture>();
            List <Vector2> entryPoints = new List <Vector2>();
            List <Vector2> exitPoints  = new List <Vector2>();

            //Get the entry points
            World.RayCast((f, p, n, fr) =>
            {
                fixtures.Add(f);
                entryPoints.Add(p);
                return(1);
            }, _start, _end);

            //Reverse the ray to get the exitpoints
            World.RayCast((f, p, n, fr) =>
            {
                exitPoints.Add(p);
                return(1);
            }, _end, _start);

            DrawString("Fixtures: " + fixtures.Count);

            DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);
            foreach (Vector2 entryPoint in entryPoints)
            {
                DebugView.DrawPoint(entryPoint, 0.5f, Color.Yellow);
            }

            foreach (Vector2 exitPoint in exitPoints)
            {
                DebugView.DrawPoint(exitPoint, 0.5f, Color.PowderBlue);
            }
            DebugView.EndCustomDraw();

            base.Update(settings, gameTime);
        }
Exemplo n.º 6
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();
        }
Exemplo n.º 7
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));
        }
Exemplo n.º 8
0
        public override void Update(FarseerPhysicsGameSettings settings)
        {
            bool advanceRay = settings.Pause == false || settings.SingleStep;

            base.Update(settings);
            DrawString("Press 1-5 to drop stuff");


            const double l      = 25.0f;
            Vector2      point1 = new Vector2(0.0f, 10.0f);
            Vector2      d      = new Vector2(l * (double)Math.Cos(_angle), -l * Math.Abs((double)Math.Sin(_angle)));
            Vector2      point2 = point1 + d;

            _fixture = null;

            World.RayCast((fixture, point, normal, fraction) =>
            {
                _fixture = fixture;
                _point   = point;
                _normal  = normal;

                return(fraction);
            }, point1, point2);


            if (_fixture != null)
            {
                DebugView.DrawPoint(_point, 0.5f, new ColorR(0.4f, 0.9f, 0.4f));

                DebugView.DrawSegment(point1, _point, new ColorR(0.8f, 0.8f, 0.8f));

                Vector2 head = _point + 0.5f * _normal;
                DebugView.DrawSegment(_point, head, new ColorR(0.9f, 0.9f, 0.4f));
            }
            else
            {
                DebugView.DrawSegment(point1, point2, new ColorR(0.8f, 0.8f, 0.8f));
            }


            if (advanceRay)
            {
                _angle += 0.25f * Alt.FarseerPhysics.Settings.Pi / 180.0f;
            }
        }
Exemplo n.º 9
0
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            bool advanceRay = settings.Pause == false || settings.SingleStep;

            base.Update(settings, gameTime);
            DrawString("Press 1-5 to drop stuff");


            const float l      = 25.0f;
            Vector2     point1 = new Vector2(0.0f, 10.0f);
            Vector2     d      = new Vector2(l * (float)Math.Cos(_angle), -l * Math.Abs((float)Math.Sin(_angle)));
            Vector2     point2 = point1 + d;

            _fixture = null;

            World.RayCast((fixture, point, normal, fraction) =>
            {
                _fixture = fixture;
                _point   = point;
                _normal  = normal;

                return(fraction);
            }, point1, point2);

            DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);
            if (_fixture != null)
            {
                DebugView.DrawPoint(_point, 0.5f, new Color(0.4f, 0.9f, 0.4f));

                DebugView.DrawSegment(point1, _point, new Color(0.8f, 0.8f, 0.8f));

                Vector2 head = _point + 0.5f * _normal;
                DebugView.DrawSegment(_point, head, new Color(0.9f, 0.9f, 0.4f));
            }
            else
            {
                DebugView.DrawSegment(point1, point2, new Color(0.8f, 0.8f, 0.8f));
            }
            DebugView.EndCustomDraw();

            if (advanceRay)
            {
                _angle += 0.25f * MathHelper.Pi / 180.0f;
            }
        }
Exemplo n.º 10
0
        public override void Update(FarseerPhysicsGameSettings settings)
        {
            DrawString("Use the mouse to create a polygon.");
            DrawString("Simple: " + _vertices.IsSimple());
            DrawString("Convex: " + _vertices.IsConvex());
            DrawString("CCW: " + _vertices.IsCounterClockWise());
            DrawString("Area: " + _vertices.GetArea());

            PolygonError returnCode = _vertices.CheckPolygon();

            if (returnCode == PolygonError.NoError)
            {
                DrawString("Polygon is supported in Farseer Physics Engine");
            }
            else
            {
                DrawString("Polygon is NOT supported in Farseer Physics Engine. Reason: " + returnCode);
            }



            for (int i = 0; i < _vertices.Count; i++)
            {
                Vector2 currentVertex = _vertices[i];
                Vector2 nextVertex    = _vertices.NextVertex(i);

                DebugView.DrawPoint(currentVertex, 0.1f, Color.Yellow);
                DebugView.DrawSegment(currentVertex, nextVertex, Color.Red);
            }

            DebugView.DrawPoint(_vertices.GetCentroid(), 0.1f, Color.Green);

            AABB aabb = _vertices.GetAABB();

            DebugView.DrawAABB(ref aabb, Color.HotPink);


            base.Update(settings);
        }
Exemplo n.º 11
0
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            bool advanceRay = !settings.Pause || settings.SingleStep;

            base.Update(settings, gameTime);
            DrawString("Press 1-5 to drop stuff");

            float   L      = 25.0f;
            Vector2 point1 = new Vector2(0.0f, 10.0f);
            Vector2 d      = new Vector2(L * MathUtils.Cosf(_angle), -L * MathUtils.Abs(MathUtils.Sinf(_angle)));
            Vector2 point2 = point1 + d;

            EdgeShapesCallback callback = new EdgeShapesCallback();

            World.RayCast(callback.ReportFixture, point1, point2);

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

            if (callback._fixture != null)
            {
                DebugView.DrawPoint(callback._point, 5f, new Color(0.4f, 0.9f, 0.4f));

                DebugView.DrawSegment(point1, callback._point, new Color(0.8f, 0.8f, 0.8f));

                Vector2 head = callback._point + 0.5f * callback._normal;
                DebugView.DrawSegment(callback._point, head, new Color(0.9f, 0.9f, 0.4f));
            }
            else
            {
                DebugView.DrawSegment(point1, point2, new Color(0.8f, 0.8f, 0.8f));
            }

            DebugView.EndCustomDraw();

            if (advanceRay)
            {
                _angle += 0.25f * MathConstants.Pi / 180.0f;
            }
        }
Exemplo n.º 12
0
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            _rayActor = null;
            for (int i = 0; i < ActorCount; ++i)
            {
                _actors[i].Fraction = 1.0f;
                _actors[i].Overlap  = false;
            }

            if (_automated)
            {
                int actionCount = Math.Max(1, ActorCount >> 2);

                for (int i = 0; i < actionCount; ++i)
                {
                    Action();
                }
            }

            Query();
            RayCast();

            DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);
            for (int i = 0; i < ActorCount; ++i)
            {
                Actor actor = _actors[i];
                if (actor.ProxyId == -1)
                {
                    continue;
                }

                Color ca = new Color(0.9f, 0.9f, 0.9f);
                if (actor == _rayActor && actor.Overlap)
                {
                    ca = new Color(0.9f, 0.6f, 0.6f);
                }
                else if (actor == _rayActor)
                {
                    ca = new Color(0.6f, 0.9f, 0.6f);
                }
                else if (actor.Overlap)
                {
                    ca = new Color(0.6f, 0.6f, 0.9f);
                }

                DebugView.DrawAABB(ref actor.AABB, ca);
            }

            Color c = new Color(0.7f, 0.7f, 0.7f);

            DebugView.DrawAABB(ref _queryAABB, c);

            DebugView.DrawSegment(_rayCastInput.Point1, _rayCastInput.Point2, c);

            Color c1 = new Color(0.2f, 0.9f, 0.2f);
            Color c2 = new Color(0.9f, 0.2f, 0.2f);

            DebugView.DrawPoint(_rayCastInput.Point1, 0.1f, c1);
            DebugView.DrawPoint(_rayCastInput.Point2, 0.1f, c2);

            if (_rayActor != null)
            {
                Color   cr = new Color(0.2f, 0.2f, 0.9f);
                Vector2 p  = _rayCastInput.Point1 + _rayActor.Fraction * (_rayCastInput.Point2 - _rayCastInput.Point1);
                DebugView.DrawPoint(p, 0.1f, cr);
            }
            DebugView.EndCustomDraw();

            int height = _tree.Height;

            DrawString("Dynamic tree height = " + height);
        }
Exemplo n.º 13
0
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            bool advanceRay = settings.Pause == false || settings.SingleStep;

            base.Update(settings, gameTime);

            DebugView.DrawString(50, TextLine, "Press 1-5 to drop stuff, m to change the mode");
            TextLine += 15;
            DebugView.DrawString(50, TextLine, string.Format("Mode = {0}", _mode));
            TextLine += 15;

            const float l      = 11.0f;
            Vector2     point1 = new Vector2(0.0f, 10.0f);
            Vector2     d      = new Vector2(l * (float)Math.Cos(_angle), l * (float)Math.Sin(_angle));
            Vector2     point2 = point1 + d;

            Vector2 point = Vector2.Zero, normal = Vector2.Zero;

            switch (_mode)
            {
            case RayCastMode.Closest:
                bool hitClosest = false;
                World.RayCast((f, p, n, fr) =>
                {
                    Body body = f.Body;
                    if (body.UserData != null)
                    {
                        int index = (int)body.UserData;
                        if (index == 0)
                        {
                            // filter
                            return(-1.0f);
                        }
                    }

                    hitClosest = true;
                    point      = p;
                    normal     = n;
                    return(fr);
                }, point1, point2);

                if (hitClosest)
                {
                    DebugView.BeginCustomDraw();
                    DebugView.DrawPoint(point, .5f, new Color(0.4f, 0.9f, 0.4f));

                    DebugView.DrawSegment(point1, point, new Color(0.8f, 0.8f, 0.8f));

                    Vector2 head = point + 0.5f * normal;
                    DebugView.DrawSegment(point, head, new Color(0.9f, 0.9f, 0.4f));
                    DebugView.EndCustomDraw();
                }
                else
                {
                    DebugView.BeginCustomDraw();
                    DebugView.DrawSegment(point1, point2, new Color(0.8f, 0.8f, 0.8f));
                    DebugView.EndCustomDraw();
                }

                break;

            case RayCastMode.Any:
                bool hitAny = false;
                World.RayCast((f, p, n, fr) =>
                {
                    Body body = f.Body;
                    if (body.UserData != null)
                    {
                        int index = (int)body.UserData;
                        if (index == 0)
                        {
                            // filter
                            return(-1.0f);
                        }
                    }

                    hitAny = true;
                    point  = p;
                    normal = n;
                    return(0);
                }, point1, point2);

                if (hitAny)
                {
                    DebugView.BeginCustomDraw();
                    DebugView.DrawPoint(point, .5f, new Color(0.4f, 0.9f, 0.4f));

                    DebugView.DrawSegment(point1, point, new Color(0.8f, 0.8f, 0.8f));

                    Vector2 head = point + 0.5f * normal;
                    DebugView.DrawSegment(point, head, new Color(0.9f, 0.9f, 0.4f));
                    DebugView.EndCustomDraw();
                }
                else
                {
                    DebugView.BeginCustomDraw();
                    DebugView.DrawSegment(point1, point2, new Color(0.8f, 0.8f, 0.8f));
                    DebugView.EndCustomDraw();
                }
                break;

            case RayCastMode.Multiple:
                List <Vector2> points  = new List <Vector2>();
                List <Vector2> normals = new List <Vector2>();
                World.RayCast((f, p, n, fr) =>
                {
                    Body body = f.Body;
                    if (body.UserData != null)
                    {
                        int index = (int)body.UserData;
                        if (index == 0)
                        {
                            // filter
                            return(-1.0f);
                        }
                    }

                    points.Add(p);
                    normals.Add(n);
                    return(1.0f);
                }, point1, point2);

                DebugView.BeginCustomDraw();
                DebugView.DrawSegment(point1, point2, new Color(0.8f, 0.8f, 0.8f));

                for (int i = 0; i < points.Count; i++)
                {
                    DebugView.DrawPoint(points[i], .5f, new Color(0.4f, 0.9f, 0.4f));

                    DebugView.DrawSegment(point1, points[i], new Color(0.8f, 0.8f, 0.8f));

                    Vector2 head = points[i] + 0.5f * normals[i];
                    DebugView.DrawSegment(points[i], head, new Color(0.9f, 0.9f, 0.4f));
                }
                DebugView.EndCustomDraw();
                break;

            default:
                break;
            }

            if (advanceRay)
            {
                _angle += 0.25f * Settings.Pi / 180.0f;
            }
        }
Exemplo n.º 14
0
        public override void Update(GameSettings settings, float elapsedSeconds)
        {
            bool advanceRay = settings.Pause == false || settings.SingleStep;

            base.Update(settings, elapsedSeconds);

            DrawString("Press 1-5 to drop stuff, m to change the mode");
            DrawString(string.Format("Mode = {0}", _mode));

            const float l      = 11.0f;
            Vector2     point1 = new Vector2(0.0f, 10.0f);
            Vector2     d      = new Vector2(l * (float)Math.Cos(_angle), l * (float)Math.Sin(_angle));
            Vector2     point2 = point1 + d;

            Vector2 point = Vector2.Zero, normal = Vector2.Zero;

            switch (_mode)
            {
            case RayCastMode.Closest:
                bool hitClosest = false;
                World.RayCast((f, p, n, fr) =>
                {
                    Body body = f.Body;
                    if (body.Tag != null)
                    {
                        int index = (int)body.Tag;
                        if (index == 0)
                        {
                            // filter
                            return(-1.0f);
                        }
                    }

                    hitClosest = true;
                    point      = p;
                    normal     = n;
                    return(fr);
                }, point1, point2);

                if (hitClosest)
                {
                    DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);
                    DebugView.DrawPoint(point, .5f, ColorHelper.FromPercentages(0.4f, 0.9f, 0.4f));

                    DebugView.DrawSegment(point1, point, ColorHelper.FromPercentages(0.8f, 0.8f, 0.8f));

                    Vector2 head = point + 0.5f * normal;
                    DebugView.DrawSegment(point, head, ColorHelper.FromPercentages(0.9f, 0.9f, 0.4f));
                    DebugView.EndCustomDraw();
                }
                else
                {
                    DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);
                    DebugView.DrawSegment(point1, point2, ColorHelper.FromPercentages(0.8f, 0.8f, 0.8f));
                    DebugView.EndCustomDraw();
                }

                break;

            case RayCastMode.Any:
                bool hitAny = false;
                World.RayCast((f, p, n, fr) =>
                {
                    Body body = f.Body;
                    if (body.Tag != null)
                    {
                        int index = (int)body.Tag;
                        if (index == 0)
                        {
                            // filter
                            return(-1.0f);
                        }
                    }

                    hitAny = true;
                    point  = p;
                    normal = n;
                    return(0);
                }, point1, point2);

                if (hitAny)
                {
                    DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);
                    DebugView.DrawPoint(point, .5f, ColorHelper.FromPercentages(0.4f, 0.9f, 0.4f));

                    DebugView.DrawSegment(point1, point, ColorHelper.FromPercentages(0.8f, 0.8f, 0.8f));

                    Vector2 head = point + 0.5f * normal;
                    DebugView.DrawSegment(point, head, ColorHelper.FromPercentages(0.9f, 0.9f, 0.4f));
                    DebugView.EndCustomDraw();
                }
                else
                {
                    DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);
                    DebugView.DrawSegment(point1, point2, ColorHelper.FromPercentages(0.8f, 0.8f, 0.8f));
                    DebugView.EndCustomDraw();
                }
                break;

            case RayCastMode.Multiple:
                List <Vector2> points  = new List <Vector2>();
                List <Vector2> normals = new List <Vector2>();
                World.RayCast((f, p, n, fr) =>
                {
                    Body body = f.Body;
                    if (body.Tag != null)
                    {
                        int index = (int)body.Tag;
                        if (index == 0)
                        {
                            // filter
                            return(-1.0f);
                        }
                    }

                    points.Add(p);
                    normals.Add(n);
                    return(1.0f);
                }, point1, point2);

                DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);
                DebugView.DrawSegment(point1, point2, ColorHelper.FromPercentages(0.8f, 0.8f, 0.8f));

                for (int i = 0; i < points.Count; i++)
                {
                    DebugView.DrawPoint(points[i], .5f, ColorHelper.FromPercentages(0.4f, 0.9f, 0.4f));

                    DebugView.DrawSegment(point1, points[i], ColorHelper.FromPercentages(0.8f, 0.8f, 0.8f));

                    Vector2 head = points[i] + 0.5f * normals[i];
                    DebugView.DrawSegment(points[i], head, ColorHelper.FromPercentages(0.9f, 0.9f, 0.4f));
                }

                DebugView.EndCustomDraw();
                break;
            }

            if (advanceRay)
            {
                _angle += 0.25f * MathHelper.Pi / 180.0f;
            }
        }
Exemplo n.º 15
0
        public override void Update(FarseerPhysicsGameSettings settings)
        {
            _rayActor = null;
            for (int i = 0; i < ActorCount; ++i)
            {
                _actors[i].Fraction = 1.0f;
                _actors[i].Overlap  = false;
            }

            if (_automated)
            {
                int actionCount = Math.Max(1, ActorCount >> 2);

                for (int i = 0; i < actionCount; ++i)
                {
                    Action();
                }
            }

            Query();
            RayCast();


            for (int i = 0; i < ActorCount; ++i)
            {
                Actor actor = _actors[i];
                if (actor.ProxyId == -1)
                {
                    continue;
                }

                Color ca = new ColorR(0.9, 0.9, 0.9);
                if (actor == _rayActor && actor.Overlap)
                {
                    ca = new ColorR(0.9, 0.6, 0.6);
                }
                else if (actor == _rayActor)
                {
                    ca = new ColorR(0.6, 0.9, 0.6);
                }
                else if (actor.Overlap)
                {
                    ca = new ColorR(0.6, 0.6, 0.9);
                }

                DebugView.DrawAABB(ref actor.AABB, ca);
            }

            Color c = new ColorR(0.7, 0.7, 0.7);

            DebugView.DrawAABB(ref _queryAABB, c);

            DebugView.DrawSegment(_rayCastInput.Point1, _rayCastInput.Point2, c);

            Color c1 = new ColorR(0.2, 0.9, 0.2);
            Color c2 = new ColorR(0.9, 0.2, 0.2);

            DebugView.DrawPoint(_rayCastInput.Point1, 0.1f, c1);
            DebugView.DrawPoint(_rayCastInput.Point2, 0.1f, c2);

            if (_rayActor != null)
            {
                Color   cr = new ColorR(0.2f, 0.2f, 0.9f);
                Vector2 p  = _rayCastInput.Point1 + _rayActor.Fraction * (_rayCastInput.Point2 - _rayCastInput.Point1);
                DebugView.DrawPoint(p, 0.1f, cr);
            }


            int height = _tree.Height;

            DrawString("Dynamic tree Height = " + height);
        }
Exemplo n.º 16
0
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            //B2_NOT_USED(settings);

            _rayActor = null;
            for (int i = 0; i < _actorCount; ++i)
            {
                _actors[i].fraction = 1.0f;
                _actors[i].overlap  = false;
            }

            if (_automated)
            {
                int actionCount = MathUtils.Max(1, _actorCount >> 2);

                for (int i = 0; i < actionCount; ++i)
                {
                    Action();
                }
            }

            Query();
            RayCast();

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

            for (int i = 0; i < _actorCount; ++i)
            {
                Actor actor = _actors[i];
                if (actor.proxyId == DynamicTree <Actor> .NullNode)
                {
                    continue;
                }

                Color c = new Color(0.9f, 0.9f, 0.9f);
                if (actor == _rayActor && actor.overlap)
                {
                    c = new Color(0.9f, 0.6f, 0.6f);
                }
                else if (actor == _rayActor)
                {
                    c = new Color(0.6f, 0.9f, 0.6f);
                }
                else if (actor.overlap)
                {
                    c = new Color(0.6f, 0.6f, 0.9f);
                }

                DebugView.DrawAABB(ref actor.aabb, c);
            }

            {
                Color c = new Color(0.7f, 0.7f, 0.7f);
                DebugView.DrawAABB(ref _queryAABB, c);

                DebugView.DrawSegment(_rayCastInput.Point1, _rayCastInput.Point2, c);
            }
            Color c1 = new Color(0.2f, 0.9f, 0.2f);
            Color c2 = new Color(0.9f, 0.2f, 0.2f);

            DebugView.DrawPoint(_rayCastInput.Point1, 6.0f, c1);
            DebugView.DrawPoint(_rayCastInput.Point2, 6.0f, c2);

            if (_rayActor != null)
            {
                Color   cr = new Color(0.2f, 0.2f, 0.9f);
                Vector2 p  = _rayCastInput.Point1 + _rayActor.fraction * (_rayCastInput.Point2 - _rayCastInput.Point1);
                DebugView.DrawPoint(p, 6.0f, cr);
            }

            {
                int height = _tree.Height;
                DrawString("dynamic tree height = " + height);
            }

            DebugView.EndCustomDraw();

            ++_stepCount;
            base.Update(settings, gameTime);
        }
Exemplo n.º 17
0
        //void UpdateUI()
        //{
        //    ImGui::SetNextWindowPos(ImVec2(10.0f, 100.0f));
        //    ImGui::SetNextWindowSize(ImVec2(210.0f, 285.0f));
        //    ImGui::Begin("Ray-cast Controls", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);

        //    if (ImGui::Button("Shape 1"))
        //    {
        //        Create(0);
        //    }

        //    if (ImGui::Button("Shape 2"))
        //    {
        //        Create(1);
        //    }

        //    if (ImGui::Button("Shape 3"))
        //    {
        //        Create(2);
        //    }

        //    if (ImGui::Button("Shape 4"))
        //    {
        //        Create(3);
        //    }

        //    if (ImGui::Button("Shape 5"))
        //    {
        //        Create(4);
        //    }

        //    if (ImGui::Button("Shape 6"))
        //    {
        //        Create(5);
        //    }

        //    if (ImGui::Button("Destroy Shape"))
        //    {
        //        DestroyBody();
        //    }

        //    ImGui::RadioButton("Any", _mode, Any);
        //    ImGui::RadioButton("Closest", _mode, Closest);
        //    ImGui::RadioButton("Multiple", _mode, Multiple);

        //    ImGui::SliderFloat("Angle", _degrees, 0.0f, 360.0f, "%.0f");

        //    ImGui::End();
        //}

        public override void Update(GameSettings settings, GameTime gameTime)
        {
            base.Update(settings, gameTime);

            DrawString("Shape 1 is intentionally ignored by the ray");
            switch (_mode)
            {
            case Mode.Closest:
                DrawString("Ray-cast mode: closest - find closest fixture along the ray");
                break;

            case Mode.Any:
                DrawString("Ray-cast mode: any - check for obstruction");
                break;

            case Mode.Multiple:
                DrawString("Ray-cast mode: multiple - gather multiple fixtures");
                break;
            }

            float   angle  = MathConstants.Pi * _degrees / 180.0f;
            float   L      = 11.0f;
            Vector2 point1 = new Vector2(0.0f, 10.0f);
            Vector2 d      = new Vector2(L * MathUtils.Cosf(angle), L * MathUtils.Sinf(angle));
            Vector2 point2 = point1 + d;

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

            if (_mode == Mode.Closest)
            {
                RayCastClosestCallback callback = new RayCastClosestCallback();
                World.RayCast(callback.ReportFixture, point1, point2);

                if (callback._hit)
                {
                    DebugView.DrawPoint(callback._point, 5.0f, new Color(0.4f, 0.9f, 0.4f));
                    DebugView.DrawSegment(point1, callback._point, new Color(0.8f, 0.8f, 0.8f));
                    Vector2 head = callback._point + 0.5f * callback._normal;
                    DebugView.DrawSegment(callback._point, head, new Color(0.9f, 0.9f, 0.4f));
                }
                else
                {
                    DebugView.DrawSegment(point1, point2, new Color(0.8f, 0.8f, 0.8f));
                }
            }
            else if (_mode == Mode.Any)
            {
                RayCastAnyCallback callback = new RayCastAnyCallback();
                World.RayCast(callback.ReportFixture, point1, point2);

                if (callback._hit)
                {
                    DebugView.DrawPoint(callback._point, 5.0f, new Color(0.4f, 0.9f, 0.4f));
                    DebugView.DrawSegment(point1, callback._point, new Color(0.8f, 0.8f, 0.8f));
                    Vector2 head = callback._point + 0.5f * callback._normal;
                    DebugView.DrawSegment(callback._point, head, new Color(0.9f, 0.9f, 0.4f));
                }
                else
                {
                    DebugView.DrawSegment(point1, point2, new Color(0.8f, 0.8f, 0.8f));
                }
            }
            else if (_mode == Mode.Multiple)
            {
                RayCastMultipleCallback callback = new RayCastMultipleCallback();
                World.RayCast(callback.ReportFixture, point1, point2);
                DebugView.DrawSegment(point1, point2, new Color(0.8f, 0.8f, 0.8f));

                for (int i = 0; i < callback._count; ++i)
                {
                    Vector2 p = callback._points[i];
                    Vector2 n = callback._normals[i];
                    DebugView.DrawPoint(p, 5.0f, new Color(0.4f, 0.9f, 0.4f));
                    DebugView.DrawSegment(point1, p, new Color(0.8f, 0.8f, 0.8f));
                    Vector2 head = p + 0.5f * n;
                    DebugView.DrawSegment(p, head, new Color(0.9f, 0.9f, 0.4f));
                }
            }

            DebugView.EndCustomDraw();

#if false
            // This case was failing.
            {
                b2Vec2 vertices[4];
Exemplo n.º 18
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();
        }