Jump to content
  • Advertisement

Archived

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

ZitherMan

Actor class...

This topic is 5980 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

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
Advertisement
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

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!