Problem with triangle selector
Problem with triangle selector
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?
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?
Re: Problem with triangle selector
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
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Re: Problem with triangle selector
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 1186
- Joined: Fri Dec 29, 2006 12:04 am
Re: Problem with triangle selector
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:
Create node and selector:
Cast ray and calculate voxel position if hit:
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));
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();
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;
}
}
}
Re: Problem with triangle selector
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.
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Problem with triangle selector
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 : /
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 : /
Re: Problem with triangle selector
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Problem with triangle selector
No collision at all, just jumps past "if(selectedSceneNode)"
Re: Problem with triangle selector
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?
Re: Problem with triangle selector
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.
Re: Problem with triangle selector
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?
so you have to drop the triangle selector and create a new one every time you reshape the mesh then?
Re: Problem with triangle selector
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.
This will be a terrain later, just a cube now for easy testing.
Re: Problem with triangle selector
thanks for the information
sorry for hijacking your thread!
sorry for hijacking your thread!
Re: Problem with triangle selector
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?
>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?