Silverlight 2 Farseer Physics Geom Visual Helper Method

by calbert 8/21/2008 9:43:00 PM

I ported some code from the Farseer Physics Engine XNA demos that displayed  a debug view of the geom vertices used with the Physics Simulator. This is useful if you want to see where your geoms are being rendered to the screen to make sure you have everything in the right place. I know I need this a lot, helps me to understand where I am placing body geoms.

Anyway, here is the method, the _debug variable is just a Canvas I added at the top of the UI. Keep in mind that this method will slow your game WAY down so be sure and use it to test where geoms are positioned and if everything is moving properly. I use a static variable for the PhysicsSimulator, hence the cleverly named Physics.Simulator.

        private void DrawVertices()
        {
            _debug.Children.Clear();
            int verticeCount = 0;
            for (int i = 0; i < Physics.Simulator.GeomList.Count; i++)
            {
                verticeCount = Physics.Simulator.GeomList[i].LocalVertices.Count;
                for (int j = 0; j < verticeCount; j++)
                {
                    Line line = new Line();
                    line.Fill = new SolidColorBrush(Colors.Transparent);
                    line.Stroke = new SolidColorBrush(Colors.Magenta);
                    line.StrokeThickness = 1;
                    if (j < verticeCount - 1)
                    {
                        line.X1 = Physics.Simulator.GeomList[i].WorldVertices[j].X;
                        line.Y1 = Physics.Simulator.GeomList[i].WorldVertices[j].Y;
                        line.X2 = Physics.Simulator.GeomList[i].WorldVertices[j + 1].X;
                        line.Y2 = Physics.Simulator.GeomList[i].WorldVertices[j + 1].Y;
                    }
                    else
                    {
                        line.X1 = Physics.Simulator.GeomList[i].WorldVertices[j].X;
                        line.Y1 = Physics.Simulator.GeomList[i].WorldVertices[j].Y;
                        line.X2 = Physics.Simulator.GeomList[i].WorldVertices[0].X;
                        line.Y2 = Physics.Simulator.GeomList[i].WorldVertices[0].Y;
                    }
                    _debug.Children.Add(line);
                }
            }
        }

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Game Development | Silverlight 2 Development | Silverlight Games

Powered by BlogEngine.NET 1.3.1.0
Theme by Mads Kristensen

About the author

I am Senior Software Engineer specializing in the Microsoft .NET Framework and PBBG development.

E-mail me Send mail

Calendar

<<  August 2008  >>
MoTuWeThFrSaSu
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

View posts in large calendar

Recent posts

Recent comments