Multiple terrain scene nodes won't create collision points

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
CQCex
Posts: 8
Joined: Thu Jul 21, 2011 11:25 pm
Location: Germany

Multiple terrain scene nodes won't create collision points

Post by CQCex »

Hey,
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 problem that occurs:
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();
Because I couldn't get the collisions to work, I also tried using another approach, getCollisionPoint().
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);
}
The problem remains the same: When the cursor is placed at any other terrain tile, getCollisionPoint() returns false because it didn't find any collision.

Thanks to anyone who read this thread, I really appreciate any hints or possible solutions anyone can find.

Thank you
Last edited by CQCex on Fri Aug 05, 2011 6:52 pm, edited 1 time in total.
CQCex
Posts: 8
Joined: Thu Jul 21, 2011 11:25 pm
Location: Germany

Re: Multiple terrain scene nodes won't create collision poin

Post by CQCex »

I hope it is not to early to bump, but does no one have any idea?
I'm really stuck here, if any more information is needed, just tell me.

Thanks in advance
Last edited by CQCex on Fri Aug 05, 2011 6:52 pm, edited 1 time in total.
Insomniacp
Posts: 288
Joined: Wed Apr 16, 2008 1:45 am
Contact:

Re: Multiple terrain scene nodes won't create collision poin

Post by Insomniacp »

quick thought. the triangle selector may be created relative to the scene node so they will all start at 0,0,0 and make the same exact triangle selector placed on top of each other. What you may need to do is translate each triangle selector before adding it into the meta selector. That way each triangle selector is in its proper world position and not in a relative position. Having not used them before I don't know how they get created. Another thing it could be is that you move the scene nodes after creating the triangle selector which will result in them all being in one spot instead of spread out like they appear after moving. Hope these help and point you in the right direction
CQCex
Posts: 8
Joined: Thu Jul 21, 2011 11:25 pm
Location: Germany

Re: Multiple terrain scene nodes won't create collision poin

Post by CQCex »

Thanks for the hint.I'm in London right now, so I"ll have to wait until thursday
To follow it. I forgot to mention though, that the problem only occurs when I'm working with terrain scene nodes, since user created objects to which a triangle selector is added after creation return normal collision points. That means that for them the triangle selector is created at their position and not at 0,0,0. I'm not really sure whether there's a difference here...

Thank you
Last edited by CQCex on Fri Aug 05, 2011 6:52 pm, edited 1 time in total.
CQCex
Posts: 8
Joined: Thu Jul 21, 2011 11:25 pm
Location: Germany

Re: Multiple terrain scene nodes won't create collision poin

Post by CQCex »

The problem doesen't seem to lie there, the triangle selectors are created exactly like the ones of the other objects,
for which they do exactly what they are supposed to.
Does anyone know whether the terrain triangle selectors support being moved?
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Re: Multiple terrain scene nodes won't create collision poin

Post by Lonesome Ducky »

Hmm, have you tried creating a triangle selector from its normal mesh? Something like:

Code: Select all

smgr->createTriangleSelector(terrain->getMesh(),terrain);
If that doesn't work, you can use the terrain's transformation inverse to transform the ray into local space and it should work.
CQCex
Posts: 8
Joined: Thu Jul 21, 2011 11:25 pm
Location: Germany

Re: Multiple terrain scene nodes won't create collision poin

Post by CQCex »

Thank you.
I had already tried using a mesh triangle selector, but that didn't work, then even at the first terrain no collisions are returned. I don't really know why, but it might me related to the lod patch stuff inside the terrain scene node.

I'm not really sure how to translate the ray.
You can use core::matrix4::transformVect() to transform a vector, but I'm not sure how to do that with a ray.

Thanks
CQCex
Posts: 8
Joined: Thu Jul 21, 2011 11:25 pm
Location: Germany

Re: Multiple terrain scene nodes won't create collision poin

Post by CQCex »

Still stuck on this... any help is really appreciated.
Post Reply