Physics Simulator View - questions

Dec 11, 2008 at 12:18 AM
Sorry if this has been covered before. (i searched discussion)

1.) Why isnt the PhysicsSimulatorView class and supporting classes in the core FarseerPhysics project? (its added in the advanced examples)

2.) I get a NULL reference error (in RectangleBrush i think) at runtime. In my project i have copied over and changed namespaces for the PhysicsSimulatorView.cs and DrawingSystem folder and files. I get no compile time warnings or errors.

In my game1 constructor i created a PhysicsSimulatorView object, then set EnableVertice/EdgeView to true and Vertice/EdgeColor to a new Color. Then in Draw() i call myPhysicsSimulatorView.Draw(spriteBatch).

I am not sure what I am missing. I cant post code right now, becuase I was trying it out on my work computer. (dont tell my boss :)

Thanks
Dec 11, 2008 at 1:40 AM
If it helps (for you to help me)

I have created a simple test. I have created a project with a 128x128 ball.png with a simple rectangle body and geom. Now I get a NULL ref error on _verticeCircleBrush.Draw(...) in PhysicsSimulatorView.cs. (this is similar situation as described before)


In my Game1 constructor i have this:

myPhysicsim =

new PhysicsSimulator(new Vector2(0, 0));
myPhysicsimView =
new PhysicsSimulatorView(myPhysicsim);

----------------------------

 

In LoadContent() i have this:

ballTexture = Content.Load<

Texture2D>("ball");
spriteBatch =
new SpriteBatch(GraphicsDevice);
ballBody =
BodyFactory.Instance.CreateRectangleBody(myPhysicsim, ballTexture.Width, ballTexture.Height, 100);
ballBody.Position =
new Vector2(200, 200);
ballGeom =
GeomFactory.Instance.CreateRectangleGeom(myPhysicsim, ballBody, ballTexture.Width, ballTexture.Height);

 

------------------
In Draw() i have this:

spriteBatch.Begin();
spriteBatch.Draw(ballTexture, ballBody.Position,

null, Color.White, 1.0f, new Vector2(0, 0), 1, SpriteEffects.None, 0.0f);
myPhysicsimView.Draw(spriteBatch);
spriteBatch.End();

 

That is all. I am guessing that I am taking a too simplistic approach to the SimulatorView usage. I have loaded the Advanced Samples project and it looks like you are using some other drawing and screen managers. I guess that there is more to using "View" than just including the neccessary files.

Please let me know if I need to study the provided source some more or if I am missing something. (maybe the manual should not include info about "View" if it is not part of the core engine,....not an insult or complaint! I appreciate your work)

Thanks

Dec 11, 2008 at 2:34 AM
Heh, dont mean to turn this discussion into my personal blog.

I see that in PhysicsSimulatorView.cs, the LoadContent function takes a Graphics device and Content manager arguments. I am confused on how to pass the content manager.

I also noticed that in LoadPerformancePanelContent() it is trying to load a specific font. That font and its directory are specific to the examples project. 

Thus I am concluding that the PhysicsSimulatorView is something that is custom to the examples. I will continue to try to get it to work, any advice is appreciated.

This whole thing started becuase when I was testing the Texture to Vert function, my ball geom would "sink" into my ground geom and then re-surface. Very weird. I think that issue was covered in a previous Discussion and in the known issues section of the manual. I will continue to look tomorrow.

Any advice welcome.

Thanks
Coordinator
Dec 11, 2008 at 7:04 AM
1. It's not part of the official release of Farseer Physics because it contains platform specific drawing code. It will only work on XNA while Farseer Physics works on all platforms.

2. That is because you are not calling LoadContent() on the PhysicsSimulatorView object.
2.a The Graphics device and ContentManager objects are both part of XNA. When you create a standard game, the 2 objects are created by default.

As for the samples, they are based on a sample structure from XNA creators club (If I remember correctly). It's great for simple games, you should look into it.
Dec 11, 2008 at 8:27 PM
Thanks AGAIN genbox. I added the LoadContent line. The problem wasnt with my content manager, but I was trying to pass the GraphicsDeviceManager instead of the GraphicsDevice.

It works perfectly.