Box2D Forums

It is currently Sat May 25, 2013 4:17 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: SetMassData problem
PostPosted: Sat Jun 11, 2011 1:45 am 
Offline

Joined: Mon May 23, 2011 9:41 am
Posts: 18
Hi,
I need to set the mass of a specific BodyShape. I tried to do so using the b2body.SetMassData:
Code:
   
var MassData:b2MassData = new b2MassData();
var b2Vec:b2Vec2 = new b2Vec2(0);
b2Vec.v2 = new V2(0, 0);
MassData.center = b2Vec;
MassData.mass = mass;
MassData.I = 0;
b2body.SetMassData(MassData);

After I set the mass, the body starts acting like SetFixedRotation=true.
How can I solve this?


Top
 Profile  
 
 Post subject: Re: SetMassData problem
PostPosted: Sat Jun 11, 2011 2:26 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1518
Location: Tokyo
Yes, setting the rotational inertia value I to zero will cause that.

What I would do is first set all the fixtures in the body as normal, to let the engine calculate what the mass and inertia should be with say, a density of 1.
Using GetMassData you can get the values that were set. You might find for example that the body has a mass of 2.5.
Calculate the factor that the mass needs to be multiplied by to become the mass you want. So if you want a mass of 10, that would be a factor of 4.
Do that for both the mass and inertia, then set it back in the body with SetMassData.


Top
 Profile  
 
 Post subject: Re: SetMassData problem
PostPosted: Sat Jun 11, 2011 3:27 am 
Offline

Joined: Mon May 23, 2011 9:41 am
Posts: 18
Thanks a lot! :D


Top
 Profile  
 
 Post subject: Re: SetMassData problem
PostPosted: Sat Jun 11, 2011 5:16 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1518
Location: Tokyo
irresistible force wrote:
Yes, setting the rotational inertia value I to zero will cause that.

What I would do is first set all the fixtures in the body as normal, to let the engine calculate what the mass and inertia should be with say, a density of 1.
Using GetMassData you can get the values that were set. You might find for example that the body has a mass of 2.5.
Calculate the factor that the mass needs to be multiplied by to become the mass you want. So if you want a mass of 10, that would be a factor of 4.
Multiply both the mass and inertia by that factor, then set them back in the body with SetMassData.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group