Skip to main content
GameDev.net gamedev.net
🔒 Locked

Actor class...

Started by ZitherMan Jul 27, 2002 at 9:17 AM 1 replies 350+ views
Original Post
ZitherMan
ZitherMan
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
----------------------------
When hell freez
Neosmyle
Neosmyle
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
TheGilb
TheGilb
www.bruceeckel.com ;D


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.