Cut tool producing polygons with null shape type?

Topics: User Forum
Mar 22, 2011 at 10:33 PM
Edited Mar 22, 2011 at 10:44 PM

I've been using Farseer 3.3 to write a 2D game. I've been using the cut tool to slice polygons to bits.

I then store both the new fixtures in a list of Fixtures. When i try to do some ShapeType comparison I get the exception that the object reference isnt set to an instance, in this case due to the fact that ShapeType && shape for the fixtures is null.

Yet for an if statement checking to see if the ShapeType for the fixture is not null it tells me that it will always be true as ShapeType cannot be null despite the fact that they are.

Is there anyway for me to set the ShapeType or shape of the a cut fixture and if not is there a way in which i can grab the vertices from the fixtures? And is this all simply because of an extremely foolish error on my behalf?

Code as follows:

To store the fixtures:

if (CuttingTools.fixtures != null)
            {
                for (int i = 0; i < CuttingTools.fixtures.Count; ++i)
                {
                    if (CuttingTools.fixtures != null)
                    {
                        if (cutPolygonList.Count == 0)
                        {
                            Fixture newCutPolygon = new Fixture(CuttingTools.fixtures.ElementAt(i).Body, CuttingTools.fixtures.ElementAt(i).Shape);
                            cutPolygonList.Add(newCutPolygon);
                        }
                        if (CuttingTools.fixtures[i] != cutPolygonList[i])
                        {
                            newCutPolygon = CuttingTools.fixtures[i];
                            cutPolygonList.Add(newCutPolygon);
                        }
                    }
                }
            }

 

To check ShapeType:

 

            for (int i = 0; i < cutPolygonList.Count; ++i)
            {
                Transform transform = new Transform();
                cutPolygonList[i].Body.GetTransform(out transform);

                #region circle draw

                ShapeType circleType = new ShapeType();

                circleType = ShapeType.Circle;

                // if (cutPolygonList[i].ShapeType != null)
                {
                    try
                    {
                        //if (cutPolygonList[i].ShapeType == circleType)
                        {
                            CircleShape circle = (CircleShape)cutPolygonList[i].Shape;

                            Vector2 center = MathUtils.Multiply(ref transform, circle.Position);
                            float radius = circle.Radius;
                            Vector2 axis = transform.R.Col1;

                            _debugView.DrawSolidCircle(center, radius, axis, Color.Black);
                        }
                    }
                    catch
                    {
                    }
                #endregion

                    #region poly draw


                    ShapeType polygonType = new ShapeType();

                    polygonType = ShapeType.Polygon;

                    //      if (cutPolygonList[i].ShapeType == polygonType)
                    {

                        PolygonShape poly = (PolygonShape)cutPolygonList[i].Shape;
                        int vertexCount = poly.Vertices.Count;
                        //Debug.Assert(vertexCount <= Settings.MaxPolygonVertices);

                        for (int j = 0; j < vertexCount; ++j)
                        {
                            _tempVertices[i] = MathUtils.Multiply(ref transform, poly.Vertices[i]);
                        }

                        _debugView.DrawSolidPolygon(_tempVertices, vertexCount, Color.Black);
                    }
                    #endregion                    

                }
            }

 

Using a DrawShape also produces the same result.

 

Thanks in advance