behdad / box2d

Automatically exported from code.google.com/p/box2d
2 stars 12 forks source link

b2Body.SetMass function missing #90

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm using AS3 Flash 9 box2d 2.1a version.

I tried using this code:

var massData:b2MassData = new b2MassData();
b3.GetMassData(massData);
massData.mass = myNewMass;
b3.SetMassData(massData);

Then my bodies start acting very weird. For some shapes in body collision 
work normally, but mostly those bodies start jumping like with restitution 
set to 10.

Later I created this function in b2Body:

public function SetMass(mass:Number):void
{
   m_mass = mass;
   m_invMass = 1.0 / mass;
}

Now everything looks fine using b3.SetMass(myNewMass)

Forum post http://www.box2d.org/forum/viewtopic.php?f=8&t=4518

Original issue reported on code.google.com by evaldas...@gmail.com on 27 Feb 2010 at 9:11

GoogleCodeExporter commented 9 years ago
Please post flash issues here: http://sourceforge.net/projects/box2dflash/

Original comment by erinca...@gmail.com on 28 Feb 2010 at 6:32

GoogleCodeExporter commented 9 years ago
No, this is really an issue with the C++.

Try the following in the CharacterCollision TestBed.

// Square character
        {
            b2BodyDef bd;
            bd.position.Set(-3.0f, 5.0f);
            bd.type = b2_dynamicBody;
            bd.allowSleep = false;

            b2Body* body = m_world->CreateBody(&bd);

            b2PolygonShape shape;
            shape.SetAsBox(0.5f, 0.5f, b2Vec2(0.5f, 0.5f), 0.0f);

            b2FixtureDef fd;
            fd.shape = &shape;
            fd.density = 20.0f;
            body->CreateFixture(&fd);
            body->ResetMassData();

            b2MassData md;
            body->GetMassData(&md);
            body->SetMassData(&md);
        }

Problem disappears if you remove the 3 lines at the end. The problem is that 
there is
a conversion from I about origin to I about center, contrary to what the
documentation says. I'd recommend making two mass data types, with conversions
between them, for each way of storing I - let the type system do the work of 
ensuring
I is consistent.

Original comment by sadwanm...@gmail.com on 28 Feb 2010 at 10:19

GoogleCodeExporter commented 9 years ago

Original comment by erinca...@gmail.com on 4 Mar 2010 at 6:02

GoogleCodeExporter commented 9 years ago
Fixed. b2MassData.I is always about the local origin. b2BodyGetInertia returns 
I about 
the local origin. The only place I is stored about the center is in the body.

Original comment by erinca...@gmail.com on 8 Mar 2010 at 1:15