Problem with triangle selector

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.
Virror
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Problem with triangle selector

Post by Virror »

I have a problem with a triangle selector. I have a cube that consists of 20x20x20 vertices based on a volume of voxels.
I create a triangleSelector so when i click the cube, i transform the coordinates from a ray collision and remove the correct voxel, then i recalculate the mesh for that area and redo the selector.
Problem is that i don't get a "hit" on the whole cube, just some of the sides, what can cause this problem?
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Problem with triangle selector

Post by REDDemon »

Do you use the built-in selector or do you have wrote your own selector?
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
CuteAlien
Admin
Posts: 9679
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Problem with triangle selector

Post by CuteAlien »

Fixing collision problems is very hard to do without a testcase (and often even hard with a testcase....).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: Problem with triangle selector

Post by randomMesh »

Please show a minimal compilable example.
"Whoops..."
Virror
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Re: Problem with triangle selector

Post by Virror »

A compilable example would be hard cause its integrated into the game I'm making and using external libs and stuff. But i will try to post as much relevant code as i can.
Problem is that on half of the cube I'm not getting a ray hit at all, or working camera collision.

Create class and then cube:

Code: Select all

ITerrainVoxelSceneNode * test = new ITerrainVoxelSceneNode(0, irrScene, MT_WORLD, vector3df(2500*2, 450*2, 2000*2),
    vector3df(0, 0, 0),vector3df(30.0F, 30.0F, 30.0F));
ISceneNode * test2 = test->loadCube(20, SColor(255, 255, 255, 255));
Create node and selector:

Code: Select all

newMesh = new SMesh;
ITriangleSelector* meshSelector = 0;
IMeshBuffer * newBuffer = ConvertMesh(*mesh, vertexColor);
newMesh->addMeshBuffer(newBuffer);
newMesh->recalculateBoundingBox();
SceneManager->getMeshManipulator()->makePlanarTextureMapping(newMesh, 2.0f);
newNode = SceneManager->addMeshSceneNode(newMesh, Parent, ID, RelativeTranslation, RelativeRotation, RelativeScale);
meshSelector = SceneManager->createTriangleSelector(newMesh, newNode);
newNode->setTriangleSelector(meshSelector);
meshSelector->drop();
 
Cast ray and calculate voxel position if hit:

Code: Select all

vector3df intersection;
triangle3df hitTriangle;
line3d<f32> ray;
ray.start = camera->getPosition();
ray.end = ray.start + (camera->getTarget() - ray.start).normalize() * 300.0f;
ISceneNode * selectedSceneNode = collMan->getSceneNodeAndCollisionPointFromRay(ray, intersection, hitTriangle, 0, 0); 
    if(selectedSceneNode)
    {
        switch(selectedSceneNode->getID())
        {
            case MT_WORLD:
            {
                int posX, posY, posZ;
                posX = (int)(intersection.X - selectedSceneNode->getAbsolutePosition().X);
                posY = (int)(intersection.Y - selectedSceneNode->getAbsolutePosition().Y);
                posZ = (int)(intersection.Z - selectedSceneNode->getAbsolutePosition().Z);
                voxelScene->removeVoxel(posX, posY, posZ);
                break;
            }
        }
    }
 
CuteAlien
Admin
Posts: 9679
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Problem with triangle selector

Post by CuteAlien »

Hm, really hard without a working test-example :-(
First idea - you are only using 300 units length for your collision-ray, maybe it's beyond that? Try working with the camera far-value instead to be sure you can hit anything that's visible for the user.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Virror
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Re: Problem with triangle selector

Post by Virror »

I know its hard without an example to debug : /
The 300 length should be ok if I'm standing right next to the cube right? Its working from one side, so it should work from the other side to if im close.
The reason for the 300 is that i don't want the player to be able to dig to far away, that would feel very unrealistic, but i can try to change it just to test : )

Edit: Setting range wont help : /
CuteAlien
Admin
Posts: 9679
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Problem with triangle selector

Post by CuteAlien »

Did you debug if you maybe hit something else? (like your own player ... )
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Virror
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Re: Problem with triangle selector

Post by Virror »

No collision at all, just jumps past "if(selectedSceneNode)"
aanderse
Posts: 155
Joined: Sun Aug 10, 2008 2:02 pm
Location: Canada

Re: Problem with triangle selector

Post by aanderse »

somewhat unrelated, just for my own understanding of irrlicht collision system, and could be stupid question but... if you actually just have a cube why don't you just use the bounding box triangle selector via ISceneManager::createTriangleSelectorFromBoundingBox?
Virror
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Re: Problem with triangle selector

Post by Virror »

Well, the thing is that i can "cut" in the stone shaping it, so i need mesh collision to transform the collision point into numbers i use for mesh transformation.
aanderse
Posts: 155
Joined: Sun Aug 10, 2008 2:02 pm
Location: Canada

Re: Problem with triangle selector

Post by aanderse »

ah didn't realize you could reshape the cube
so you have to drop the triangle selector and create a new one every time you reshape the mesh then?
Virror
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Re: Problem with triangle selector

Post by Virror »

Thats what im doing currently, it was my guess it was the only way. But creating a selector is pretty quick.
This will be a terrain later, just a cube now for easy testing.
aanderse
Posts: 155
Joined: Sun Aug 10, 2008 2:02 pm
Location: Canada

Re: Problem with triangle selector

Post by aanderse »

thanks for the information
sorry for hijacking your thread!
zprg
Competition winner
Posts: 30
Joined: Tue Jul 31, 2012 12:29 pm
Location: Germany

Re: Problem with triangle selector

Post by zprg »

virror wrote:
>and using external libs and stuff. But i will try to post as much relevant code as i can.
>Problem is that on half of the cube I'm not getting a ray hit at all, or working camera collision.

ah i think you also use polyvox and i run into the same problem atm. from the half of the polyvoxmesh i get no collision.
so cause you had the same problem is seems that the reason of the problem is not irrlicht, please how solved the problem?
Post Reply