Empty compound collision

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Empty compound collision

Postby PJani » Tue May 15, 2012 7:52 pm

Hey. I am building compound collision at runtime(via NewtonCompoundCollisionAddSubCollision) so at the start empty compound is assigned to the body but i get exception in ...newton300\source\physics\dgCollisionCompound.cpp at line 475. Is this normal behaveur? Cheers, PJ
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
User avatar
PJani
 
Posts: 448
Joined: Mon Feb 02, 2009 7:18 pm
Location: Slovenia

Re: Empty compound collision

Postby Julio Jerez » Wed May 16, 2012 8:31 am

no that is not normal, and it should not happens.
I looked at that line in the code and I do not see how it can crah there, it is a funtion that is not call by anything.

can you show the code you are using to do that?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Empty compound collision

Postby PJani » Wed May 16, 2012 7:48 pm

I just updated my local repo from svn and now i have trouble with functions which don't exist anymore. I don't know how this part is handled.

I am using my own modified version of ogrenewt wrapper for 300.

Code: Select all
Collision::Collision( const Collision& shape) : m_col(shape.m_col)
{
   m_world = shape.m_world;

   

   if (m_col) {
      NewtonAddCollisionReference (m_col); /// Identifier not found
   }
}

Collision::Collision(const NewtonCollision* collision, const World* world) : m_col((NewtonCollision*)collision)
{
   m_world = world;
   NewtonAddCollisionReference (m_col); /// Identifier not found
}

Collision::~Collision()
{
    if (m_world->getNewtonWorld() && m_col)
    {
        NewtonReleaseCollision( m_world->getNewtonWorld(), m_col ); /// Identifier not found
    }
}


void Collision::makeUnique()
{
    NewtonCollisionMakeUnique( m_world->getNewtonWorld(), m_col ); /// Identifier not found
}


One more what happend to NewtonSetWorldSize?
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
User avatar
PJani
 
Posts: 448
Joined: Mon Feb 02, 2009 7:18 pm
Location: Slovenia

Re: Empty compound collision

Postby Julio Jerez » Thu May 17, 2012 6:56 am

In Newton 300 ther si noi world budown anymore, you can simple comment put all call to NewtonSetWorldSize?
also all colilsion are instances, i think thsi woudl be teh code conversion
Code: Select all
Collision::Collision( const Collision& shape)
 :m_world(m_world)
 : m_col(shape.m_col ? NewtonCollisionCreateInstance(shape.m_col) : NULL)
{
//   m_world = shape.m_world;
//   if (m_col) {
//      NewtonAddCollisionReference (m_col); /// Identifier not found
//   }
}

Collision::Collision(const NewtonCollision* collision, const World* world)
  : m_world (world)
  , m_col(NewtonCollisionCreateInstance(m_col))
{
//   m_world = world;
//   NewtonAddCollisionReference (m_col); /// Identifier not found
}

Collision::~Collision()
{
   if (m_world->getNewtonWorld() && m_col)
   {
      // all collision are instances now
      //NewtonReleaseCollision( m_world->getNewtonWorld(), m_col ); /// Identifier not found
      NewtonDestroyCollision(m_col);
   }
}


void Collision::makeUnique()
{
   // all collision are instances now
   //NewtonCollisionMakeUnique( m_world->getNewtonWorld(), m_col ); /// Identifier not found
}
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Empty compound collision

Postby PJani » Thu May 17, 2012 9:58 am

Ok i updated so project compiles but it crashes...here are bare newton only calls in their sequence of calls...

Code: Select all
m_col = NewtonCreateCompoundCollision( world->getNewtonWorld(), id );

m_body = NewtonCreateBody( m_world->getNewtonWorld(), m_col, &posit[0][0] ); //here my app crashes



if i do the way bellow everything goes fine thru...but later added collisions to compound are not coliding
Code: Select all

m_col = NewtonCreateCompoundCollision( world->getNewtonWorld(), id );

