Triangle selector on a plane?

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
whythishard
Posts: 9
Joined: Tue Feb 25, 2020 1:53 pm

Triangle selector on a plane?

Post by whythishard »

I do the following in order to create planes and send only one draw call for every single one of them

Code: Select all

 
device->getCursorControl()->setVisible(false);
 
 
    irr::scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS();
    cam->setPosition(irr::core::vector3df(10, 30, 10));
 
    irr::video::ITexture * myTex = driver->getTexture("ground.png");
    const irr::scene::IGeometryCreator *geomentryCreator = smgr->getGeometryCreator();
 
    CBatchingMesh *BatchingMesh = new CBatchingMesh();
 
    for(int x = 0; x < 100; x++) {
        for(int z = 0; z < 50; z++) {
            irr::scene::IMesh* plane = geomentryCreator->createPlaneMesh(irr::core::dimension2d<irr::f32>(5, 5), irr::core::dimension2d<irr::u32>(1, 1));
            plane->getMeshBuffer(0)->getMaterial().setTexture(0, driver->getTexture("ground.png"));
            BatchingMesh->addMesh(plane, core::vector3df(5*x, 0, 5*z));
        }
    }
 
    BatchingMesh->update();
    BatchingMesh->setMaterialFlag(EMF_LIGHTING, false);
    BatchingMesh->setHardwareMappingHint(EHM_STREAM, EBT_VERTEX_AND_INDEX);
 
    ISceneNode *node = smgr->addMeshSceneNode(BatchingMesh);
    node->setScale(core::vector3df(1, 1, 1));
    node->setDebugDataVisible(EDS_BBOX_BUFFERS);
    BatchingMesh->drop();
 
You might've noticed I do not create any IAnimateMesh to render the world, therefor I cannot pass that into a scene::ITriangleSelector. How do I go about solving this issue? The goal is to get the planes to highlight when the player looks at them and they are within range (let say 25 length units) of the camera. I want the whole plane to highlight, not just a triangle of the plane, and not the whole sum of the planes either (by that I mean I do not want to slap a single triangle selector on the mesh so all planes highlight when you look at any of them).
CuteAlien
Admin
Posts: 9652
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Triangle selector on a plane?

Post by CuteAlien »

Tricky. First some quick other stuff... EHM_STATIC probably works better for you than EHM_STREAM.
And default scale is always 1,1,1 so you don't have to set that if you don't want to (you are still allowed to do so if you want... just for info).

Now the problem with selectors... there's really more than one problem here. The first is having independent selectors. The second is highlighting planes independent when you have them in a batchingmesh. The batching mostly works faster because it put identical materials together. But then you no longer have different materials so highlighting just one of them becomes tricky.

Basically - this is kinda where you start writing our own SceneNodes, Shaders and TriangleSelectors. But that's not exactly beginner stuff. A very ugly workaround I can think off would be - you create one triangle-selector for each plane. And then you create invisible nodes as well and use them for this. So you have a bunch of nodes which do nothing but be there with the correct offset for the triangle selector (and I'm not 100% certain this will work). And maybe those invisible nodes may even be later be used to add some highlight effect for the selected one (like drawing some semi-transparent stuff over the real triangles - or some lines around them so you got a selection border).

Things always become difficult when you have to work with lots of objects - as then you have to start using tricks. It's easier if your first game is far away from all limits. I always recommend something like space-invaders or snake or pacman or so to start with.
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
Post Reply