It took me time because I had to make modification so that the material graph is functional, the way is was, could work, but was no generic enough.
you do no need to use ndModel, if you do not what to.
as I said you car is essentially and raycast but you drag the actual body shape over the ground.
I am actually surpriced that is work as well as if does, but that's a different story.
her is how it works.
-I made the change to the app martial graph, that's files ../applications\ndSandbox\ndContactCallback
-2 you take the and add to your applicatiopn. you cna remove the thing you do no need and what what you need, (ex I have a sound there)
3- in the material graph, you set the enum fo rteh kind of materil; you application will deal with
4- these could be concret, grass, metal .....
5-then when you make the collision shapes, you asign the type of material that shape will be.
for example
- Code: Select all
ndShapeInstance heighfieldInstance(new ndShapeHeightfield(D_HEIGHTFIELD_WIDTH, D_HEIGHTFIELD_HEIGHT,
ndShapeHeightfield::m_invertedDiagonals,
1.0f / 100.0f, D_HEIGHTFIELD_GRID_SIZE, D_HEIGHTFIELD_GRID_SIZE));
ndShapeMaterial material (heighfieldInstance.GetMaterial());
material.m_userId = ndApplicationMaterial::m_aiTerrain;
heighfieldInstance.SetMaterial(material);
same for the body parts.
6- you make your material class that will handle the car/terrain contact and register with teh contact notify graph, something like
- Code: Select all
class CAIMaterial : public ndApplicationMaterial
{
public:
CAIMaterial()
:ndApplicationMaterial()
{
}
CAIMaterial(const CAIMaterial& src)
:ndApplicationMaterial(src)
{
}
ndApplicationMaterial* Clone(const ndApplicationMaterial& src) const
{
return new CAIMaterial((CAIMaterial&)src);
}
virtual void OnContactCallback(const ndContact* const joint, ndFloat32) const
{
//dAssert(joint->IsActive());
const ndContactPointList& contactPoints = joint->GetContactPoints();
for (ndContactPointList::ndNode* contactPointsNode = contactPoints.GetFirst(); contactPointsNode; contactPointsNode = contactPointsNode->GetNext())
{
ndContactPoint& contactPoint = contactPointsNode->GetInfo();
// quick hack to show the solution.
contactPoint.m_normal = ndVector(0.0f, 1.0f, 0.0f, 0.0f);
}
}
};
and the registration is like
- Code: Select all
CAIMaterial material;
ndContactCallback* const callback = (ndContactCallback*)scene->GetWorld()->GetContactNotify();
callback->RegisterMaterial(material, ndApplicationMaterial::m_aiCar, ndApplicationMaterial::m_aiTerrain);
7- now each time new contacts are generated, you can iterate ovr the contact point and fix the contact normals.
as a test so that you can see it is action I simple overide the normal to be a vector point up.
but I will use this to determine when the bug happen,
if you think this could be a solution, please check it out, before I add the part that take the contact and cast and small sphere, to get a general enough contact point.
The rectified contacts, will not have the edge contact problem because they will be the translation distance that will move the sphere up, the vehicle move horizontal.
anyway I hope this is clear,
If you sync, it is all in the sandbox, and I test it, the vehicle moves like silk, not a single bump.
of course, we need a better fix, as I said but I leave like that, until you see it, and also to see if I can detect where the edge bug is actually happening, I's like to know why, and maybe I can fix it.