Empty compound collision

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Empty compound collision

Postby Julio Jerez » Sat May 19, 2012 6:14 pm

render the debug to see if the shape are where the video shows.
do this test, make the collision before adding to the body and see if that words.

if it works then there most be a problem where the instace is not right.
The compound is empty when it is created, then it make a copy when you asign it to teh body, if anythong it will be adding a made compund that will have more problems.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Empty compound collision

Postby PJani » Sun May 20, 2012 10:05 am

My raycast menu for actions on the right says the collisions are at right positions(i looked with camera at edges of my boxes...)

I tried with [code bellow] after the NewtonCompoundCollisionEndAddRemove but this didn't solve the problem.
Code: Select all
NewtonBodySetCollision(m_body->getNewtonBody(), NewtonBodyGetCollision(m_body->getNewtonBody()));



Now i added [code bellow] after the NewtonCompoundCollisionEndAddRemove and now collisions are working right.
Code: Select all
NewtonBodySetCollision(m_body->getNewtonBody(), NewtonCollisionCreateInstance(NewtonBodyGetCollision(m_body->getNewtonBody())));


CORRECTION: it doesnt work right...its same.
Last edited by PJani on Sun May 20, 2012 12:17 pm, edited 1 time in total.
| 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 » Sun May 20, 2012 12:12 pm

Code: Select all
NewtonBodySetCollision(m_body->getNewtonBody(), NewtonBodyGetCollision(m_body->getNewtonBody()));

maybe there is a bug here, and the function is not making a copy of the instance, I will find out.

this
Code: Select all
 NewtonBodySetCollision(m_body->getNewtonBody(), NewtonCollisionCreateInstance(NewtonBodyGetCollision(m_body->getNewtonBody())));

will definitlly work, because you are making an explicit copy of a the collision shape.
the new rule in core 300, is that instances are always unique pointers, therefore NewtonBodySetCollision should make a copy of the colilsion that is passed in

the correct sulution shoudl be that.
Code: Select all
NewtonBodySetCollision(m_body->getNewtonBody(), NewtonBodyGetCollision(m_body->getNewtonBody()));
NewtonBodySetCollision(m_body->getNewtonBody(), NewtonCollisionCreateInstance(NewtonBodyGetCollision(m_body->getNewtonBody())));

both work, but that the first call should be more efficient since only one copy is made.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Empty compound collision

Postby PJani » Sun May 20, 2012 12:20 pm

Julio Jerez wrote:
Code: Select all
NewtonBodySetCollision(m_body->getNewtonBody(), NewtonBodyGetCollision(m_body->getNewtonBody()));

maybe there is a bug here, and the function is not making a copy of the instance, I will find out.

this
Code: Select all
 NewtonBodySetCollision(m_body->getNewtonBody(), NewtonCollisionCreateInstance(NewtonBodyGetCollision(m_body->getNewtonBody())));

will definitlly work, because you are making an explicit copy of a the collision shape.
the new rule in core 300, is that instances are always unique pointers, therefore NewtonBodySetCollision should make a copy of the colilsion that is passed in

the correct sulution shoudl be that.
Code: Select all
NewtonBodySetCollision(m_body->getNewtonBody(), NewtonBodyGetCollision(m_body->getNewtonBody()));
NewtonBodySetCollision(m_body->getNewtonBody(), NewtonCollisionCreateInstance(NewtonBodyGetCollision(m_body->getNewtonBody())));

both work, but that the first call should be more efficient since only one copy is made.


Sory for late response i made another discovery that the ether doesn't work right still same problem happends.
| 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 » Sun May 20, 2012 12:28 pm

I check it out, and I can not undertand how that is failing the funtion is in fact correct

thi sis teh function
Code: Select all
void NewtonBodySetCollision(const NewtonBody* const bodyPtr, const NewtonCollision* const collisionPtr)
{
   TRACE_FUNCTION(__FUNCTION__);
   dgBody* const body = (dgBody *)bodyPtr;
   dgCollisionInstance* const collision = (dgCollisionInstance*) collisionPtr;
   body->AttachCollision (collision);
}



and it call this function on the body
Code: Select all
void dgBody::AttachCollision (dgCollisionInstance* const collisionSrc)
{
// here is where the new instance is made, (all shapes, even compound)
   dgCollisionInstance* const instance = new (m_world->GetAllocator()) dgCollisionInstance (*collisionSrc);
   if (m_collision) {
      m_collision->Release();
   }
   m_collision = instance;

   if (m_collision->IsType(dgCollision::dgCollisionMesh_RTTI) || m_collision->IsType(dgCollision::dgCollisionScene_RTTI)) {
      SetMassMatrix (m_mass.m_w, m_mass.m_x, m_mass.m_y, m_mass.m_z);
   }
}


