// ------------------------------------------------------ //
// --------------- Scene Graph V.ALPHA.00 --------------- //
// ------------------------------------------------------ //
#include <vector>
namespace sg
{
// ------------------------------------------------------
class drawable
{
public:
GLdouble xp,yp,zp;
GLdouble angle,xr,yr,zr;
virtual void draw(){}
virtual void glRotated(GLdouble angle,GLdouble x,GLdouble y,GLdouble z){}
virtual void glTranslated(GLdouble x,GLdouble y,GLdouble z){}
drawable():xp(0.0),yp(0.0),zp(0.0),angle(0.0),xr(0.0),yr(0.0),zr(0.0){}
drawable(GLdouble xp,GLdouble yp,GLdouble zp,
GLdouble angle,GLdouble xr,GLdouble yr,GLdouble zr)
:xp(xp),yp(yp),zp(zp),angle(angle),xr(xr),yr(yr),zr(zr){}
virtual ~drawable(){}
};
// ------------------------------------------------------
class Group : public drawable
{
private:
std::vector<drawable*>avector;
std::vector<drawable*>::iterator j;
public:
void addDrawable(drawable* nd)
{
avector.push_back(nd);
}
void draw()
{
j = avector.begin();
while (j != avector.end())
{
(*j)->draw();
j++;
}
}
~Group()
{
j = avector.begin();
while (j != avector.end())
{
delete(*j);
j++;
}
avector.clear();
}
};
// ------------------------------------------------------
class Triangle : public drawable
{
public:
void draw(){
glBegin (GL_TRIANGLES);
glColor3f (1.f, 0.f, 0.f); glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f (0.f, 1.f, 0.f); glVertex3f(-1.0f,-1.0f, 1.0f);
glColor3f (0.f, 0.f, 1.f); glVertex3f( 1.0f,-1.0f, 1.0f);
glEnd ();
}
~Triangle(){}
};
// ------------------------------------------------------
class Quad : public drawable
{
public:
void draw(){/*later*/}
~Quad(){}
};
class Mesh : public drawable
{
public:
void draw(){/*later*/}
~Mesh(){}
};
}
Some help on Scenegraph please.
grr, wrote a quite long reply and lost it.. so this one will be shorter
- I would suggest seperating data and drawing method. so that one day you can support D3D easily; make a pure abstract class, say Renderer, derive a GLRenderer, and implement your draw() function in there..
- Usually, you should put everything in the engine as seperate nodes to the scene. so derive your drawable class from a base class, say Node, and also derive other classes such as Transform, Light, Material from Node as well. Which means you take away your angle, and other transformation related stuff out of the class drawable.
- Your Node class can also implement tree/graph structure. So everything is stored hierarchicaly. I mean each node can have children nodes, add and remove them, etc..
example of a scene;
wow that was long as well.. hope that helps..
- I would suggest seperating data and drawing method. so that one day you can support D3D easily; make a pure abstract class, say Renderer, derive a GLRenderer, and implement your draw() function in there..
- Usually, you should put everything in the engine as seperate nodes to the scene. so derive your drawable class from a base class, say Node, and also derive other classes such as Transform, Light, Material from Node as well. Which means you take away your angle, and other transformation related stuff out of the class drawable.
- Your Node class can also implement tree/graph structure. So everything is stored hierarchicaly. I mean each node can have children nodes, add and remove them, etc..
example of a scene;
headnode | ---- LightNode | --- Material node | ---- Transform node | --- Drawable
wow that was long as well.. hope that helps..
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement