New Wrapper for the Ogre Engine

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: New Wrapper for the Ogre Engine

Postby Slick » Fri Dec 13, 2013 5:29 pm

In this callback: virtual void OnContactProcess (dNewtonContactMaterial* const contactMaterial, dFloat timestep, int threadIndex) const {}

How would I selectively ignore a collision if I didn't want it to happen? In older versions you would return 0.
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Re: New Wrapper for the Ogre Engine

Postby Julio Jerez » Fri Dec 13, 2013 6:38 pm

Slick wrote:How would I selectively ignore a collision if I didn't want it to happen? In older versions you would return 0.

you are probably confusing with the OnAABBOvelear call back, in the pass there where two callbacks, now there are three.

Code: Select all
bool OnBodiesAABBOverlap (const dNewtonBody* const body0, const dNewtonBody* const body1, int threadIndex) const;
bool OnCompoundSubCollisionAABBOverlap (const dNewtonBody* const body0, const dNewtonCollision* const subShape0, const dNewtonBody* const body1, const dNewtonCollision* const subShape1, int threadIndex) const;
virtual void OnContactProcess (dNewtonContactMaterial* const contacts, dFloat timestep, int threadIndex) const;

OnBodiesAABBOverlap is the same as it was before, it is call from the broad phase, and return false reject teh collsions
OnCompoundSubCollisionAABBOverlap is teh newer whi si call frome teh mid phase, tehis is for compoudn ans scsne collision
and you cn arejest the collsion with specific supshape of a compoudn collisiosn


OnContactProcess is called from the narrow phase after all contacts are calculated.
here you can only reject contacts by delting the form eth contact array, yo ucna do tha is tyow ways.

the first way is by overloading your OnContactProcess in yor WordkClass, something like this

Code: Select all
void OgreNewtonWorld::OnContactProcess (dNewtonContactMaterial* const contactMaterial, dFloat timestep, int threadIndex) const
{
   void* nextContact = NULL;
   for (void* contact = contactMaterial->GetFirstContact(); contact; contact = nextContact) {
      nextContact = contactMaterial->GetNextContact(contact);
      dNewtonCollision* const shape0 = contactMaterial->GetShape0(contact);
      dNewtonCollision* const shape1 = contactMaterial->GetShape1(contact);
      const dMaterialPairManager::dMaterialPair* const materialPair = m_materialMap.GetPair (shape0->GetMaterialId(), shape1->GetMaterialId(), threadIndex);

      // do some condtion 
      //if (somecondition) {
      //   contactMaterial->RemoveContact(contact);
      //}
   }

   OgreNewtonWorld::OnContactProcess (contactMaterial, timestep, threadIndex);
}


the secund way is by overloading the same function on the Body callback with a simular function, che out the ForkLift demo,
I do it to aligne contact to teh tire plane of rotation.

I suspect that you want to reject on per body or per shape bases, so you do not need the lower lever OnContactProcess
but the are all there in case you are doing something special.


Note: function RemoveContact(contact); was missing form teh contact material, I just added.
please sync to svn.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: New Wrapper for the Ogre Engine

Postby Slick » Fri Dec 13, 2013 6:54 pm

Excellent I will synch. I could only find removecontact related to a joint so what you just added is good.

I might look at the world based OnBodiesAABBOverlap too since that is more like I used to use materials. In this case it is for a "sensor field" kind of detection but rejecting contacts. I remember you mentioned another way to do that in the past but I would have to look that up too.
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Re: New Wrapper for the Ogre Engine

Postby Slick » Thu Dec 19, 2013 8:26 pm

Is there a way to convert a mesh loaded in an Ogre::MeshPtr to a dNewtonCollision*?
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Re: New Wrapper for the Ogre Engine

Postby Julio Jerez » Thu Dec 19, 2013 8:57 pm

look at file ../dNewton\dNewtonCollision.h

some of the constructors take a mesh as parameter
Code: Select all
dNewtonCollisionMesh (dNewton* const world, const dNewtonMesh& mesh, dLong collisionMask);
dNewtonCollisionConvexHull (dNewton* const world, const dNewtonMesh& mesh, dLong collisionMask);
dNewtonCollisionCompound (dNewton* const world, const dNewtonMesh& mesh, dLong collisionMask);

for example to make a collision tree out of a newtonMesh you can do something like:
from demo ../ogrenewton\source\OgreNewtonSceneBody.cpp
Code: Select all
void* OgreNewtonSceneBody::AddCollisionTree (SceneNode* const treeNode)
{
   OgreNewtonWorld* const world = (OgreNewtonWorld*) GetNewton();

   // convert the nod and all its children to a newton mesh
   OgreNewtonMesh mesh (world, treeNode);
   mesh.Polygonize();

   // create a collision tree mesh
   dNewtonCollisionMesh meshCollision (world, mesh, 0);

   // add this collision to the scene body
   return AddCollision (&meshCollision);
}