the function AttachCollision is use every time an shape is assigned to a body, and as you can see the first thing is does is that it make a copy of the source instance.
you have to have a bug that is missing pointers. a body can never have a shared instance shape.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Empty compound collision

Postby PJani » Sun May 20, 2012 12:39 pm

This is my "body " handler code is very dirty because i am chaning it all the time:
Code: Select all
   Body::Body( BodyManager* bodymanager, BodyListener* listener, const Ogre::Vector3& pos, const Ogre::Quaternion& q )
      : m_bodymanager(bodymanager)
      , m_listener(listener)
      , m_force(Ogre::Vector3::ZERO)
      , m_torque(Ogre::Vector3::ZERO)
      , m_userdata(NULL)
      , m_begin_build(false)
      , m_mass(0)
   {
      NewtonWorld* world = m_bodymanager->getOgreNewtWorld();
      NewtonCollision* col = NewtonCreateCompoundCollision(world, 0);
      m_body = new OgreNewt::Body(w, col);
      NewtonDestroyCollision(col);
      
      Ogre::Real mass;
      Ogre::Vector3 inertia;
      m_body->getMassMatrix(mass, inertia);

      std::cout  << this << " " << mass << " " << inertia << std::endl;

      m_body->setPositionOrientation(pos, q);
      m_body->setUserData(this);
      m_body->setCustomForceAndTorqueCallback<Body>(&Body::forceCallBack, this);
      m_body->setUpdateHandler(boost::bind(&Body::updateCallback, this, _1, _2, _3));

      m_listener->onBodyCreated(this);
   }

   void Body::begin()
   {
      
      m_begin_build = true;

      m_added_ids.clear();
      m_removed_ids.clear();

      NewtonCollision* col = NewtonBodyGetCollision(m_body->getNewtonBody());

      NewtonCompoundCollisionBeginAddRemove(col);

   }

   void Body::end()
   {

      using namespace OgreNewt;
      NewtonCollision* col = NewtonBodyGetCollision(m_body->getNewtonBody());

      
      NewtonCompoundCollisionEndAddRemove(col);
      

      m_begin_build = false;

      if(m_collisions.size())
      {
         m_volume = NewtonConvexCollisionCalculateVolume(col);
         NewtonConvexCollisionCalculateInertialMatrix(col, &m_inertia.x, &m_center_of_mass.x);

         std::cout << "Volume/Inertia/COM" << std::endl;
         std::cout << m_volume << "/" << m_inertia << "/" << m_center_of_mass << std::endl;

         //m_body->setCenterOfMass(m_center_of_mass);
         //m_body->setMassMatrix(m_mass, m_mass * m_inertia);
         NewtonBodySetCentreOfMass(m_body->getNewtonBody(), &m_center_of_mass.x);
         NewtonBodySetMassMatrix(m_body->getNewtonBody(), m_mass, m_inertia.x * m_mass, m_inertia.y * m_mass, m_inertia.z * m_mass);
      }
      else
      {
         m_mass = 0;
         m_center_of_mass = Ogre::Vector3::ZERO;
         m_inertia = Ogre::Vector3::ZERO;
         m_volume = 0;

         m_body->setCenterOfMass(Ogre::Vector3::ZERO);
         m_body->setMassMatrix(0, m_inertia);
      }


      Ogre::Real mass;
      Ogre::Vector3 inertia;
      m_body->getMassMatrix(mass, inertia);

      std::cout << this << " " << mass << " " << inertia << std::endl;

      NewtonBodySetCollision(m_body->getNewtonBody(), NewtonCollisionCreateInstance(col));

      m_listener->onBodyRebuild(this);
   }

   void Body::createBoxCollision(long ID, float mass, const Ogre::Vector3& box, int collision_id, const Ogre::Vector3& pos, const Ogre::Quaternion& orient, NewtonCollision* cols)
   {
      if(!m_begin_build)
         return;

      CollisionInfoMap::iterator it = m_collisions.find(ID);
      if(it != m_collisions.end())
      {
         return;
      }

      using namespace OgreNewt;
      NewtonCollision* col = NewtonBodyGetCollision(m_body->getNewtonBody());
      //CollisionPrimitives::ConvexHull* col = new CollisionPrimitives::ConvexHull(m_body->getWorld(), cloud, vertex_count, collision_id, orientation, position);
        float matrix[16];
        OgreNewt::Converters::QuatPosToMatrix( orient, pos, &matrix[0] );

        //make the collision primitive.
        NewtonCollision* sub_col = NewtonCreateBox( m_body->getWorld()->getNewtonWorld(), box.x, box.y, box.z, collision_id, &matrix[0]);
      
      CollisionInfo ci;
      ci.mass = mass;
      ci.volume = NewtonConvexCollisionCalculateVolume(sub_col);
      ci.handle = NewtonCompoundCollisionAddSubCollision(col, sub_col);

      NewtonDestroyCollision(sub_col);


      m_collisions[ID] = ci;

      m_added_ids.insert(ID);

      m_mass += mass;
   }
