Kinematic body created from a mesh and registering collision

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Kinematic body created from a mesh and registering collision

Postby Slick » Sat Jan 16, 2021 7:50 am

Using 3.14 a few commits back.

I created some kinematic objects using dNewtonCollisionBox for the collision. I then decided that I needed a kinematic created by a mesh so I did that. Looking at both using a debug viewer they look very similar or the same.

The issue is that while an object is inside the dNewtonCollisionBox version I get collisions but I only get collisions from the mesh based version when the item enters or exits the kinematic object.

This could well be a problem on my side but I'm just asking if that could be a bug? I'll try and look closer at my debug viewer.
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Re: Kinematic body created from a mesh and registering colli

Postby Julio Jerez » Sat Jan 16, 2021 10:48 am

The only difference of kinematic body is that they do not get integrated.
If you set the collision of a kinematic boy off, then they do not get collision but they generate the collision callback.

Check the kinematic body demos, it show both cases.

This has been simplified a lot in 4.0 so that it is much simpler to make triggers since they are part of the core engine now.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Kinematic body created from a mesh and registering colli

Postby Slick » Mon Jan 18, 2021 9:17 am

I will check the demo. I do want to move to 4.0 when it makes sense since I've only ever used the c++. You will have to let us know how much refactoring will be needed to move to 4.0.

I didn't think of looking at the samples. I should have thought that there might have been a mesh based collision object.
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Re: Kinematic body created from a mesh and registering colli

Postby Julio Jerez » Mon Jan 18, 2021 12:33 pm

It is very easdy to convert to 4.0.
In fact almost all demos has been translated in a one to one translation.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Kinematic body created from a mesh and registering colli

Postby FSA » Tue Jan 19, 2021 1:12 pm

Are kinematic bodies with collision turned off, the preferred way to fire for example a "player enters area (kinematic body)" callback? Until now I used manual NewtonCollision or AABB checks for this.
User avatar
FSA
 
Posts: 318
Joined: Wed Dec 21, 2011 9:47 am

Re: Kinematic body created from a mesh and registering colli

Postby Julio Jerez » Tue Jan 19, 2021 2:13 pm

in 4.0 thigger volume are first order objects
this is how you made one

Code: Select all
class ndArchimedesBuoyancyVolume : public ndBodyTriggerVolume
{
   public:
   ndArchimedesBuoyancyVolume();
   ndArchimedesBuoyancyVolume(const nd::TiXmlNode* const xmlNode, const dTree<const ndShape*, dUnsigned32>& shapesCache);

   void CalculatePlane(ndBodyKinematic* const body);
   void OnTriggerEnter(ndBodyKinematic* const body, dFloat32 timestep);
   void OnTrigger(ndBodyKinematic* const kinBody, dFloat32 timestep);
   void OnTriggerExit(ndBodyKinematic* const body, dFloat32 timestep);
   virtual void Save(nd::TiXmlElement* const rootNode, const char* const assetPath, dInt32 nodeid, const dTree<dUnsigned32, const ndShape*>& shapesCache) const;

   dPlane m_plane;
   dFloat32 m_density;
   bool m_hasPlane;
};


then to place one in teh world you write code like this

Code: Select all
static void AddTrigger(ndDemoEntityManager* const scene)
{
   ndPhysicsWorld* const world = scene->GetWorld();

   ndShapeInstance box(new ndShapeBox(20.0f, 10.0f, 20.0f));
   dMatrix uvMatrix(dGetIdentityMatrix());
   uvMatrix[0][0] *= 1.0f / 20.0f;
   uvMatrix[1][1] *= 1.0f / 10.0f;
   uvMatrix[2][2] *= 1.0f / 20.0f;
   uvMatrix.m_posit = dVector(0.5f, 0.5f, 0.5f, 1.0f);
   ndDemoMesh* const geometry = new ndDemoMesh("trigger", scene->GetShaderCache(), &box, "metal_30.tga", "metal_30.tga", "logo_php.tga", 0.5f, uvMatrix);

   dVector floor(FindFloor(*world, dVector(0.0f, 100.0f, 0.0f, 0.0f), 200.0f));
   dMatrix matrix(dGetIdentityMatrix());
   matrix.m_posit = floor;
   matrix.m_posit.m_w = 1.0f;
   matrix.m_posit.m_y += 2.0f;

   ndDemoEntity* const entity = new ndDemoEntity(matrix, nullptr);
   entity->SetMesh(geometry, dGetIdentityMatrix());

   ndBodyTriggerVolume* const body = new ndArchimedesBuoyancyVolume();
   body->SetNotifyCallback(new ndDemoEntityNotify(scene, entity));
   body->SetMatrix(matrix);
   body->SetCollisionShape(box);

   world->AddBody(body);

   scene->AddEntity(entity);
   geometry->Release();
}



and you just respond to the call backs
Code: Select all
   void OnTriggerEnter(ndBodyKinematic* const body, dFloat32 timestep);
   void OnTrigger(ndBodyKinematic* const kinBody, dFloat32 timestep);
   void OnTriggerExit(ndBodyKinematic* const body, dFloat32 timestep);
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Kinematic body created from a mesh and registering colli

Postby FSA » Tue Jan 19, 2021 4:56 pm

What's the reason for using "ndArchimedesBuoyancyVolume" instead of "ndBodyTriggerVolume" diretly?
Also what is the purpose of "ndArchimedesBuoyancyVolume"? Couldn't find anything in the docs.
User avatar
FSA
 
Posts: 318
Joined: Wed Dec 21, 2011 9:47 am

Re: Kinematic body created from a mesh and registering colli

Postby Julio Jerez » Tue Jan 19, 2021 7:44 pm

not particular reason, that just an example of a trigger, you just subclass for it and place it in the world

a class could be like this

Code: Select all
class MyTrigger : public ndBodyTriggerVolume
{
   public:
   MyTrigger();

   // this is called when entering the volume
   void OnTriggerEnter(ndBodyKinematic* const body, dFloat32 timestep)
   {
   }

   // this is called while the body is penetrating the volume
   void OnTrigger(ndBodyKinematic* const kinBody, dFloat32 timestep)
   {
   }

   // this is called when the body leaves the volume
   void OnTriggerExit(ndBodyKinematic* const body, dFloat32 timestep)
   {
   }
};


for example say you have a door in your map.
you place a trigger volume that encluse the door or maybe just enclose the door knock.

you call you call door the when you player touched the trigger, you play the animation that open the door. is just that simple.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Kinematic body created from a mesh and registering colli

Postby Slick » Wed Jan 20, 2021 6:05 am

I'm still playing around with this. My object is smaller than the kinematic object and it looks like if it goes inside the kinematic object I no longer get a collision callback.

I was just trying to test using NewtonContactJointGetClosestDistance but that isn't a solution.

I need to check if my object is inside a kinematic object as well as when it hits it.
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 6 guests

cron