Noob problems. Need input :( (FPE 3.0 + Silverlight)

Topics: Developer Forum, User Forum
Sep 28, 2010 at 5:48 PM

Video of my problem : http://www.youtube.com/watch?v=cUY12KEgOwY

- Using FPE 3.0

- Using Silverlight for Windows Phone 7.

- NOT using the "Physics Helper" for Silverlight

- I'm creating my rectangle shapes like this: 

 

            PolygonShape rectangleShape = new PolygonShape();

            float halfWidth = (float)(((this.AssociatedObject.Width) / PIXELS_TO_METERS_RATIO) / 2.0f);
            float halfHeight = (float)(((this.AssociatedObject.Height) / PIXELS_TO_METERS_RATIO) / 2.0f);

            rectangleShape.SetAsBox(halfWidth, halfHeight);

            Fixture rectangleFixture = body.CreateFixture(rectangleShape, 1.0f);

 

- I'm updating the rectangles on each step like this:

 

            CompositeTransform pixelTransform = new CompositeTransform();

            pixelTransform.Rotation = MathHelper.ToDegrees(body.Rotation);
            pixelTransform.TranslateX = body.Position.X * PIXELS_TO_METERS_RATIO;
            pixelTransform.TranslateY = body.Position.Y * PIXELS_TO_METERS_RATIO;
            this.AssociatedObject.SetValue(Rectangle.RenderTransformProperty, pixelTransform);

Any idea what could be causing this?

 

Sep 29, 2010 at 1:38 PM

I think you are drawing the corner of your objects at the body position.  You need to offset the position for the center of your object.

I.e., I had a drawing method that looked something like:

            this.rotationTransf.Angle = this.GameObject.Rotation;
            this.translTransf.X = this.GameObject.Position.X - this.center.X;
            this.translTransf.Y = this.GameObject.Position.Y - this.center.Y;

The center was just a Point relative to the top left of the graphic.

Oct 5, 2010 at 2:33 PM

This kind of makes sense but i'm having other noob problems which I don't understand.

ex: box2d says we should have a negative gravity (b2Vec2 gravity(0.0f, -10.0f)) which makes sense but whenever I set a negative gravity, my objects fall towards the sky and I don't know why. I'm about to have a panic attack trying to find the common ground between FPE, Box2d, Silverlight and Windows Phone 7.

 

Oct 5, 2010 at 3:39 PM
Edited Oct 5, 2010 at 3:54 PM

Then just use a positive value for gravity? Something to do with the example setting up their coordinate system differently to match physics textbooks. Makes more sense (to me) to leave -Y as up and Y+ as down to keep things familiar. (see http://farseerphysics.codeplex.com/Thread/View.aspx?ThreadId=11878)

As an alternative to what ben33333 mentioned.... you can just pass in an Origin parameter into your spritebatch.draw function and it will offset the drawing for you(See http://msdn.microsoft.com/en-us/library/bb203919(XNAGameStudio.30).aspx )