[Solved]Another question about collisions in irredit.

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
DarksideX
Posts: 22
Joined: Wed Dec 10, 2008 7:42 am

[Solved]Another question about collisions in irredit.

Post by DarksideX »

Hello.

I have managed to load a .irr file and apply collision to it. After that i added a collisionanimator to an object(the player). When i start the game the player falls down on the landscape and stands on it. No problem.

The .irr files consists of one terrain generated from a bitmap.
Now the problem is. As soon as i add a cube/mesh/sphere or any form into the irr file. The collision disappears when i start the game :/

Here is the code for creating the triangle selector thing.

Code: Select all

ITriangleSelector * selector = 0;

 // load the scene
        smgr->loadScene("data/scenes/testlv2.irr");
IMetaTriangleSelector * meta = smgr->createMetaTriangleSelector();
array<ISceneNode *> nodes;
        smgr->getSceneNodesFromType(ESNT_ANY, nodes); // Find all nodes
        
        for (u32 i=0; i < nodes.size(); ++i)
        {
                ISceneNode * node = nodes[i];

                switch(node->getType())
                {
                case scene::ESNT_CUBE:
                case scene::ESNT_ANIMATED_MESH:
                        // Because the selector won't animate with the mesh,
                        // and is only being used for camera collision, we'll just use an approximate
                        // bounding box instead of ((scene::IAnimatedMeshSceneNode*)node)->getMesh(0)
                        selector = smgr->createTriangleSelectorFromBoundingBox(node);
                break;

                case scene::ESNT_MESH:
                case scene::ESNT_SPHERE: // Derived from IMeshSceneNode
                        selector = smgr->createTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node);
                        break;

                case scene::ESNT_TERRAIN:
                        selector = smgr->createTerrainTriangleSelector((scene::ITerrainSceneNode*)node);
                        break;

                case scene::ESNT_OCT_TREE:
                        selector = smgr->createOctTreeTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node);
                        break;

                default:
                        // Don't create a selector for this node type
                        break;
                }

                if(selector)
                {
                        // Add it to the meta selector, which will take a reference to it
                        meta->addTriangleSelector(selector);
                        // And drop my reference to it, so that the meta selector owns it.
                        selector->drop();
                }
                
        }




if (selector){ //Set col animator to draPlayer
ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(selector, draPlayer, vector3df(10,20,10),vector3df(0,0,0),vector3df(0,50,0));
selector->drop();
draPlayer->addAnimator(anim);
anim->drop();
}
If i press "add cube" in the irredit toolbar and run the game collisions are disabled. The only thing that appears to be working is the terrain...

Thanks.

-Ali


EDIT:
I tried removing the terrain and adding a simple cube. It worked. As soon as i add a second cube the collision is turned off.
All textures are loaded succesfully btw.

One more thing. I have my own gravity inmplemented (i tried changing to the default grav, didnt work either. Fell right through the floor).

EDIT2:
I turned off all gravity and tried to move to collide with a wall. And it worked! Apperantly only the floor's collision is gone... Why??

EDIT3:
I noticed one more thing. Only the latest cube i added into irredit has collision applied to it. All other are ignored.
Last edited by DarksideX on Sun Dec 21, 2008 6:27 pm, edited 1 time in total.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

When you create the collision response animator, you pass selector which is a pointer to the last triangle selector that you created. You probably want to pass meta instead.

Travis
DarksideX
Posts: 22
Joined: Wed Dec 10, 2008 7:42 am

Post by DarksideX »

When you create the collision response animator, you pass selector which is a pointer to the last triangle selector that you created. You probably want to pass meta instead.

Travis
I tried to replace "selector" with "meta" in this line

ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(selector, draPlayer, vector3df(10,20,10),vector3df(0,0,0),vector3df(0,50,0));
selector->drop();

and the game crashed..

-Ali
DarksideX
Posts: 22
Joined: Wed Dec 10, 2008 7:42 am

Post by DarksideX »

After changing selector to meta, I replaced:

selector->drop(); with meta->drop();

and it worked :) dont know why.. But it worked.

Thanks alot vitek!

-Ali
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

DarksideX wrote:After changing selector to meta, I replaced:

selector->drop(); with meta->drop();

and it worked :) dont know why.. But it worked.
Because you were dropping selector twice, but it was only being grabbed once. Then when it was used by the animator, the program was accessing deallocated memory.

Travis
Post Reply