Editor style Grid SceneNode [Updated: Sept. 27, 2009]

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post by shadowslair »

It`s just a guess, but IMO most probably either your grid lines coinside with some floor mesh or somewhat and it`s a z-buffer problem, or you`re talking for a simple line pixelisation rendering problem( lol :lol:). If so try enabling antialiasing for your application, if not you can always post a screenshot... :wink:
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
ceyron
Posts: 63
Joined: Tue Mar 03, 2009 5:10 pm
Location: Bucuresti, România

Post by ceyron »

Well i fixed it somehow, the problem was that the grid lines overlapped with the axis lines so that wierd flickering occured so i modified my code and changed the spacing and accent line offset and it works now.


Original Code - flickering occurs

Code: Select all

scene::CGridSceneNode* grid = new scene::CGridSceneNode(smgr->getRootSceneNode(), smgr, 0,
                                  32, // spacing
                                  2048, //size
                                  video::SColor(0xAA666666), //color
		                  12, //accent line offset
                                  video::SColor(0xAA5c5c5c), //accent grid color
		                  true); //axis line state

Modified code - No flickering because the grid and axis lines don't overlap anymore

Code: Select all

scene::CGridSceneNode* grid = new scene::CGridSceneNode(smgr->getRootSceneNode(), smgr, 0, //root node, scene manager, ID
                                  33, // spacing   << +1
                                  2048, //size
                                  video::SColor(0xAA666666), //color
		                  13, //accent line offset << +1
                                  video::SColor(0xAA5c5c5c), //accent grid color
		                  true); //axis line state
Image
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post by Dark_Kilauea »

Sounds like you are getting a z-fighting bug.

You may be able to fix this bug by making a small change to CGridSceneNode::render() in CGridSceneNode.cpp

Code: Select all

...
                // Axis Lines are only drawn if the State is true
		if(m_AxisLineState)
		{
			driver->draw3DLine(core::vector3df((f32)m_size,0.01f,0),core::vector3df(-(f32)m_size,0.01f,0),m_XLineColor);
			driver->draw3DLine(core::vector3df(0,0.01f,(f32)m_size),core::vector3df(0,0.01f,-(f32)m_size),m_ZLineColor);
		}
...
Note that this does raise the axis lines slightly above the rest of the grid. I'm not going to add this as a patch to the base node, since raising the axis lines above the grid may not be useful for those that do not have this issue.
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
ceyron
Posts: 63
Joined: Tue Mar 03, 2009 5:10 pm
Location: Bucuresti, România

Post by ceyron »

This is indeed a z-fighting bug, what you suggested doesn't work i'm afraid (it was the first thing i tried myself) 0.01 produces the same flickering, 0.1 on the other hand solves the issue but only above the grind plane, below the plane the axes are barely visible and are flickering.

My irrlicht version is 1.6 from SVN, and i am compiling this on Linux Mint 7 with openGL, i cannot test this on windows with Direct3D to see if the same issue occurs :(


UPDATE:
setting the material ZWriteEnable to false in the class constructor seem to work just fine, it's rather strange i thought that with no Zbuffer write the grid will render above other things in my scene but it does not :shock:

Code: Select all

Buffer.Material.ZWriteEnable = false;
Thank you for the quick answer Dark_Kilauea.
Image
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post by Dark_Kilauea »

Well, z testing is still on, thus the grid will still be hidden by other objects. However, the grid really shouldn't be writing to the z-buffer, since it really can't (and shouldn't) hide anything behind it.

I've updated the node to disable z-write. Thanks for the patch.
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post by shadowslair »

Well, the "new" patch (Buffer.Material.ZWriteEnable = false;) or disabling the z-buffer check makes the engine draw the grid always behind everything and some really ugly things happen for me... :lol:

(just for the protocol - test running on WinXP DX9 on ATI Radeon 9550, Irrlicht 1.5.1 stable) :wink:
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post by randomMesh »

Just wanted to say thank you. This is a nice piece of code.

You could work on the const-correctness and inlining, though.

Code: Select all

inline const video::SColor& GetGridColor() const { return m_gridcolor; }
rather than

Code: Select all

video::SColor GetGridColor();
etc.
"Whoops..."
CuteAlien
Admin
Posts: 9646
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Editor style Grid SceneNode [Updated: Sept. 27, 2009]

Post by CuteAlien »

The original link seems to be dead :-( Are you still around Dark_Kilauea ? Or is there someone who still has a working version?
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
RdR
Competition winner
Posts: 273
Joined: Tue Mar 29, 2011 2:58 pm
Contact:

Re: Editor style Grid SceneNode [Updated: Sept. 27, 2009]

Post by RdR »

CuteAlien wrote:The original link seems to be dead :-( Are you still around Dark_Kilauea ? Or is there someone who still has a working version?
Not sure if its the same version but I used one for my CASViewer application.

CGridSceneNode.h
http://pastebin.com/DSkcPuXL

Code: Select all

 
#ifndef __C_GRID_SCENE_NODE_H__
#define __C_GRID_SCENE_NODE_H__
 
#include "ISceneNode.h"
#include "CMeshBuffer.h"
#include <memory>
 
//! Grid scene node
/*! If you need a grid on the XY or ZY axis, simply rotate this node by 90 
degrees in the appropiate axis.
This node creates an XZ grid by default, which should be fine for normal use.
Axis Lines are a default Red and Blue for the X and Z axis respectively.
 
Please note that the internal meshbuffer used for the grid has a max size of 65535 indecies.
 
Thanks goes to MasterGod for helping to clean up the code and for a few bug fixes.
 
Additional thanks to:
JP for optimising the rendering.
Vins for fixing a nasty crash bug and optimising memory usage.
*/
 
namespace irr
{
namespace scene
{
 
class CGridSceneNode : public ISceneNode
{
public:
    //! Constructor
    CGridSceneNode(ISceneNode* parent, ISceneManager* smgr, s32 id = -1, 
        u32 spacing = 8, u32 size = 1024, video::SColor gridcolor = video::SColor(255,128,128,128),
        u32 accentlineoffset = 8, video::SColor accentgridcolor = video::SColor(255,192,192,192),
        bool axislinestate = false);
 
    //! Will create a copy of this scenenode and it's settings
    virtual CGridSceneNode* clone(ISceneNode* newParent = 0, ISceneManager* newSceneManager = 0);
 
    //! Pre-Register stuff
    virtual void OnRegisterSceneNode();
 
    //! Render our grid using 3D lines stored inside the internal meshbuffer
    virtual void render();
 
    //! Returns our bounding box
    virtual const core::aabbox3d<f32>& getBoundingBox() const;
 
    //! Returns the total number of materials, in this case, only 1
    virtual u32 getMaterialCount();
 
    //! Returns the only material
    virtual video::SMaterial& getMaterial(u32 i);
 
    //! Will cause the grid scene node to rebuild it's grid
    void RegenerateGrid();
 
    //! Returns the Spacing of the grid
    u32 GetSpacing();
 
    //! Returns the total size of the grid
    u32 GetSize();
 
    //! Returns the Grid Color
    video::SColor GetGridColor();
 
    //! Returns the offset of the accent lines
    u32 GetAccentlineOffset();
 
    //! Returns the Accent Line Color
    video::SColor GetAccentlineColor();
 
    //! Returns the Active State of the Axis Lines
    bool AreAxisLineActive();
 
    //! Returns the Color of the "X" axis lines
    video::SColor GetAxisLineXColor();
 
    //! Returns the Color of the "Z" axis lines
    video::SColor GetAxisLineZColor();
 
    //! Sets Spacing
    void SetSpacing(u32 newspacing);
 
    //! Sets Size
    void SetSize(u32 newsize);
 
    //! Sets the general grid color
    void SetGridColor(video::SColor newcolor);
 
    //! Sets the offset for the accent lines
    //! If > 0, accent lines will be active, otherwise not
    void SetAccentlineOffset(u32 newoffset);
 
    //! Sets the color of the accent lines
    void SetAccentlineColor(video::SColor newcolor);
 
    //! Sets whether the lines denoting the center of the grid are active
    void SetAxisLineActive(bool active);
 
    //! Sets the Color of the "X" axis lines
    void SetAxisLineXColor(video::SColor XLine);
    
    //! Sets the Color of the "Z" axis lines
    void SetAxisLineZColor(video::SColor ZLine);
 
    //! Allows for setting a complete new material
    void SetMaterial(video::SMaterial newMaterial);
 
private:
    u32 m_spacing;
    u32 m_size;
    video::SColor m_gridcolor;
    video::SColor m_accentgridcolor;
    u32 m_accentlineoffset;
    bool m_AxisLineState;
    video::SColor m_XLineColor;
    video::SColor m_YLineColor;
    video::SColor m_ZLineColor;
 
    //irr::scene::CMeshBuffer Buffer;
    std::shared_ptr<irr::scene::CMeshBuffer<irr::video::S3DVertex>> m_buffer;
};
 
};
};
 
#endif // __C_GRID_SCENE_NODE_H__
 
 
 
CGridSceneNode.cpp
http://pastebin.com/iMdEzM4D

Code: Select all

 
#include "CGridSceneNode.h"
#include "ISceneManager.h"
#include "IVideoDriver.h"
 
namespace irr
{
namespace scene
{
CGridSceneNode::CGridSceneNode(ISceneNode* parent, ISceneManager* smgr, s32 id, 
        u32 spacing, u32 size, video::SColor gridcolor, u32 accentlineoffset, 
        video::SColor accentgridcolor, bool axislinestate)  : ISceneNode(parent, smgr, id), 
        m_spacing(spacing), m_size(size), 
        m_gridcolor(gridcolor), m_accentgridcolor(accentgridcolor),
        m_accentlineoffset(accentlineoffset), m_AxisLineState(axislinestate),
        m_XLineColor(video::SColor(255,255,0,0)), m_ZLineColor(video::SColor(255,0,0,255)), m_YLineColor(video::SColor(255,0,255,0)),
        m_buffer(std::make_shared<irr::scene::CMeshBuffer<irr::video::S3DVertex>>(DeviceContainer::driver->getVertexDescriptor(0)))
{
    // Set the material
    m_buffer->Material.Wireframe = false;
    m_buffer->Material.Lighting = false;
    m_buffer->Material.Thickness = 1;
    m_buffer->Material.FogEnable = false;
    m_buffer->Material.ZWriteEnable = false;
    m_buffer->Material.BackfaceCulling = true;
    m_buffer->Material.AntiAliasing = true;
 
    // Set the default culling state to Frustum Box
    AutomaticCullingState = EAC_FRUSTUM_BOX;
 
    RegenerateGrid();
}
 
CGridSceneNode* CGridSceneNode::clone(ISceneNode *newParent, ISceneManager *newSceneManager)
{
    if (!newParent) newParent = Parent;
    if (!newSceneManager) newSceneManager = SceneManager;
 
    CGridSceneNode* clone = new CGridSceneNode(
        Parent,
        SceneManager,
        ID,
        m_spacing,
        m_size*2,
        m_gridcolor,
        m_accentlineoffset,
        m_accentgridcolor,
        m_AxisLineState);
 
    if (!clone)
        return 0x0;
 
    clone->SetAxisLineXColor(m_XLineColor);
    clone->SetAxisLineZColor(m_ZLineColor);
    clone->SetMaterial(m_buffer->Material);
 
    clone->drop();
    return clone;
}
 
void CGridSceneNode::OnRegisterSceneNode()
{
    if (IsVisible)
        SceneManager->registerNodeForRendering(this);
 
    ISceneNode::OnRegisterSceneNode();
}
 
void CGridSceneNode::RegenerateGrid()
{
    //Clean up memory
    m_buffer->getIndexBuffer()->clear();
    m_buffer->getVertexBuffer()->clear();
 
    u32 m_numVertices = ((m_size / m_spacing) + 1) * 2 * 2;
    if (m_accentlineoffset) m_numVertices += ((m_size / (m_spacing * m_accentlineoffset)) + 1) * 2 * 2;
 
    if ( m_numVertices > 65535)
    {
        //Too many vertices on 16 bit for for 16bit indices of SMeshBuffer
        //Returning with a blank buffer to avoid segfaulting the entire application
        return;
    }
 
    //Set our left corner
    core::vector3df leftMost = core::vector3df(0,0,0);
    leftMost.X -= m_size/2;
    leftMost.Z -= m_size/2;
 
    //Set our right corner
    core::vector3df rightMost = core::vector3df(0,0,0);
    rightMost.X += m_size/2;
    rightMost.Z += m_size/2;
 
    u32 indexIndex = 0;
 
    //X-axis lines
    for (u32 x = 0; x <= m_size; x+= m_spacing)
    {
        core::vector3df start = leftMost;
        start.X += x ;
 
        core::vector3df end = rightMost;
        end.X = start.X;
 
        m_buffer->getVertexBuffer()->addVertex(&video::S3DVertex(start, core::vector3df(0,1,0), m_gridcolor, core::vector2df(0.0f, 0.0f)));
        m_buffer->getVertexBuffer()->addVertex(&video::S3DVertex(end, core::vector3df(0,1,0), m_gridcolor, core::vector2df(0.0f, 0.0f)));
 
        m_buffer->getIndexBuffer()->addIndex(indexIndex++);
        m_buffer->getIndexBuffer()->addIndex(indexIndex++);
    }
 
    //Z-axis lines
    for (u32 z = 0; z <= m_size; z+= m_spacing)
    {
        core::vector3df start = leftMost;
        start.Z += z ;
 
        core::vector3df end = rightMost;
        end.Z = start.Z;
 
        m_buffer->getVertexBuffer()->addVertex(&video::S3DVertex(start, core::vector3df(0,1,0), m_gridcolor, core::vector2df(0.0f, 0.0f)));
        m_buffer->getVertexBuffer()->addVertex(&video::S3DVertex(end, core::vector3df(0,1,0), m_gridcolor, core::vector2df(0.0f, 0.0f)));
 
        m_buffer->getIndexBuffer()->addIndex(indexIndex++);
        m_buffer->getIndexBuffer()->addIndex(indexIndex++);
    }
 
    //Accent lines are only drawn if the offset is greater than 0
    if (m_accentlineoffset > 0)
    {
        //X-axis
        for (u32 x = 0; x <= m_size; x+= m_spacing*m_accentlineoffset)
        {
            core::vector3df start = leftMost;
            start.X += x ;
 
            core::vector3df end = rightMost;
            end.X = start.X;
 
            m_buffer->getVertexBuffer()->addVertex(&video::S3DVertex(start, core::vector3df(0,1,0), m_accentgridcolor, core::vector2df(0.0f, 0.0f)));
            m_buffer->getVertexBuffer()->addVertex(&video::S3DVertex(end, core::vector3df(0,1,0), m_accentgridcolor, core::vector2df(0.0f, 0.0f)));
 
            m_buffer->getIndexBuffer()->addIndex(indexIndex++);
            m_buffer->getIndexBuffer()->addIndex(indexIndex++);
        }
 
        //Z-axis
        for (u32 z = 0; z <= m_size; z+= m_spacing*m_accentlineoffset)
        {
            core::vector3df start = leftMost;
            start.Z += z ;
 
            core::vector3df end = rightMost;
            end.Z = start.Z;
            m_buffer->getVertexBuffer()->addVertex(&video::S3DVertex(start, core::vector3df(0,1,0), m_accentgridcolor, core::vector2df(0.0f, 0.0f)));
            m_buffer->getVertexBuffer()->addVertex(&video::S3DVertex(end, core::vector3df(0,1,0), m_accentgridcolor, core::vector2df(0.0f, 0.0f)));
 
            m_buffer->getIndexBuffer()->addIndex(indexIndex++);
            m_buffer->getIndexBuffer()->addIndex(indexIndex++);
        }
    }
 
 
    // Create our box, it is the size of the grid exactly, plus 1 in the Y axis
    m_buffer->BoundingBox = core::aabbox3df(-(f32)m_size/2,-0.5f,-(f32)m_size/2,(f32)m_size/2,0.5f,(f32)m_size/2);
}
 
void CGridSceneNode::render()
{
    video::IVideoDriver* driver = SceneManager->getVideoDriver();
 
    //Prep to render
    if (driver)
    {
        driver->setMaterial(m_buffer->Material);
        driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
 
        driver->drawVertexPrimitiveList(false, m_buffer->getVertexBuffer(), false, m_buffer->getIndexBuffer(), m_buffer->getVertexBuffer()->getVertexCount()/2, scene::EPT_LINES);
        
        // Axis Lines are only drawn if the State is true
        if (m_AxisLineState)
        {
            m_buffer->Material.Thickness = 3;
            driver->setMaterial(m_buffer->Material);
            driver->draw3DLine(core::vector3df(0,0,0),core::vector3df(0.5f,0,0), m_XLineColor);
            driver->draw3DLine(core::vector3df(0,0,0),core::vector3df(0,0.5f,0), m_YLineColor);
            driver->draw3DLine(core::vector3df(0,0,0),core::vector3df(0,0,0.5f), m_ZLineColor);
            m_buffer->Material.Thickness = 1;
            driver->setMaterial(m_buffer->Material);
        }
    }
}
 
const core::aabbox3d<f32>& CGridSceneNode::getBoundingBox() const
{
    return m_buffer->BoundingBox;
}
 
u32 CGridSceneNode::getMaterialCount()
{
    return 1;
}
 
video::SMaterial& CGridSceneNode::getMaterial(u32 i)
{
    return m_buffer->Material;
}
 
u32 CGridSceneNode::GetSpacing()
{
    return m_spacing;
}
 
u32 CGridSceneNode::GetSize()
{
    return m_size;
}
 
u32 CGridSceneNode::GetAccentlineOffset()
{
    return m_accentlineoffset;
}
 
video::SColor CGridSceneNode::GetAccentlineColor()
{
    return m_accentgridcolor;
}
 
video::SColor CGridSceneNode::GetGridColor()
{
    return m_gridcolor;
}
 
bool CGridSceneNode::AreAxisLineActive()
{
    return m_AxisLineState;
}
 
video::SColor CGridSceneNode::GetAxisLineXColor()
{
    return m_XLineColor;
}
 
video::SColor CGridSceneNode::GetAxisLineZColor()
{
    return m_ZLineColor;
}
 
void CGridSceneNode::SetSpacing(u32 newspacing)
{
    m_spacing = newspacing;
    RegenerateGrid();
}
 
void CGridSceneNode::SetSize(u32 newsize)
{
    m_size = newsize;
    RegenerateGrid();
}
 
void CGridSceneNode::SetAccentlineColor(video::SColor newcolor)
{
    m_accentgridcolor = newcolor;
    RegenerateGrid();
}
 
void CGridSceneNode::SetAccentlineOffset(u32 newoffset)
{
    m_accentlineoffset = newoffset;
    RegenerateGrid();
}
 
void CGridSceneNode::SetGridColor(video::SColor newcolor)
{
    m_gridcolor = newcolor;
    RegenerateGrid();
}
 
void CGridSceneNode::SetAxisLineActive(bool active)
{
    m_AxisLineState = active;
}
 
void CGridSceneNode::SetAxisLineXColor(video::SColor XLine)
{
    m_XLineColor = XLine;
}
 
void CGridSceneNode::SetAxisLineZColor(video::SColor ZLine)
{
    m_ZLineColor = ZLine;
}
 
void CGridSceneNode::SetMaterial(video::SMaterial newMaterial)
{
    m_buffer->Material = newMaterial;
}
};
};
 
 
 
CuteAlien
Admin
Posts: 9646
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Editor style Grid SceneNode [Updated: Sept. 27, 2009]

Post by CuteAlien »

Thanks!

edit: How comes your CMeshBuffer has functions like getIndexBuffer, are you working with a modified Irrlicht version? Or maybe it was that way in older Irrlicht versions before CDynamicMeshBuffer was introduced.

edit: Slightly modified version which compiles with Irrlicht 1.8 and fixes a memory leak (but still not const-correct):
CGridSceneNode.h: http://ideone.com/SqcYQL
CGridSceneNode.cpp: http://ideone.com/2GMAdK
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
CuteAlien
Admin
Posts: 9646
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Editor style Grid SceneNode [Updated: Sept. 27, 2009]

Post by CuteAlien »

I made another version which rewrites a lot of stuff. Instead of accent-lines you can have several grids with different spacing.
CGridSceneNode.h: http://ideone.com/vV0NIR
CGridSceneNode.cpp: http://ideone.com/5XxGiy

(edit: Sorry for horrible indention, there's a messy mix of whitespace and tabs in that file right now)
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
Ultraporing
Posts: 34
Joined: Tue Nov 06, 2007 7:22 pm
Location: Würzburg, Germany

Re: Editor style Grid SceneNode [Updated: Sept. 27, 2009]

Post by Ultraporing »

Thank you, thats exactly what i was looking for.
Can I somehow project this grid on top of my terrain? Because I like to use it to place objects and let the player select cells.

thanks Ultraporing
CuteAlien
Admin
Posts: 9646
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Editor style Grid SceneNode [Updated: Sept. 27, 2009]

Post by CuteAlien »

I've by now made a new version of this:
CGridSceneNode.h: http://ideone.com/f7pdad
CGridSceneNode.cpp: http://ideone.com/Av76mw

Example:

Code: Select all

 
 
#include <irrlicht.h>
#include "CGridSceneNode.h"
 
using namespace irr;
using namespace core;
 
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
 
int main()
{
    IrrlichtDevice *  Device = createDevice(irr::video::EDT_OPENGL, irr::core::dimension2d<irr::u32>(800,600));
    if (!Device)
        return false;
   
    scene::ISceneManager* smgr = Device->getSceneManager();
    video::IVideoDriver * videoDriver = Device->getVideoDriver ();
   
    irr::scene::ICameraSceneNode * camera = smgr->addCameraSceneNodeFPS(0, 20.f, 0.1f );
 
    CGridSceneNode * gridSceneNode = new CGridSceneNode(smgr->getRootSceneNode(), smgr, -1, 1);
    gridSceneNode->setGridsSize( irr::core::dimension2df(2500, 2500));
    gridSceneNode->getGrid(0).setSpacing( 100.f );
    gridSceneNode->getGrid(0).setGridColor(irr::video::SColor(255, 100, 255, 100));
    gridSceneNode->drop();  // added to scene already, that still has a reference
 
    while ( Device->run() )
    {
        if ( Device->isWindowActive() )
        {
            videoDriver->beginScene(true, true);
 
            smgr->drawAll();
 
            videoDriver->endScene();
        }
 
        Device->sleep( 5 );
    }
 
    Device->closeDevice();
    Device->drop();
    Device = NULL;
 
    return 0;
}
 
Changed a lot to last versions. Grid is calculated a little different now and draw always to the full width/height given. Also you can have more than one grid now for example for different resolutions with different colors.
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
chronologicaldot
Competition winner
Posts: 685
Joined: Mon Sep 10, 2012 8:51 am

Re: Editor style Grid SceneNode [Updated: Sept. 27, 2009]

Post by chronologicaldot »

Nice! Good to see this project still alive.

I'm curious, though, in hasDirtyBoundingBox() (and hasDirtyGrid() ) you do the following:

Code: Select all

 
bool hasDirty = false;
for ( irr::u32 i=0; i<Grids.size(); ++i )
{
        if ( Grids[i].BoundingBoxDirty )
        {
                hasDirty = true;
                break;
        }
}
return hasDirty;
 
Why not just shorten it to:

Code: Select all

 
for ( irr::u32 i=0; i<Grids.size(); ++i )
{
        if ( Grids[i].BoundingBoxDirty )
              return true;
}
return false;
 
or is that going to mess with your compiler?
CuteAlien
Admin
Posts: 9646
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Editor style Grid SceneNode [Updated: Sept. 27, 2009]

Post by CuteAlien »

No, that would be better indeed. I had the code first in some loops inside another function where the flag was useful and didn't care when I moved it inside the ::hasDirty functions.
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