this is my first post here, but I've been reading threads for quite a while now.
I searched the forums for several hours this evening and tried out everything that came to my mind,
but I just didn't manage to solve this problem. I tried to keep the snippets small, but I think everything that might me important is included.
The situation:
I have created a class that manages several terrain tiles. Each terrain tile is an Irrlicht terrain scene node and the class manages the creation, editing
and saving/loading of the tiles. So far, eveything works like a charm.
My application includes an editor mode, in which a cursor is placed upon the terrain which works as some kind of mouse pointer. The user can
select existing objects and create new ones at the cursor's position. To get the position the cursor has to be placed at, the following code is being used:
In the snippet below, "editor_ColPoint" is the scene node representing the cursor, "terrain->getTerrainAtPos(collisionPoint)" is a member of the managing class (terrain is an object of it).
Code: Select all
core::line3d<f32> line;
line.start=camera->getPosition();
line.end=line.start+(camera->getTarget()-line.start).normalize()*MAX_COL_DISTANCE;
core::vector3df collisionPoint;
core::triangle3df triangle;
//Check for collisions:
scene::ISceneNode*hitNode=colmgr->getSceneNodeAndCollisionPointFromRay(line,collisionPoint,triangle,0,0,false);
if(hitNode)
{
if(hitNode!=terrain->getTerrainAtPos(collisionPoint))
{
selectedNode=hitNode;
selectedNode->getMaterial(0).Wireframe=true;
}
}
//Move collision sphere:
editor_ColPoint->setPosition(collisionPoint);
The cursor is shown at the right place, but only on the terrain tile which has been added first. On all other terrain tiles, no collisions are detected ( if(hitNode) fails).
I'm using a meta triangle selector, all new tiles are added to it using the following code (trinangle selector is the meta triangle selector):
Code: Select all
irr::scene::ITriangleSelector*sel=smgr->createTerrainTriangleSelector(terrainNode,0);
triangleSelector->addTriangleSelector(sel);
terrainNode->setTriangleSelector(triangleSelector);
sel->drop();
In the snippet below, terrain->getTriangleSelector() returns a pointer to the meta triangle selector:
Code: Select all
core::line3df ray=colmgr->getRayFromScreenCoordinates(device->getCursorControl()->getPosition(),camera);
core::vector3df pos;
core::triangle3df triangle;
const scene::ISceneNode* hitNode;
if(smgr->getSceneCollisionManager()->getCollisionPoint(ray,terrain->getTriangleSelector(),pos,triangle,hitNode))
{
editor_ColPoint->setPosition(pos);
}
Thanks to anyone who read this thread, I really appreciate any hints or possible solutions anyone can find.
Thank you