コード例 #1
0
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            DebugView.DrawString(50, TextLine,
                                 "SimpleWindForce | Mouse: Direction | Left-Click: Position | W/S: Variation");
            TextLine += 15;
            DebugView.DrawString(50, TextLine, "Wind Strength:" + _simpleWind.Strength);
            TextLine += 15;
            DebugView.DrawString(50, TextLine, "Variation:" + _simpleWind.Variation);

            DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);
            //DebugView.DrawSegment(SimpleWind.Position, SimpleWind.Direction-SimpleWind.Position, Color.Red);
            DrawPointForce();
            DebugView.EndCustomDraw();
            base.Update(settings, gameTime);
        }
コード例 #2
0
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);
            DebugView.DrawAABB(ref _terrainArea, Color.Red * 0.5f);
            DebugView.EndCustomDraw();

            DrawString("Left click and drag the mouse to destroy terrain!");
            DrawString("Right click and drag the mouse to create terrain!");
            DrawString("Middle click to create circles!");
            DrawString("Press t or y to cycle between decomposers: " + _terrain.Decomposer);
            TextLine += 25;
            DrawString("Press g or h to decrease/increase circle radius: " + _circleRadius);

            base.Update(settings, gameTime);
        }
コード例 #3
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);
        }
コード例 #4
0
ファイル: DistanceTest.cs プロジェクト: lab132/owlicity
        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);

            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;

            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();
        }
コード例 #5
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();
        }
コード例 #6
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;
            }
        }
コード例 #7
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);
        }
コード例 #8
0
        public override void Mouse(MouseManager mouse)
        {
            Vector2 position = GameInstance.ConvertScreenToWorld(mouse.NewPosition);

            if (mouse.IsButtonDown(MouseButton.Left))
            {
                DrawCircleOnMap(position, (sbyte)(_create ? -1 : 1));
                _terrain.RegenerateTerrain();

                DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);
                DebugView.DrawSolidCircle(position, _circleRadius, Vector2.UnitY, Color.Red * 0.5f);
                DebugView.EndCustomDraw();
            }
            else if (mouse.IsButtonDown(MouseButton.Middle))
            {
                Body circle = BodyFactory.CreateCircle(World, 1, 1);
                circle.BodyType = BodyType.Dynamic;
                circle.Position = position;
            }
        }
コード例 #9
0
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            base.Update(settings, gameTime);

            DrawString("Press: (,) to explode at mouse position.");
            
            DrawString("Press: (A) to decrease the explosion radius, (S) to increase it.");
            
            DrawString("Press: (D) to decrease the explosion power, (F) to increase it.");
            
            // Fighting against float decimals
            float powernumber = (float)((int)(_force * 10)) / 10;
            DrawString("Power: " + powernumber);

            Color color = new Color(0.4f, 0.7f, 0.8f);
            DebugView.BeginCustomDraw(ref GameInstance.Projection, ref GameInstance.View);
            DebugView.DrawCircle(_mousePos, _radius, color);

            DebugView.EndCustomDraw();
        }
コード例 #10
0
        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);
        }
コード例 #11
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;

            ContactSolver.WorldManifold.Initialize(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(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)
            {
                TextLine += 15;
                DebugView.DrawPoint(points[i], 0.1f, new Color(0.9f, 0.3f, 0.3f));
                DebugView.DrawString(50, TextLine, "{0}", points[i].ToString());
                TextLine += 15;
            }
            DebugView.EndCustomDraw();
        }
コード例 #12
0
        public override void Update(GameSettings settings, float elapsedSeconds)
        {
            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");
            }
            else
            {
                DrawString("Polygon is NOT supported. 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, elapsedSeconds);
        }
コード例 #13
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;
            }
        }
コード例 #14
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(ref GameInstance.Projection, ref GameInstance.View);
            DebugView.DrawPolygon(tempshape.ToArray(), _clipCircle.Count, color);
            DebugView.EndCustomDraw();
        }
コード例 #15
0
        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 Vector2 normal, out FixedArray2 <Vector2> points, out FixedArray2 <float> separations);

            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], 4.0f, new Color(0.9f, 0.3f, 0.3f));
            }

            DebugView.EndCustomDraw();

            base.Update(settings, gameTime);
        }
コード例 #16
0
        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();
        }
コード例 #17
0
        public override void Update(GameSettings settings, GameTime gameTime)
        {
            DrawString(string.Format("Center ({0}): Original polygon", _twoShape.Count));

            DrawString(string.Format("Upper left ({0}): Simplified by removing points with an area of below 0.1", _upperLeft.Count));

            DrawString(string.Format("Upper right ({0}): Simplified by removing every 3 point", _upperRight.Count));

            DrawString(string.Format("Lower left ({0}): Simplified by removing points with a distance of less than 1", _lowerLeft.Count));

            DrawString(string.Format("Lower right ({0}): Simplified with Douglas Peucker", _lowerRight.Count));

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

            DrawVertices(_twoShape);
            DrawVertices(_upperLeft);
            DrawVertices(_upperRight);
            DrawVertices(_lowerLeft);
            DrawVertices(_lowerRight);

            DebugView.EndCustomDraw();

            base.Update(settings, gameTime);
        }
コード例 #18
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();
            }
        }
コード例 #19
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);
        }
コード例 #20
0
        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;
        }
コード例 #21
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;
            }
        }
コード例 #22
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;
            }
        }
コード例 #23
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 * 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);

            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();
        }
コード例 #25
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();
        }
コード例 #26
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);
        }
コード例 #27
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);
        }
コード例 #28
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];