Hallo,
I am working with adding geometry to a program I am making, and have some questions about the uses of classes.
Here is my class(s) so far. The idea is to have on base class that has the information that is common for all the geometry types, and then have subclasses(?) for the things that are different.
Is this a good way of doing it?Code:class Primitive
{
public:
Primitive();
~Primitive();
void setType(); // ??
void getType(); // ??
void setName(std::string n);
std::string getName();
void setMaterial(Material m);
Material getMaterial();
void setPos(Vector3D pos);
Vector3D getPos();
private:
//type
std::string name;
Material material;
Vector3D position;
};
class sphere : public Primitive
{
public:
void setRadius(float r);
float getRadius();
float getRadiusSqr();
result intersectionTest(Ray r);
private:
float radius;
float radiusSqr;
};
Also, for the setType/getType, how would you do them? I want to be able to do something like:
setType(SPHERE);
and than it knows that that primitive is a sphere. Should I define SPHERE as 1, BOX as 2 and so on, and do it that way?