bascally you create a NewtonMesh out of the ogremesh, and then you call the apropriate colsion contructor.
the terrain shows hoa is that done using teh abiove code, it add few instances of stock house in in Ogre SDK as collision tree to a scene collision
Code: Select all
   void AddOgreHouse(OgreNewtonSceneBody* const sceneBody)
   {
      // we are going to place the same mode few time, therefore let us reuse the same asset
      Entity* const houseEntity = mSceneMgr->createEntity (MakeName("house"), "tudorhouse.mesh");
      houseEntity->setCastShadows (true);

      // convert the entity to a newton mesh
      OgreNewtonMesh newtonMesh (m_physicsWorld, houseEntity);
      // optimize the mesh
      newtonMesh.Polygonize();

      // the house is too big we mus scale by some value
      const Real houseScale = 0.02f;
      newtonMesh.ApplyTransform (Vector3(0.0f, 0.0f, 0.0f), Vector3(houseScale, houseScale, houseScale), Quaternion(Quaternion::IDENTITY));

      //now make a collision tree for this mesh
      dNewtonCollisionMesh collision (m_physicsWorld,newtonMesh, 0);

      // now we can use this collision as many time as we want
      Vector3 origin (mCamera->getPosition());

      sceneBody->BeginAddRemoveCollision();
      AddOgreHouse (sceneBody, Vector3(origin + Vector3 (  0.0f, 0.0f, -200.0f)), houseScale, collision, houseEntity);
      AddOgreHouse (sceneBody, Vector3(origin + Vector3 ( 60.0f, 0.0f, -200.0f)), houseScale, collision, houseEntity);
      AddOgreHouse (sceneBody, Vector3(origin + Vector3 (-60.0f, 0.0f, -200.0f)), houseScale, collision, houseEntity);

      AddOgreHouse (sceneBody, Vector3(origin + Vector3 ( 60.0f, 0.0f, -250.0f)), houseScale, collision, houseEntity);
      AddOgreHouse (sceneBody, Vector3(origin + Vector3 (-60.0f, 0.0f, -250.0f)), houseScale, collision, houseEntity);

      sceneBody->EndAddRemoveCollision();

      //delete houseEntity;
   }
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: New Wrapper for the Ogre Engine

Postby Slick » Thu Dec 19, 2013 8:59 pm

I am manually loading a mesh into a meshptr. I am not rendering so I can't create an ogre mesh. It is to create a scenebody but I'll need to do something similar for dynamicbodies.
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Re: New Wrapper for the Ogre Engine

Postby Julio Jerez » Thu Dec 19, 2013 9:06 pm

I edit te hpost, look at this funtion
void AddOgreHouse(OgreNewtonSceneBody* const sceneBody)
is make a collision tree out of an ogremesh, the first function make a collsion tree out of a oger node, and all it children.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: New Wrapper for the Ogre Engine

Postby Slick » Thu Dec 19, 2013 9:28 pm

Ok thanks I will take a look. I only have a meshptr to work with not a mesh/entity or scenenode but maybe I can use the code you pointed me to.
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Re: New Wrapper for the Ogre Engine

Postby Julio Jerez » Thu Dec 19, 2013 10:14 pm

The funtion takes and entity as argument, but all you nee to do is make an entity from you mesh and pass that to the sample fyntion
Entity( const String& name, const MeshPtr& mesh);

and pass that to this constructor
OgreNewtonMesh (dNewton* const world, const Entity* const entity);
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: New Wrapper for the Ogre Engine

Postby Slick » Thu Dec 19, 2013 11:46 pm

I'll see if I can make an entity without a renderer. I've hit problems like this before.
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Re: New Wrapper for the Ogre Engine

Postby Julio Jerez » Fri Dec 20, 2013 9:21 am

I can add a new constructor to the OgerNewtonMesh that will take a meshptr , will that will help?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: New Wrapper for the Ogre Engine

Postby Slick » Fri Dec 20, 2013 11:57 am

Yes that would be excellent. I haven't looked at it today but was thinking I might have to derive a class and try and copy your code. That constructor would do the job because from a OgerNewtonMesh I can then get to a dNewtoncollision to create a body.
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Re: New Wrapper for the Ogre Engine

Postby Julio Jerez » Fri Dec 20, 2013 4:37 pm

ok if you sync you will find a new constructor
OgreNewtonMesh (dNewton* const world, const MeshPtr mesh, const Matrix4& matrix = Matrix4::IDENTITY);
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: New Wrapper for the Ogre Engine

Postby Slick » Fri Dec 20, 2013 5:18 pm

Very cool I was just thinking about asking when you might do it. I hope this solves my problem - it probably does.
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Re: New Wrapper for the Ogre Engine

Postby Slick » Fri Dec 20, 2013 8:51 pm

I had to comment out the UV section of ParseEntity (it was crashing there) but at least it doesn't crash now. I need to do some testing to see it is good.
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 13 guests

cron