Custom Scenenode use

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Seven
Posts: 1030
Joined: Mon Nov 14, 2005 2:03 pm

Custom Scenenode use

Post by Seven »

I am trying to create a custom scenenode that I can use during terrain editing. The intent is to have the scenenode 'cover' the area that is selected for editing.
( editing code works fine)

my thought was to create a node with 9 vertices to create 8 triangles, giving me 4 squares rendered.
vertex #4 would be the center of the node and I would use setPosition(pos) to set the node to the correct location.
(using a cube works fine, but I am wanting just a plane that always faces up, thinking I would edit the Y pos of each vertex based on the terrain height.)
since the plane always faces up, I thought to use vector3df(0,1,0) as the normal for all vertices.

// 0 1 2
// 3 4 5
// 6 7 8

Code: Select all

 
    class FSTerrainEditorNode : public scene::ISceneNode
    {
        core::aabbox3d<f32> Box;
        video::S3DVertex Vertices[9];
        video::SMaterial Material;
    public:
 
        FSTerrainEditorNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id)   : scene::ISceneNode(parent, mgr, id)
        {
            Material.Wireframe = true;
            Material.Lighting = false;
 
            // 0   1   2
            // 3   4   5
            // 6   7   8
            vector3df always_up_vector(0, 1, 0);
            Vertices[0] = video::S3DVertex(-10, 0, -10, always_up_vector.X,always_up_vector.Y,always_up_vector.Z, video::SColor(255, 0, 255, 255),  0,      0);
            Vertices[1] = video::S3DVertex(0,   0, -10, always_up_vector.X,always_up_vector.Y,always_up_vector.Z, video::SColor(255, 255, 0, 255),  0.5,    0);
            Vertices[2] = video::S3DVertex(10,  0, -10, always_up_vector.X,always_up_vector.Y,always_up_vector.Z, video::SColor(255, 255, 255, 0),  1,      0);
            Vertices[3] = video::S3DVertex(-10, 0, 0,   always_up_vector.X,always_up_vector.Y,always_up_vector.Z, video::SColor(255, 0, 255, 0),    0,      0.5);
            Vertices[4] = video::S3DVertex(0,   0, 0,   always_up_vector.X,always_up_vector.Y,always_up_vector.Z, video::SColor(255, 0, 255, 0),    0.5,    0.5);
            Vertices[5] = video::S3DVertex(10,  0, 0,   always_up_vector.X,always_up_vector.Y,always_up_vector.Z, video::SColor(255, 0, 255, 0),    1,      0.5);
            Vertices[6] = video::S3DVertex(-10, 0, 10,  always_up_vector.X,always_up_vector.Y,always_up_vector.Z, video::SColor(255, 0, 255, 0),    0,      1);
            Vertices[7] = video::S3DVertex(0,   0, 10,  always_up_vector.X,always_up_vector.Y,always_up_vector.Z, video::SColor(255, 0, 255, 0),    0.5,    1);
            Vertices[8] = video::S3DVertex(10,  0, 10,  always_up_vector.X,always_up_vector.Y,always_up_vector.Z, video::SColor(255, 0, 255, 0),    1,      1);
 
            
            Box.reset(Vertices[0].Pos);
 
            for (s32 i = 1; i < 8; ++i)
                Box.addInternalPoint(Vertices[i].Pos);
        }
 
        virtual void OnRegisterSceneNode()
        {
            if (IsVisible)
                SceneManager->registerNodeForRendering(this);
 
            ISceneNode::OnRegisterSceneNode();
        }
 
        virtual void render()
        {   
            // 0   1   2
            // 3   4   5
            // 6   7   8
            u16 indices[] = { 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(&Vertices[0], 9, &indices[0], 8, video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
        }
 
        virtual const core::aabbox3d<f32>& getBoundingBox() const
        {
            return Box;
        }
 
        virtual u32 getMaterialCount() const
        {
            return 1;
        }
 
        virtual video::SMaterial& getMaterial(u32 i)
        {
            return Material;
        }
        void setVertexPosition(int index, vector3df pos)
        {
            //Vertices[index].Pos.Y = pos.Y;
        }
    };
 


this is not showing up when rendered. any help on getting this going would be appreciated.
Seven
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Custom Scenenode use

Post by CuteAlien »

Not seeing an obvious reason on quick view. Maybe start without Wireframe and disable backface culling to see if anything shows up. If nothing at all shows up set a breakpoint in OnRegisterSceneNode and in render to see if they are ever called.
Later on with Wireframe you might want to ignore z-buffer in Material so it writes always on top.
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
Seven
Posts: 1030
Joined: Mon Nov 14, 2005 2:03 pm

Re: Custom Scenenode use

Post by Seven »

perfect. thanks for the help!
Post Reply