Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Jonus

Some help on Scenegraph please.

This topic is 5907 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


  
// ------------------------------------------------------ //

// --------------- 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(){}
	};

}  
Is that a good start? It reminds me a bit on the composite pattern. Any Suggestions? Recomendations?

Share this post


Link to post
Share on other sites
Advertisement
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;

headnode
|
---- LightNode
|
--- Material node
|
---- Transform node
|
--- Drawable



wow that was long as well.. hope that helps..

Share this post


Link to post
Share on other sites
Thanks - great input.

I will sleep over it, programm again, and the repost my class hirarchy.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!