NewtonCompoundCollisionBeginAddRemove (m_col);   
NewtonCompoundCollisionAddSubCollision(m_col, NewtonCreateNull( world->getNewtonWorld(), id);
NewtonCompoundCollisionEndAddRemove (m_col);

m_body = NewtonCreateBody( m_world->getNewtonWorld(), m_col, &posit[0][0] );

| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
User avatar
PJani
 
Posts: 448
Joined: Mon Feb 02, 2009 7:18 pm
Location: Slovenia

Re: Empty compound collision

Postby Julio Jerez » Thu May 17, 2012 10:47 am

[quote="PJani"]
Code: Select all
m_col = NewtonCreateCompoundCollision( world->getNewtonWorld(), id );
m_body = NewtonCreateBody( m_world->getNewtonWorld(), m_col, &posit[0][0] ); //here my app crashes


if i do the way bellow everything goes fine thru...but later added collisions to compound are not coliding
I do not see how that can crash, teh demos use that everywhere.


when you create a body, you pass a pointer to a collision instance.
the collision that is in the body is not the pointer to the object that you pass.
the engine make a new collision instance.

you cannot hold to a collision pointer an assume it is the pointer that it is in the body.
you need to get the pointer from the body.
The was an inconsistence in core 200 and lower, there were collision that were instances and collision that where shared assets. Not all collision are instances who use a shared asset.
you can build your compound and then make the body and then destroy that compound.
the to edit the compound you simple Get it from the Body. if you want make a collision class you can store the call pointer as user data in the collision.
This code would be wrong
Code: Select all
m_col = NewtonCreateCompoundCollision( world->getNewtonWorld(), id );
NewtonCompoundCollisionBeginAddRemove (m_col);   
NewtonCompoundCollisionAddSubCollision(m_col, NewtonCreateNull( world->getNewtonWorld(), id);
NewtonCompoundCollisionEndAddRemove (m_col);
m_body = NewtonCreateBody( m_world->getNewtonWorld(), m_col, &posit[0][0] );

this will be right
Code: Select all
NewtonCollision* const coll = NewtonCreateCompoundCollision( world->getNewtonWorld(), id );
NewtonCompoundCollisionBeginAddRemove (coll);   
NewtonCompoundCollisionAddSubCollision(coll, NewtonCreateNull( world->getNewtonWorld(), id);
NewtonCompoundCollisionEndAddRemove (coll);
m_body = NewtonCreateBody( m_world->getNewtonWorld(), coll, &posit[0][0] );
NewtonDestroyCollision(coll);
// now if you want to have a shortcut to teh collisionb you do this.
m_coll = NewtonBodyGetCollision(body);

also you do not have to add any collsion to teh compound you can jsut do this
Code: Select all
NewtonCollision* const coll = NewtonCreateCompoundCollision( world->getNewtonWorld(), id );
m_body = NewtonCreateBody( m_world->getNewtonWorld(), coll, &posit[0][0] );
NewtonDestroyCollision(coll);
// now if you want to have a shortcut to teh collisionb you do this.
m_coll = NewtonBodyGetCollision(body);

later you can edit the compoundt any time like this
Code: Select all
NewtonCompoundCollisionBeginAddRemove (m_coll);   
NewtonCompoundCollisionAddSubCollision(m_coll, anyConvexcollisionYouWant, id);
NewtonCompoundCollisionEndAddRemove (m_coll);
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Empty compound collision

Postby Julio Jerez » Thu May 17, 2012 10:52 am

here is a sample of making a simple compound from the SDK demos
Code: Select all
   //test Yeside compound shape shape
   NewtonCompoundCollisionBeginAddRemove(compound);   

   NewtonCollision* collision;
   dMatrix offsetMatrix (dPitchMatrix(1.5708f));
   offsetMatrix.m_posit.m_z = 0.115947f;
   collision = NewtonCreateCylinder (world, 0.021f, 0.096f, 0, &offsetMatrix[0][0]) ;
   NewtonCompoundCollisionAddSubCollision (compound, collision);
   NewtonDestroyCollision(collision);

   offsetMatrix.m_posit.m_z = 0.035182f;
   collision = NewtonCreateCylinder (world, 0.0065f, 0.07f, 0, &offsetMatrix[0][0]) ;
   NewtonCompoundCollisionAddSubCollision (compound, collision);
   NewtonDestroyCollision(collision);

   offsetMatrix.m_posit.m_z = 0.147914f;
   collision = NewtonCreateCylinder (world, 0.195f, 0.024f, 0, &offsetMatrix[0][0]) ;
   NewtonCompoundCollisionAddSubCollision (compound, collision);
   NewtonDestroyCollision(collision);

   NewtonCompoundCollisionEndAddRemove(compound);   
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Empty compound collision

Postby PJani » Thu May 17, 2012 2:13 pm

Yes i am re implementing collisions but did you try to create empty compound without adding any collisions to it? And assiging it to body?

One more question... Are compound indexes continues allways and are node void* allways the same for compound nodes even after adding or removing of nodes?
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
User avatar
PJani
 
Posts: 448
Joined: Mon Feb 02, 2009 7:18 pm
Location: Slovenia

Re: Empty compound collision

Postby Julio Jerez » Thu May 17, 2012 2:58 pm

Upps my mistake, this is a legacy from core 200.
Oh you are right, I just tried that and I see that many function expect the root to never by NULL.
but on initilaization if not shape is added before is assigned to a body, the root is still NULL.

as a work around you can add a NULL shape. and I will fit it tonight.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Empty compound collision

Postby Julio Jerez » Thu May 17, 2012 3:03 pm

PJani wrote:One more question... Are compound indexes continues allways and are node void* allways the same for compound nodes even after adding or removing of nodes?


the id of the shape is permanent, Shapesget enumerated with an ordinal value as they are added to the root.
if you look at the class, you can see that the container is a red black tree tha uses an integate as key.

dgTree<dgNodeBase*, dgInt32> m_array;

you can read the subshape nodes as a vector.

and not the node is not a poiner to the shape you need to use this function to get the shape
NewtonCollision* NewtonCompoundCollisionGetCollisionFromNode (NewtonCollision* const compoundCollision, void* const node);
you can look at the node as a handle. that never changes memory locations. this is a tecnique I use a lot.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Empty compound collision

Postby PJani » Thu May 17, 2012 3:25 pm

Julio Jerez wrote:you can look at the node as a handle. that never changes memory locations. this is a tecnique I use a lot.


Great! that is the thing was looking for so i can use node as handle directly :)
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
User avatar
PJani
 
Posts: 448
Joined: Mon Feb 02, 2009 7:18 pm
Location: Slovenia

Re: Empty compound collision

Postby Julio Jerez » Fri May 18, 2012 6:57 am

ok I fixed that bug.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Empty compound collision

Postby PJani » Fri May 18, 2012 8:06 pm

Thank you!

Now i have another problem...I have two bodies each with compound collision and they have one box as sub collision. But they should collide with each other but they just pass thru eachother. One body have mass of 0.

Any idea?...inertias are calculated as they should be(checked by hand)
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
User avatar
PJani
 
Posts: 448
Joined: Mon Feb 02, 2009 7:18 pm
Location: Slovenia

Re: Empty compound collision

Postby Julio Jerez » Sat May 19, 2012 7:28 am

I assume your bodies have inertia zero since the whe created when the shapes was empty, you need to reaassign again after shape modifications
The volume of inetia of the shape are updated afte you add or remove a shape, but the inertia of the body is not.
you need to call NewtonConvexCollisionCalculateInertialMatrix (collision, &inertia[0], &origin[0]);
after you do the any modification and set teh inerta on the body.

like I said before the volume of inerta is not teh same as teh moment of inertia, tow shape can hav eteh same vo,ume of inerta and different moment of inerta.
volme of inerta as well a area of inerta is a consta property of a shape. and it is teh part that is compel top calculate.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Empty compound collision

Postby PJani » Sat May 19, 2012 5:18 pm

Every time after i call NewtonCompoundCollisionEndAddRemove(...) i recalculate moment of inertia(via NewtonConvexCollisionCalculateInertialMatrix) and correct the inertial matrix and center of mass of the body.

Here is the effect of what happens. The stationary compound with box has mass 0.
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
User avatar
PJani
 
Posts: 448
Joined: Mon Feb 02, 2009 7:18 pm
Location: Slovenia

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests