Page 1 of 1

terrain selection

Posted: Sat Jun 11, 2016 5:42 pm
by Seven
I am working on the CobbleStones editor and have the terrain editing functions done.
To make it more visual, I am trying to 'paint' a rectangle around the editing target area.

rendering the square to show the selected area i am using this theory
based on the target vertice (index), select the vertices around it

012
345
678
with 4 being the actual target but modifying the points around it also. (this all works for editing)

to create the poly i do this
terrain pointer, selected index (4) and width of terrain heightmap

Code: Select all

 
        void setup(ITerrainSceneNode* terrain, int index, int width)
        {
            scene::IMesh* pMesh = terrain->getMesh();
            scene::IMeshBuffer* pMeshBuffer = pMesh->getMeshBuffer(0);
            if (pMeshBuffer->getVertexType() != video::EVT_2TCOORDS) return;
            video::S3DVertex2TCoords* pVertices = (video::S3DVertex2TCoords*)pMeshBuffer->getVertices();
 
            smallVertices[0].Pos = pVertices[index - 1 + width].Pos;
            smallVertices[1].Pos = pVertices[index     + width ].Pos;
            smallVertices[2].Pos = pVertices[index + 1 + width].Pos;
            smallVertices[3].Pos = pVertices[index - 1].Pos;
            smallVertices[4].Pos = pVertices[index].Pos;
            smallVertices[5].Pos = pVertices[index + 1].Pos;
            smallVertices[6].Pos = pVertices[index - 1 - width].Pos;
            smallVertices[7].Pos = pVertices[index - width ].Pos;
            smallVertices[8].Pos = pVertices[index + 1 - width].Pos;
 
            for (int c = 0; c < 9; c++)
            {
                smallVertices[c].Pos.Y += 10;
                smallVertices[c].Normal = vector3df(0, 1, 0);
            }
        }
 

i then try to render like this

Code: Select all

 
        virtual void render()
        {
        u16 smallindices[27] = 
                                           { 0,1,3,
                                             3,1,4,
                                 1,2,4,
                                 4,2,5,
                                 3,4,6,
                                 6,4,7,
                                 4,5,7,
                                 7,5,8};
 
            video::IVideoDriver* driver = SceneManager->getVideoDriver();
            driver->setMaterial(Material);
            driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
            driver->drawVertexPrimitiveList(&smallVertices[0], 9, &smallindices[0], 8, video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
        }
 
of course it doenst work or I wouldnt be typing this :)
any help is appreciated.

Re: terrain selection

Posted: Sat Jun 11, 2016 11:05 pm
by mongoose7
Well, maybe AbsoluteTransformation is not correct, or maybe the winding is not correct (you could try disabling back-face culling). Also, your patch has the same coordinates as the terrain, so the depth buffer will prevent it from being rendered, so you should nudge them upwards (Y += delta). But instead of using hacks, why not simply create a scene node and let Irrlicht render it for you.

Re: terrain selection

Posted: Sun Jun 12, 2016 9:10 am
by hendu
Or, render your terrain using a shader, pass the highlight world coordinate in, and draw a nice radius ;)