My bodies acts like a slope!

I still don't know what I'm doing wrong... The body stays at angle = 0.5 radians from the create time till the impact time! I'm using Box2D XNA.

This is my code of initializing the world...

Code: Select all

Gravity = new Vector2(0, -10);
PhysicsWorld = new World(Gravity, true);


And here is the object creator void:

Code: Select all


        public void AddRectShape(float X1, float Y1, float W, float H)
        {
            BodyDef bf = new BodyDef();
            PolygonShape P = new PolygonShape();

            // Testing stuff: keep the first one stay right and rotate the another.
            if (BodiesCount == 0) bf.type = BodyType.Kinematic; else { bf.type = BodyType.Dynamic; bf.angle = 0.5f; }

            bf.position = new Vector2(X1, Y1);           
            P.SetAsBox(W, H);           

            FixtureDef fx = new FixtureDef();
            fx.density = 0.0f;
            fx.shape = P;
            fx.restitution = 0.5f;

            Body b = PhysicsWorld.CreateBody(bf);
            b.CreateFixture(fx);
            BodiesCount++;
        }   

Because I need to create them dynamically in runtime with unknown quantity. And the result looks like this: https://www.dropbox.com/s/due3u98gd83gxwp/sol.JPG
What am I wrong?
Dynamic bodies should have a non-zero density.
OK... Even I change the line from

Code: Select all

fx.density = 0.0f;

to

Code: Select all

fx.density = 1.0f;

the object still acts same.
In fact I was changed density from 1.0f to 0.0f before, and problem still remains there. So I changed my concern to detect other problems, and forgot to revert this.
Ok ok,
I figured out the problem. My coordinate translator has a bug in it so the Width and Height parameters passed to CreateRect is negative.
Anyway, thank you for replying!

Original thread: https://box2d.org/forum/viewtopic.php?t=9559