I'm truly amazed by the idea behind the OOP, since I find it so much easier to think of the classes and the objects, as if they are real ones. I have a base class Tooth and derived classes for the different groups of teeth (they have their specifics). Their constructors are taking as argument the texture, which is drawn; For upper teeth it goes something like this:
class Tooth
{
public:
Tooth(Texture &texture);
};
class Molar : public Tooth { };
class Premolar : public Tooth { };
class Frontal : public Tooth { };
main()
{
Molar *molar[6];
Premolar *premolar[4];
Frontal *frontal[6];
Texture uppertextures[8]; //only 8 textures, since the other half of the teeth are mirrored
Tooth* upperTeeth[16] = { molar[0], molar[1], molar[2], premolar[0], premolar[1], frontal[0], frontal[1], frontal[2], frontal[3], frontal[4], frontal[5], premolar[2], premolar[3], molar[3], molar[4], molar[5] }; // < the order in which the teeth have to be added to the graphic scene;
int x = 0 //for the position of the tooth on the screen;
int texture = 0; //we will need it to assign the textures in order;
for(int i = 0; i<16; i++)
{
upperTeeth[16] = new !?!?!?(uppertextures[i])
upperTeeth[16]->setPositionX(i+x) // some function for setting the position on the screen from left to right;
if(i<8) texture++; //setting the textures for the teeth on the left;
if(i>8) texture--; //setting the textures for the teeth on the right(the same, but in reverse order);
upperTeeth[16]->setPositionY(y)
}
}
As you can see the problem is with the allocation. I want to create new[] the same way I create array of the Base class, and fill in the order of the derived classes, in which the objects appear. Of course if you have completely different solution, you can share it, but that's the most clever way I could think of.