Simple collision check between octrees?

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
brick
Posts: 36
Joined: Sun Jul 10, 2011 12:15 pm

Simple collision check between octrees?

Post by brick »

Is there a simple way to check collision between two nodes on the scene that is similar to this piece of code:

Code: Select all

node1->getTransformedBoundingBox().intersectsWithBox(node2->getTransformedBoundingBox());
but that uses octrees instead of boxes, or a combination of both?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Simple collision check between octrees?

Post by hybrid »

Yes, check out triangle selectors. I think there's also an optimized octree selector, which uses a box approach.
brick
Posts: 36
Joined: Sun Jul 10, 2011 12:15 pm

Re: Simple collision check between octrees?

Post by brick »

Sorry if this is a dumb question, but is it possible to just copy this code from tut07 and use it on a, say, IAnimatedMeshSceneNode instead of camera? That is, achieve collision detection between a mesh node and the quake 3 map.

Code: Select all

 
scene::ITriangleSelector* selector = 0;
 
        if (q3node)
        {
                q3node->setPosition(core::vector3df(-1350,-130,-1400));
 
                selector = smgr->createOctreeTriangleSelector(
                                q3node->getMesh(), q3node, 128);
                q3node->setTriangleSelector(selector);
        }
 
...

Code: Select all

 
if (selector)
        {
                scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
                        selector, camera, core::vector3df(30,50,30),
                        core::vector3df(0,-10,0), core::vector3df(0,30,0));
                selector->drop(); // As soon as we're done with the selector, drop it.
                camera->addAnimator(anim);
                anim->drop();  // And likewise, drop the animator when we're done referring to it.
        }
 
Because when I put the name of my node in there instead of "camera" and run the program, the collision with level is far from accurate, even when I play around with the parameters. The character seems to be stuck in a small invisible triangle.
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: Simple collision check between octrees?

Post by christianclavet »

This should work, but have you tried increased the collision sphere/ellipsoid size of you collision response animator? Check also that your animated object is NOT in the triangle selector. If you need to detect more than one object (the level + more meshes, you can check the SDK documentation dor the metaselector)

Normally, if the movement goes well with the camera, it should do the same with a mesh. If it still block, then perhaps you should check how you move the node.
brick
Posts: 36
Joined: Sun Jul 10, 2011 12:15 pm

Re: Simple collision check between octrees?

Post by brick »

Thanks for the answer. I'm not sure what you mean by checking how I move the node?

I'm trying to have a mesh collide with quake3 instead of camera colliding, and I've tried increasing/decreasing ellipsoid radius, but the issue remains. The node occasionally starts going up as if the terrain is raising when it's not (or as if there are stairs where there aren't any), and sometimes it's completely immovable, depending on the createCollisionResponseAnimator parameters. Perhaps it has something to do with the format of the loaded object? I'm using an .X skinned animated mesh, which I believe has a box around it.
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: Simple collision check between octrees?

Post by christianclavet »

Perhaps it won't do anything more but have you tried this when you move your node?

Code: Select all

node->updateAbsolutePosition()
The object should not be affecting the movement in the scene unless you added its triangles to the triangle selector, it should only be a visual representation and nothing more. What is doing the collision with the scene actually is the ellipsoid, and it should be of a size that enclose your model (so it's visually ok). Be sure that your ellipsoid is also a little above ground when you start the application.
brick
Posts: 36
Joined: Sun Jul 10, 2011 12:15 pm

Re: Simple collision check between octrees?

Post by brick »

Only now did it strike me what you were talking about. I'm moving the node with WASD keys instead of arrow keys. Perhaps that's the reason why it isn't working properly? Is there a way to edit the above code to add the information that different keys are used for movement?
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: Simple collision check between octrees?

Post by christianclavet »

No, changing the key input should not do that. Have you tried your level with the "old method"? (I mean that is moving the camera). I still have problems with certains levels that I used to "walk" into, while others seem to run fine.

If you move your camera, and it does the same effect, then there something in the mesh of the level that cause this problem. This happened often to me because the level I was testing was really full of details (as really tiny triangles, and really big triangles). If you found out that it's the level and you want to keep it up the way it is:

Solution 1: (Reprensentation mesh, collision mesh)
- Load your level as an octree, but don't put any triangle selector, this will be your "representation object"
- Try to load your level in a modeling application, and model a "collision model". Use your original model as reference and model the "big" parts only (wall, floor, colums), no ceiling or any details on that one,
- Load the "collision model" then in Irrlicht, and assign the triangle selector on it, then place it exactly where is your level mesh, and hide it. Since the triangles are in the triangle selector, the collision with this mesh should still work.

Solution 2: Do you level in 2 parts (big triangles, and small triangles)
- You load back your level in yout modeling application and you select the floors, walls, and colums(Sometimes it could help having the colums separate), save only that part
- Save the rest as a separate object
- Load the 2 mesh in Irrlicht: The mesh containing the wall, and floor, should be assigned to a triangle selector
- The mesh containing the details should be loaded separately, and NO triangle selector should be applied
thoma91
Posts: 28
Joined: Tue Aug 09, 2011 10:00 am

Re: Simple collision check between octrees?

Post by thoma91 »

Just as the camera's and the Quake level's collision:

Code: Select all

 
if (selector)
{
        scene::ISceneNodeAnimator* animator = smgr->createCollisionResponseAnimator(
                selector, node, core::vector3df(80,50,40),
                core::vector3df(0,0,0), core::vector3df(0,0,0));
        selector->drop(); // Don't drop the selector after the camera-level collision (if you keep that), only drop after this node-level collision
        node->addAnimator(animator);
        animator->drop();
}
 
brick
Posts: 36
Joined: Sun Jul 10, 2011 12:15 pm

Re: Simple collision check between octrees?

Post by brick »

@christianclavet: Thank you very much for the detailed response! I tried the camera and it didn't work at first, but when I positioned it on the same coordinates as in the tutorial, the collision worked properly (I guess because that's the intended position in quake3). Then I placed the node on the same position and adjusted the scale and some of the coordinates to have it standing properly on the ground, and now it works great.

These boards have really been helpful so far in my working with Irrlicht. Thanks a lot everyone!
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: Simple collision check between octrees?

Post by christianclavet »

If you can check this. If the position changed everything, perhaps is that your meshes where in collision at initialisation. Try to set your mesh at another place, and check that they don't touch each other (I place the object in the air over the ground)
brick
Posts: 36
Joined: Sun Jul 10, 2011 12:15 pm

Re: Simple collision check between octrees?

Post by brick »

The object falls on the ground when I place it in the air. Also when I put the camera object on the "wrong" coordinates and it's initially stuck, I look up (with the mouse) and press the forward key, and that makes the camera view rise slightly and the collision detection becomes accurate (the camera gets unstuck). I'm guessing that the bottom of the object got stuck somehow, perhaps I didn't place the object on the scene in such a way that its bounding box initially had sufficient distance from the floor or other objects. In any case, it works well now.
Post Reply