When i put a object X 50, Y -175, Z 89, collision works fine, but if i use X < -100 it doesnt work.
for example the same object X -150, Y -175, Z 89
it's so strange because the collision works with terrain normaly all the cenario
I'm using this code:
Code: Select all
void ISceneNode_assignTriangleSelector(scene::ISceneNode* node, scene::ISceneManager* smgr, io::IFileSystem* ifs)
{
if (!node || !smgr || !ifs)
return;
if (node->getType() == scene::ESNT_OCT_TREE)
{
io::IAttributes* attribs = ifs->createEmptyAttributes();
if (attribs)
{
node->serializeAttributes(attribs);
// get the mesh name out
core::stringc name = attribs->getAttributeAsString("chao");
attribs->drop();
// get the animated mesh for the object
scene::IAnimatedMesh* mesh = smgr->getMesh(name.c_str());
if (mesh)
{
scene::ITriangleSelector* selector =
smgr->createOctTreeTriangleSelector(mesh->getMesh(0), node, 128);
node->setTriangleSelector(selector);
selector->drop();
}
}
}
else if (node->getType() == scene::ESNT_MESH)
{
if (node->getID() == -1)
{
scene::IMeshSceneNode* msn = (scene::IMeshSceneNode*)node;
if (msn->getMesh())
{
scene::ITriangleSelector* selector =
smgr->createTriangleSelector(msn->getMesh(), msn);
msn->setTriangleSelector(selector);
selector->drop();
// get objects from irr file
// swprintf(test,200,L" X %0.0f Y %0.0f Z %0.0f ",msn->getPosition().X, msn->getPosition().Y, msn->getPosition().Z );
}
}
}else if (node->getType() == scene::ESNT_ANIMATED_MESH)
{
scene::IAnimatedMeshSceneNode* msn = (scene::IAnimatedMeshSceneNode*)node;
scene::IAnimatedMesh* am = msn->getMesh();
if (am)
{
scene::ITriangleSelector* selector =
smgr->createTriangleSelector(am->getMesh(0), msn);
msn->setTriangleSelector(selector);
selector->drop();
}
}
else if (node->getType() == scene::ESNT_TERRAIN)
{
scene::ITerrainSceneNode* tsn = (scene::ITerrainSceneNode*)node;
scene::ITriangleSelector* selector =
smgr->createTerrainTriangleSelector(tsn, 2); // probably don't want lod 0 all the time...
tsn->setTriangleSelector(selector);
selector->drop();
}
else if (node->getType() == scene::ESNT_CUBE)
{
scene::ITriangleSelector* selector =
smgr->createTriangleSelectorFromBoundingBox(node);
node->setTriangleSelector(selector);
selector->drop();
}
else
{
// not something we want to collide with
}
}
void ISceneNode_assignTriangleSelectors(scene::ISceneNode* node, scene::ISceneManager* smgr, io::IFileSystem* ifs)
{
// assign a selector for this node
ISceneNode_assignTriangleSelector(node, smgr, ifs);
// now recurse on children...
core::list<scene::ISceneNode*>::Iterator begin = node->getChildren().begin();
core::list<scene::ISceneNode*>::Iterator end = node->getChildren().end();
for (; begin != end; ++begin)
ISceneNode_assignTriangleSelectors(*begin, smgr, ifs);
}
void ISceneManager_assignTriangleSelectors(scene::ISceneManager* smgr, io::IFileSystem* ifs)
{
ISceneNode_assignTriangleSelectors(smgr->getRootSceneNode(), smgr, ifs);
}
void ISceneNode_gatherTriangleSelectors(scene::ISceneNode* node, scene::IMetaTriangleSelector* meta, const core::aabbox3df& box)
{
scene::ITriangleSelector* selector = node->getTriangleSelector();
if (selector && node->getTransformedBoundingBox().intersectsWithBox(box))
meta->addTriangleSelector(selector);
// now recurse on children...
core::list<scene::ISceneNode*>::Iterator begin = node->getChildren().begin();
core::list<scene::ISceneNode*>::Iterator end = node->getChildren().end();
for (; begin != end; ++begin)
ISceneNode_gatherTriangleSelectors(*begin, meta, box);
}
void ISceneManager_gatherTriangleSelectors(scene::ISceneManager* smgr, scene::IMetaTriangleSelector* meta, const core::aabbox3df& box)
{
ISceneNode_gatherTriangleSelectors(smgr->getRootSceneNode(), meta, box);
}
int main {
....
ISceneManager_assignTriangleSelectors(smgr, device->getFileSystem());
meta = smgr->createMetaTriangleSelector();
anms = smgr->addAnimatedMeshSceneNode(smgr->getMesh("..."));
scene::ISceneNodeAnimator* anim2 = smgr->createCollisionResponseAnimator(meta, anms, core::vector3df(3,3,3), core::vector3df(0,-0.04,0), core::vector3df(0,2,0));
anms->addAnimator(anim2);
...
}