Adding collision to more than camera

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
malloc
Posts: 13
Joined: Sat Feb 04, 2012 7:25 pm

Adding collision to more than camera

Post by malloc »

Hi everyone

I'm using Irrlicht to create something similar to Minecraft. I've succeeded in adding collision to a floating cube and the camera, but no matter what I do I can't seem to get it to work on other cubes. I can make the other cubes fall, but the camera still passes through them. My code is based on the 7th tutorial.

Code for the floating cube collision works on:

Code: Select all

ITriangleSelector *g_selector = 0;
...
//test cube
        testcube = g_smgr->addCubeSceneNode(CUBESIZE);
        testcube->setPosition(vector3df(0,500,0));
        testcube->setMaterialTexture(0, g_driver->getTexture("textures/texture_stone.bmp"));
        testcube->setMaterialFlag(EMF_LIGHTING, false);
        
        mesh_testcube = g_smgr->addCubeSceneNode(CUBESIZE);
        
        // triangle selector
        g_selector = g_smgr->createOctreeTriangleSelector(mesh_testcube->getMesh(), testcube,32);
        
        // collision
        ISceneNodeAnimator *anim = g_smgr->createCollisionResponseAnimator(
                g_selector, g_cam, vector3df(30,50,30),
                vector3df(0,-3,0),
                vector3df(0,50,0));
        
        g_selector->drop();
        g_cam->addAnimator(anim);
        anim->drop();
My other cubes:

Code: Select all

#define MAXCUBES 2048
 
ISceneNode *cube[MAXCUBES];
        ISceneNodeAnimator *cube_col[MAXCUBES];
 
mesh_testcube = g_smgr->addCubeSceneNode(CUBESIZE);
        g_selector = g_smgr->createOctreeTriangleSelector(mesh_testcube->getMesh(), g_cam,32);
        
        for(j=0; j<i; j++) {
                
                //g_selector = g_smgr->createOctreeTriangleSelector(mesh_testcube->getMesh(), cube[j],32);
                //cube_mesh[j] =  g_smgr->addCubeSceneNode(CUBESIZE);
                //g_selector = g_smgr->createOctreeTriangleSelector(cube_mesh[j]->getMesh(), cube[j],32);
                cube_col[j] = g_smgr->createCollisionResponseAnimator(
                        g_selector, cube[j], vector3df(30,50,30),
                        vector3df(0,-3,0),
                        vector3df(0,50,0));
                
                //g_selector->drop();
                cube[j]->addAnimator(cube_col[j]);
                cube_col[j]->drop();
        }
        
        g_selector->drop();
 
Edit: copied some wrong code
malloc
Posts: 13
Joined: Sat Feb 04, 2012 7:25 pm

Re: Adding collision to more than camera

Post by malloc »

Thanks to a PM from ShyGuy, I think I may have this issue resolved. He linked me to his thread: http://irrlicht.sourceforge.net/forum/v ... =1&t=45767
Post Reply