| 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 » Sun May 20, 2012 1:48 pm

will it be ok if I make a CNewton class similar to the joint library.

The problem wit this is that each time I try to do stuff like that it actuall create more confusion.
but maybe for people using C++ and class will simply things.

I frankly prefer C interface on anything that is low level, In my opinion C interfaces are cleaner and can interact with more language than C++ interfaces, but apparently I am alone here.
basically this will have: CNewton, CNewtonBody, CMaterial, and CNewtonCollision
and will handle all the house keeping graciouslly
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Empty compound collision

Postby PJani » Sun May 20, 2012 1:52 pm

That would be very cool :), yeah games are very hard to maintain in pure C.

Anyway with C you are just hiding the C++ code nothing else and adding extra layer.

PS: Now i tryed with ConvexHull instead of Box, but them same problem persists.
| 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 PJani » Sun May 20, 2012 4:15 pm

I tryed with multiple collisions in the compound but is the same...
| 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 » Sun May 20, 2012 4:43 pm

can you try to serialize the scene unisng the binary serialization, it si very eassy you just call
void NewtonSerializeToFile (const NewtonWorld* const newtonWorld, const char* const filename)
from any where.

the you can try loading thet output in the sandbox demos, by going File->Import Serilalize scene
see if that works.

also if you build the engine in debug mode, do you get any assert or anything?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Empty compound collision

Postby PJani » Sun May 20, 2012 5:57 pm

When i try to import serialization i get a crash...

now i compiled the engine in debug and when i start i get this two assetions(I ignore the first so i get the second assertion)
Image
first is
Code: Select all
void dgBody::UpdateCollisionMatrixSimd (dgFloat32 timestep, dgInt32 threadIndex)
{
   _ASSERTE (0);


Image

O and btw your avatar image doesnt show up in opera because you use back slashes in path... "./images/ranks/images\avatars\newtonstrip.jpg" :)
| 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 » Sun May 20, 2012 6:53 pm

Code: Select all
void dgBody::UpdateCollisionMatrixSimd (dgFloat32 timestep, dgInt32 threadIndex)
{
   _ASSERTE (0);


I have not writen the SSE code, hwo did it get to that line? was that in the sandBox?
can you send me the serialized binary?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Empty compound collision

Postby PJani » Sun May 20, 2012 7:04 pm

Actualy i don't know how i got to that line! I builded your engine with debugDll mode.

no its not sandbox its in my project.

here is my serialization...
Attachments
debug_world.zip
Binary
(512 Bytes) Downloaded 146 times
| 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 » Sun May 20, 2012 7:33 pm

I just loaded and I have to do something because the loaded code in teh demo expect a gamera to be in teh code, I hack it liek this

Code: Select all
void DemoEntityManager::DeserializedPhysicScene (const char* const name)
{
   // add the sky
   CreateSkyBox();

   FILE* const file = fopen (name, "rb");

   // read the application data use to initialize the engine and other application related stuff.
   // reading the camera orientation
   dMatrix camMatrix(GetIdentityMatrix());

// cemnet this out so that I can load the mesh
//   DeserializeFile (file, &camMatrix, sizeof (camMatrix));
//   SetCameraMatrix(dQuaternion (camMatrix), camMatrix.m_posit);

   NewtonDeserializeBodyArray(m_world, BodyDeserialization, DeserializeFile, file);
   fclose (file);
}


after I did that the file loaded without problem.
It is one body and one compound with two identical flat boxes, tha are place hiorzontal on teh floor, and offest by abput half the width.
I will make the code to parse the user info so that it can load seralize date without it.
but if you commnet those line out, you soudl be able to load teh scene.

other than the camera, it seems to work.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Empty compound collision

Postby PJani » Sun May 20, 2012 7:47 pm

Upps my bad i send wrong file! That file has only one body! This one is with three bodies.
Attachments
debug_world.zip
(824 Bytes) Downloaded 155 times
| 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

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests