createPolygon

Topics: Developer Forum, User Forum
Mar 1, 2011 at 6:43 PM
Edited Mar 1, 2011 at 6:49 PM

Hi, I can't create a simple Fexture from Vertices, what I've done bad ? :(

A message box show me an assert error with FixtureFactory.CreatePolygon

 

            #region createSquare

            Vertices vertices = new Vertices();
            vertices.Add(ConvertUnits.ToSimUnits(new Vector2(0, 0)));
            vertices.Add(ConvertUnits.ToSimUnits(new Vector2(0, 100)));
            vertices.Add(ConvertUnits.ToSimUnits(new Vector2(100, 100)));
            vertices.Add(ConvertUnits.ToSimUnits(new Vector2(100, 0)));
            rectangle = FixtureFactory.CreatePolygon(
                world,
                vertices,
                1f,
                Vector2.Zero);
            rectangle.Body.BodyType = BodyType.Static;

            #endregion
Thanks for helping me =)
Mar 1, 2011 at 7:31 PM

First off, you can use CreateRectangle instead of CreatePolygon for your vertices.

Secondly, which Debug.Assert are you having trouble with?

Mar 1, 2011 at 7:52 PM
Edited Mar 1, 2011 at 8:05 PM

I did a rectangle to have an easy sample =)

for the assert error : "at PolygonShape.Set(Vertices vertices)

:s

edit : The error seems to disappear with a BayazitDecomposer, but World.TestPoint don't work :/

Mar 2, 2011 at 9:43 AM

I suggest you do something like this->

 

Vertices vertices = new Vertices();
            vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-50, -50)));
            vertices.Add(ConvertUnits.ToSimUnits(new Vector2(50, -50)));
            vertices.Add(ConvertUnits.ToSimUnits(new Vector2(50, 50)));
            vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-50, 50)));

 

Like this it is centered around the center.

Mar 2, 2011 at 9:46 AM

A Polygon only has 3 vectors. Could be wrong though. Try using a LoopShape instead.

Mar 2, 2011 at 3:08 PM

It works with centering around the center ! :D but now I would like to do the same with vertices from Texture2D.GetData(), and I have many problems with it :'(