My problem is, I've created my Grid3DSceneNode, whose code is below...
Code: Select all
#ifndef GRID3DSCENENODE_H_
#define GRID3DSCENENODE_H_
#include <irrlicht.h>
using namespace irr;
class Grid3DSceneNode : public irr::scene::ISceneNode
{
public:
//constructor takes three ints, the position of the grid, and
//specifying the grid's dimensions, then a color.
Grid3DSceneNode(scene::ISceneNode* parent, scene::ISceneManager *smgr,
int rows, int columns, int depth, s32 id=-1,
core::vector3df pos = core::vector3df(0.0f,0.0f,0.0f), //default in centre of place
video::SColor newCol = video::SColor(255,255,255,255 ));
virtual ~Grid3DSceneNode();
virtual void render() //overrides pure virtual method render()=0
{
//it is possible to render 2d grids with this one- if one dimension is given value zero.
if (x<0 || y<0 || z<0)
return; //not rendered.
video::IVideoDriver *driver = SceneManager->getVideoDriver();
driver->setTransform(video::ETS_WORLD, core::matrix4());
//There are three planes: the xy plane, the yz plane and the xz plane.
//draw on the xy plane, xy times, along z.
for (int i = 0; i <= x; ++i) {
for (int j = 0; j <= y; ++j) {
driver->draw3DLine(
core::vector3df(i,j,0) + getPosition(),
core::vector3df(i,j,z) + getPosition(),
col
);
}
}
//draw on the yz plane yz times, along x
for (int j = 0; j <= y; ++j) {
for (int k = 0; k <= z; ++k) {
driver->draw3DLine(
core::vector3df(0,j,k) + getPosition(),
core::vector3df(x,j,k) + getPosition(),
col
);
}
}
//draw on the xz plane xz times, along y
for (int i = 0; i <= x; i++) {
for (int k = 0; k <= z; ++k) {
driver->draw3DLine(
core::vector3df(i,0,k) + getPosition(),
core::vector3df(i,y,k) + getPosition(),
col
);
}
}
}
virtual const core::aabbox3df& getBoundingBox() const
{
return Box;
}
virtual void OnRegisterSceneNode()
{
if (IsVisible)
SceneManager->registerNodeForRendering(this);
scene::ISceneNode::OnRegisterSceneNode();
}
virtual void resize(int newRows, int newColumns, int newDepth)
{
x = newRows;
y = newColumns;
z = newDepth;
Box = core::aabbox3df(
getPosition().X,getPosition().X+x,
getPosition().Y,getPosition().Y+y,
getPosition().Z,getPosition().Z+z
);
}
virtual core::vector3df getCenter(){
return ( core::vector3df(x/2,y/2,z/2)+getPosition() );
}
video::SColor getColor() const {
return col;
}
void setColor(video::SColor newCol){
col= newCol;
}
private:
int x,y,z;
video::SColor col; //the color of this grid
core::aabbox3df Box; //the box!
};
#endif /*GRID3DSCENENODE_H_*/
I built a little app to see it working in practise. It is basically the 04. Movement example without the animated mesh of sydney: There's a textured sphere and a cube orbiting it.
When I run my little app, with the main loop like the following:
Code: Select all
video::SColor gridColor(129,255,255,255);
Grid3DSceneNode *gridNode = new Grid3DSceneNode(smgr->getRootSceneNode(), smgr,5,4,3);
gridNode->setColor(gridColor);
while(device->run())
{
//Makes the driver ready for drawing
driver->beginScene(true, true, video::SColor(255,113,113,133));
smgr->drawAll(); // draw the 3d scene
device->getGUIEnvironment()->drawAll(); // draw the gui environment (the logo)
driver->endScene();
fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw tmp =L"Movement Example - Irrlicht Engine [";
tmp += driver->getName();
tmp += L"] fps: ";
tmp += fps;
device->setWindowCaption(tmp.c_str());
lastFPS = fps;
}
}
Why might that be?? It's not culling is it?
Note the grid is drawn with the infamous video driver method draw3DLine()... the world transform was set before the lines were drawn... etc.
Thanks!