0

I tried the "Texture to polygon" example in the Farseer documentation. https://farseerphysics.codeplex.com/documentation But I always get this error message in the following line:

//Find the vertices that makes up the outline of the shape in the texture
Vertices  verts = PolygonTools.CreatePolygon(data, polygonTexture.Width, polygonTexture.Height, true);

No overload for method 'CreatePolygon' takes 4 arguments    

Is there a mistake in the Farseer documentation or what is wrong? What should I change in this line?

In addition, I get these two error messages in the following lines:

_list = BayazitDecomposer.ConvexPartition(verts);
List<Fixture> compund = FixtureFactory.CreateCompoundPolygon(World, _list, 1);

The name 'BayazitDecomposer' does not exist in the current context  
'FarseerPhysics.Factories.FixtureFactory' does not contain a definition for 'CreateCompoundPolygon' 

What is wrong?

I have the following three usings in my code:

using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories;
using FarseerPhysics.Common;

Should I add another using?

Leo
  • 267
  • 1
  • 4
  • 14
  • Your last two errors indicate some lack of reference to the necessary files. – tnw May 20 '13 at 15:21
  • Do you have the right `using FarseerPhysics` libraries included at the top? – jszigeti May 20 '13 at 15:35
  • I don't know if there is missing a using. For the moment, I use three usings. Should I add another using? – Leo May 20 '13 at 16:04
  • Try `FarseerPhysics.Common.Decomposition` for the Bayazit problem. I am curious, are these methods underlined in red before you compile, and if so, don't they provide some clue as to what library they think they're being called from? What happens when you right+click "Go To Definition" on them? – jszigeti May 20 '13 at 16:38
  • I get another error message when I do right+click "Go To Definition" on CreateCompoundPolygon: Cannot navigate to 'CreateCompoundPolygon' I don't know how to solve this problem? – Leo May 20 '13 at 16:59
  • That basically confirms in my mind that the libraries you need have not been included. It doesn't know how to reference the method. – jszigeti May 20 '13 at 17:14

2 Answers2

3

I think all of your problems can be summed up by not including the right libraries. I will admit, the FarseerPhysics documentation you linked was not very helpful. You can see in their own source code, for example, that BayazitDecomposer is part of the FarseerPhysics.Common.Decomposition namespace, therefore you'd reference it by saying either

using FarseerPhysics.Common.Decomposition;

at the top, or just using FarseerPhysics.Common; and in your code:

Decomposition.BayazitDecomposer() //etc.

I'd recommend looking at other developers' sample code, or diving further into FarseerPhysics' source, in order to see what other libraries you're lacking.

I notice also in your CreatePolygon case that the method, according to the BodyFactory definition I'm looking at, doesn't even return the Vertices type you believe it does. So in that instance, not only are you possibly missing the library you need, but when you include it, it will say the return type is wrong.

Perhaps the commenter who suggested that the sample code you're using is based on an older version of Farseer is correct, given these issues.

jszigeti
  • 373
  • 4
  • 11
1

when you download the file Farseer Physics Engine 3.3.1 Samples XNA! Advanced Demo 1 has a example of "Texture to polygon"

The documentation of the page this outdated.

user2547522
  • 110
  • 1
  • 16