SetMassMatrix()

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

SetMassMatrix()

Postby zak » Wed Mar 31, 2021 1:04 pm

When I initialize a body, if i write:

pBody->SetCollisionShape( new ndShapeSphere( radius ) );
pBody->SetMassMatrix( Ixx, Iyy, Izz, mass );

it is ok, but if i write:

pBody->SetMassMatrix( Ixx, Iyy, Izz, mass );
pBody->SetCollisionShape( new ndShapeSphere( radius ) );

then SetMassMatrix() doesn't work.
It works only if a nsShapeInstance is already setted with pBody->SetCollisionShape() before it is called.
zak
 
Posts: 87
Joined: Mon Dec 06, 2004 9:30 am

Re: SetMassMatrix()

Postby Julio Jerez » Wed Mar 31, 2021 1:32 pm

pBody->SetCollisionShape( new ndShapeSphere( radius ) );
pBody->SetMassMatrix( Ixx, Iyy, Izz, mass );

should be independent of each other. you should be able to call the in any order.
In general pBody->SetMassMatrix( Ixx, Iyy, Izz, mass ); is use when you knwo or you wnat to change of tweak the mass matric of a body after is set by function .
void SetMassMatrix(dFloat32 mass, const ndShapeInstance& shapeInstance);

an example of the is say you have a vehicle like an air plane, the body is usually a complex but you can a get the inerta from some table.
another example is the tire of a car, is you use the tires for teh inertia you get a skew values, but we all knwo that tire are designed that the inertia is very close to spherical to minimize the effect of gyro torques whi come be quite strong of sport cars. so you use
void SetMassMatrix(dFloat32 mass, const ndShapeInstance& shapeInstance);

teh you reset it by calling
In general pBody->SetMassMatrix( Ixx, Iyy, Izz, mass ); is use when you knwo or you wnat to change of

where Ixx, Iyy, Izz are set to teh max frim
dVector pBody->GetMassMatrix( ).

I am not sure why you see it as a bug.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: SetMassMatrix()

Postby Julio Jerez » Wed Mar 31, 2021 1:49 pm

zak wrote:pBody->SetMassMatrix( Ixx, Iyy, Izz, mass );
pBody->SetCollisionShape( new ndShapeSphere( radius ) );

then SetMassMatrix() doesn't work.
It works only if a nsShapeInstance is already setted with pBody->SetCollisionShape() before it is called.


I think I see what you mean there.
if you loo at the source code of

Code: Select all
void ndBodyKinematic::SetMassMatrix(dFloat32 mass, const dMatrix& inertia)
{
   mass = dAbs(mass);

   ndShape* const shape = m_shapeInstance.GetShape();
   if ((mass < D_MINIMUM_MASS) || shape->GetAsShapeNull() || !shape->GetAsShapeConvex())
   {
      mass = D_INFINITE_MASS * 2.0f;
   }


if you call to set the mass of a body and the body was just created, teh body will have a defaul shape with is the a null shape. so setting the mass of a body wi the a null shape will has no effect sine bodies with null shape or a static are static bodes

my suggestion is to do it the the reverse order, set teh shape them the mass matrix.

Code: Select all
pBody->SetCollisionShape( new ndShapeSphere(  radius ) );
pBody->SetMassMatrix( Ixx, Iyy, Izz, mass );


or better yet
Code: Select all
pBody->SetCollisionShape( new ndShapeSphere(  radius ) );
pBody->SetMassMatrix(mass,  pBody->GetCollisionShape());


also notice that
pBody->SetCollisionShape( new ndShapeSphere( radius ) )

is not possible since teh funtion is proto is,
void ndBodyKinematic::SetCollisionShape(const ndShapeInstance& shapeInstance);

you can not assign a shapes to a body, you can only assign an instance of a shape.
new ndShapeSphere( radius )
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: SetMassMatrix()

Postby zak » Wed Mar 31, 2021 1:53 pm

Julio Jerez wrote:I am not sure why you see it as a bug


in my body initialization code i had:

CMyBody::CMyBody( ..., mass, vettInertia, ... )
{
(...)
pBody->SetMassMatrix( vettInertia.x, vettInertia.y, vettInertia.z, mass );
pBody->SetCollisionShape( new ndShapeSphere( radius ) );
pWorld->Add(pBody);
}

But SetMassMatrix() doesn't work. Ad example if i pass a mass of 1.0f, i obtain a pBody having a mass very high e zero inverse mass.
It took me an hour to understand that I had to write
pBody->SetCollisionShape() before pBody->SetMassMatrix()
zak
 
Posts: 87
Joined: Mon Dec 06, 2004 9:30 am

Re: SetMassMatrix()

Postby zak » Wed Mar 31, 2021 2:02 pm

Ah, ok. This explain all.
zak
 
Posts: 87
Joined: Mon Dec 06, 2004 9:30 am


Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 4 guests

cron