Compound Collisions Newton4

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Compound Collisions Newton4

Postby MeltingPlastic » Tue Jan 18, 2022 9:55 am

What is the right way to traverse sub-Collisions in Newton4? I used to use the Node functions in 3.14:
NewtonCompoundCollisionGetFirstNode
NewtonCompoundCollisionGetNextNode

I use it to extract the collision shapes from existing compounds in order to combine them into new compounds.

Edit: I think I found it:

Code: Select all
rootCollision.GetShape()->GetAsShapeCompound()->GetTree()
MeltingPlastic
 
Posts: 237
Joined: Fri Feb 07, 2014 11:30 pm

Re: Compound Collisions Newton4

Postby Julio Jerez » Tue Jan 18, 2022 1:52 pm

from within a BeginAddRemove /EndAddRemove block you get the tree, and you iterate over the nodes.

Code: Select all
compound->BeginAddRemove();
const ndShapeCompound::ndTreeArray& shapes = compound->GetTree();
// iterate ove nodes,  do what you need to do
void EndAddRemove();


each node is of this kind

class ndShapeCompound::ndNodeBase

and there you get lot of info about how is organized. the member are public, they shouldn't probably be, but you cna just use ndShapeInstance* GetShape() const;

edit: I made it so that the internal data is private. please get later again.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Compound Collisions Newton4

Postby Julio Jerez » Tue Jan 18, 2022 4:25 pm

I see, there are fore prototype of that function, 3 are public and one private.

Code: Select all
   void SetMassMatrix(const ndVector& massMatrix);
   void SetMassMatrix(ndFloat32 mass, const ndShapeInstance& shapeInstance);
   void SetMassMatrix(ndFloat32 Ixx, ndFloat32 Iyy, ndFloat32 Izz, ndFloat32 mass);
   D_COLLISION_API virtual void SetMassMatrix(ndFloat32 mass, const ndMatrix& inertia);



I made the fourth public. but know that is you set the inertia that way, you are responsible for setting the center of mass.
It is ok to tweak the center of mass, in real life bodies are homogenies, but is you set it too far of the center of the shape, you get behavior that look weird but is what the physics yield.
In general, what I do is, using this

void SetMassMatrix(ndFloat32 mass, const ndShapeInstance& shapeInstance);
that give me a start point and them I read the value and tweak them.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Compound Collisions Newton4

Postby MeltingPlastic » Tue Jan 18, 2022 4:59 pm

Thanks, reviewing - newton expects the inertia matrices I give it to be the inertia matrices at the COM correct?

I know that there ALWAYS exists a diagonal inertia matrix with diagonals for ANY shape. But for some asymmetric shapes the diagonal matrix is not on the center of mass. For these cases, the intertia matrix on the COM is symmetric and newton needs a full symmetric matrix.

I think there need to be more tools for this. And it would be very cool if built into newton.

Like specifying the mass-density of subShapes. So all a user has to do is
1. create shapes with specified density
2. add the shapes to a compound
3. call the cool function that computes the best COM, and Inertia Matrix.

I have alot of code that does this from the last time we talked about this. But will probly be different as I try to get things working again..

EDIT: number 3 I know there is a function for. But not for different densities for subShapes. Thats why I wrote all the code to hack it by alter shape sizes.
MeltingPlastic
 
Posts: 237
Joined: Fri Feb 07, 2014 11:30 pm

Re: Compound Collisions Newton4

Postby Julio Jerez » Tue Jan 18, 2022 5:21 pm

But that kind of funtionality can easily by Implementing in the app side.

The shape that you use to set the inertia does not have to be the shape you set for the body.

Say you have a vehicle and you made with tow boxes in a compound.

Say Say one bix in the front an one in the back, and they are of equal size.

But you know that the vehicle weigh more in the front than in the back.

You can do two things.
1- since volume and mass are linearly related,
M = density * volume.
Increasing mass is the same as increasing the volume.
You can just scale one of the boxes by the same ratio, and you set the inertia with that.

A secund way would be to just add an extra shape as a counter weight.

Them after the inertia and the com is calculated you remove it.

There are so many ways to do that. That it is fertile to try to cover every thing, there will alway be some one who want a new method.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 49 guests