I was getting tired of a blank screen for my test progies .. so i took the two minutes and wrote a grid class... for drawing XZ grid
the shot is the grid class quickly hacked on top of the Tutorial 1 codebase...
Here is the code.
Code: Select all
class Grid
{
public:
Grid():center(0,0,0),sizeHalf(1000),gridSpacing(50)
{
mtl.Lighting = false;
mtl.AmbientColor = mtl.DiffuseColor = mtl.EmissiveColor = video::SColor(255,0,200,0);
}
virtual ~Grid()
{
}
void draw(scene::ISceneManager* smgr)
{
core::vector3df leftMost = center;
leftMost.X -= sizeHalf;
leftMost.Z -= sizeHalf;
core::vector3df rightMost = center;
rightMost.X += sizeHalf;
rightMost.Z += sizeHalf;
smgr->getVideoDriver()->setMaterial(mtl);
//cout<<"
for(f32 x = 0; x <= 2 * sizeHalf; x+= gridSpacing)
{
vector3df start = leftMost;
start.X += x ;
vector3df end = rightMost;
end.X = start.X;
//cout<<"Drawing Line From : "<<start.X<<","<<start.Y<<","<<start.Z<<" to "<<end.X<<","<<end.Y<<","<<end.Z<<endl;
smgr->getVideoDriver()->draw3DLine(start,end,mtl.AmbientColor);
}
//cout<<endl;
for(f32 z = 0; z <= 2 * sizeHalf; z+= gridSpacing)
{
vector3df start = leftMost;
start.Z += z ;
vector3df end = rightMost;
end.Z = start.Z;
smgr->getVideoDriver()->draw3DLine(start,end,mtl.AmbientColor);
}
}
core::vector3df center;
f32 sizeHalf;
f32 gridSpacing;
SMaterial mtl;
};
Code: Select all
driver->beginScene(true, true, SColor(20,0,0,0));
smgr->drawAll();
grid.draw(smgr);
guienv->drawAll();
driver->endScene();