Archived

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

ZitherMan

Actor class...

Recommended Posts

Hey all. I''m making an actor class which several of my moving objects should use. So i start with something simple like:
class actor
{
    int x,y,z;
    GLvoid draw();
};
 
the draw function should draw the objects model, ie. a pyramid. So how would i make this support several models? Thanks /ZitherMan

Share this post


Link to post
Share on other sites
The best way is to derive a class from actor, and to make the draw function virtual.

For example:


class actor
{
public:
union // i would put this in a union for ease of use
{
GLfloat x,y,z;
GLfloat position[3];
};
virtual GLvoid draw();
};

class mesh : public actor
{
public:
mesh(char* filename); //constructor which loads mesh from file
float vertexindex[]; //or put whatever storage system you want
virtual GLvoid draw(); //virtual in case you want to derive
//more mesh classes from mesh
};


With that, you would be able to do something like this


mesh pyramid = new mesh("pyramid.3ds");
mesh box = new mesh("box.3ds");

pyramid.x = 5;
pyramid.y = 5; //these lines do the same thing as
pyramid.z = 5;

box.position = {5, 5, 5}; // this

pyramid.draw();
box.draw(); //draws the meshes


Hope that helped

Share this post


Link to post
Share on other sites