Custom scene node : what's going on ?

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
BillyCallahan
Posts: 26
Joined: Fri Jun 19, 2015 6:51 am

Custom scene node : what's going on ?

Post by BillyCallahan »

Hola :)

I tried to add a 3d rectangle into my scene, by following this tutorial : http://irrlicht.sourceforge.net/docu/example003.html, but I failed and now I get a black rectangle that's not fully drawn (Image).

Here's my render:

Code: Select all

virtual void render()
    {
        u16 indices[] = { 0, 1, 2, 0, 2, 3, 0, 1, 5, 0, 4, 5, 0, 3, 7, 0, 7, 4, 1, 2, 5, 2, 5, 6, 2, 6, 3, 3, 6, 7, 6, 5, 4, 6, 7, 4 };
        video::IVideoDriver* driver = SceneManager->getVideoDriver();
 
        driver->setMaterial(Material);
        driver->setTransform(irr::video::ETS_WORLD, AbsoluteTransformation);
 
        driver->drawVertexPrimitiveList(&Vertices[0], 8, &indices[0], 12);
    }
 
And my constructor:

Code: Select all

Poutre(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id, PoutreStruct une_poutre)
        : scene::ISceneNode(parent, mgr, id)
    {
        Material.Wireframe = false;
        Material.Lighting = false;
 
        Vertices[0] = video::S3DVertex(
            une_poutre.noeud1.x + (une_poutre.larg / 2),
            une_poutre.noeud1.y + (une_poutre.retomb / 2),
            une_poutre.noeud1.z,
            0, 0, 0,
            video::SColor(0, 0, 0, 0),
            0, 0);
 
        Vertices[1] = video::S3DVertex(
            une_poutre.noeud1.x + (une_poutre.larg / 2),
            une_poutre.noeud1.y - (une_poutre.retomb / 2),
            une_poutre.noeud1.z,
            0, 0, 0,
            video::SColor(0, 0, 0, 0),
            0, 0);
 
        Vertices[2] = video::S3DVertex(
            une_poutre.noeud1.x - (une_poutre.larg / 2),
            une_poutre.noeud1.y - (une_poutre.retomb / 2),
            une_poutre.noeud1.z,
            0, 0, 0,
            video::SColor(0, 0, 0, 0),
            0, 0);
 
        Vertices[3] = video::S3DVertex(
            une_poutre.noeud1.x - (une_poutre.larg / 2),
            une_poutre.noeud1.y + (une_poutre.retomb / 2),
            une_poutre.noeud1.z,
            0, 0, 0,
            video::SColor(0, 0, 0, 0),
            0, 0);
 
        Vertices[4] = video::S3DVertex(
            une_poutre.noeud2.x + (une_poutre.larg / 2),
            une_poutre.noeud2.y + (une_poutre.retomb / 2),
            une_poutre.noeud2.z,
            0, 0, 0,
            video::SColor(0, 0, 0, 0),
            0, 0);
 
        Vertices[5] = video::S3DVertex(
            une_poutre.noeud2.x + (une_poutre.larg / 2),
            une_poutre.noeud2.y - (une_poutre.retomb / 2),
            une_poutre.noeud2.z,
            0, 0, 0,
            video::SColor(0, 0, 0, 0),
            0, 0);
 
        Vertices[6] = video::S3DVertex(
            une_poutre.noeud2.x - (une_poutre.larg / 2),
            une_poutre.noeud2.y - (une_poutre.retomb / 2),
            une_poutre.noeud2.z,
            0, 0, 0,
            video::SColor(0, 0, 0, 0),
            0, 0);
 
        Vertices[7] = video::S3DVertex(
            une_poutre.noeud2.x - (une_poutre.larg / 2),
            une_poutre.noeud2.y + (une_poutre.retomb / 2),
            une_poutre.noeud2.z,
            0, 0, 0,
            video::SColor(0, 0, 0, 0),
            0, 0);
 
        Box.reset(Vertices[0].Pos);
        for (s32 i = 1; i < 8; ++i)
            Box.addInternalPoint(Vertices[i].Pos);
    }
 
Is there something wrong please ?
As it's in french, please consider the word 'poutre' as a beam wood, and 'noeud' as node. I get two nodes that give me the coordinates of my beam wood.

Thank you for your help :)
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Custom scene node : what's going on ?

Post by CuteAlien »

Did you make sure the ordering of your indices is always the same for each polygon (clockwise or anti-clockwise)? For a quick test disable BackfaceCulling in your material so it draws both sides.

Otherwise - might be wrong coordinates or wrong indices. Maybe draw on paper.

It being black usually is cause by a black material or you have enabled SMaterial::Lighting but no light in the scene.
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
BillyCallahan
Posts: 26
Joined: Fri Jun 19, 2015 6:51 am

Re: Custom scene node : what's going on ?

Post by BillyCallahan »

Hi ya :)

Here's my new indices tab, I tried to do as you said but it won't work...(clockwise here)

Code: Select all

u16 indices[] = { 0,1,2, 2,3,0, 4,5,1, 1,0,4, 7,4,0, 0,3,7, 3,2,6, 6,7,3, 4,5,6, 6,7,4, 5,6,2, 2,1,5};
I uploaded an image so you can check if you have time :)
By the way the number '6' is the vertex hidden behind the beam in the image.
Image
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Custom scene node : what's going on ?

Post by CuteAlien »

Most indices look correct, but I think 4,5,6, 6,7,4 should be 6,5,4, 4,7,6.
And if you say it doesn't work - just post a new image how it looks now.
And did the material thing get solved (no more black)?
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
BillyCallahan
Posts: 26
Joined: Fri Jun 19, 2015 6:51 am

Re: Custom scene node : what's going on ?

Post by BillyCallahan »

I fixed the indices, now I get this image:
Image

The material thing was normal (sorry for the misunderstanding), I set the vertices' color to black. Now I'm trying with 'Material.Wireframe = true;' .

So, I still get some un-drawn sides...:(


EDIT: With 'Material.BackfaceCulling = false;' I get this:
Image
But I don't want the hidden sides to be drawn.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Custom scene node : what's going on ?

Post by CuteAlien »

Looks to me like one vertex has wrong coordinates on those images.
edit: In your code above it looks like you set all z to the same value.
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
BillyCallahan
Posts: 26
Joined: Fri Jun 19, 2015 6:51 am

Re: Custom scene node : what's going on ?

Post by BillyCallahan »

Owh that's my bad, you're right I drew it like it was parallel to the Z axis...

It works like a charm now!

Thank you man :D
Post Reply