breaking down the tasks into classes - that’s a great place to start.
but it’s not quiet object-oriented design [yet].
consider this [with your examples in mind]:
for the sake of keeping this short but thorough, let us ask the rhetorical question: is a flower a kind of tree? is a tree a kind of flower?
having to think about it, I think it’s a better idea to consider flowers and trees a kind of plant. so let’s declare the plant class
class plant
{
protected:
float x, y, z; // plant's 3D position
public:
plant();
void draw_plant()
{
// let's pretend that this function
// just draws a stem and nothing
// else.
}
void draw()
{
// call draw_plant to draw the plant.
// [there is a point to having this
// function, you'll see it later]
draw_plant();
}
// ommitted functions
~plant();
};
ok so with our plant class we have the means to draw a plant. being that a flower is a kind of plant, let’s extend the plant class.
class flower : public plant
{
public:
// ...
void draw_petal()
{
// draws a petal of the flower
}
void draw_flower()
{
// just as an example, maybe use a for-loop
// to draw petals of the flower
for (...)
{
glRotatef(...);
draw_petal();
}
}
void draw()
{
draw_flower();
draw_plant();
// together, the two functions draw the flower
// and the stem
}
// ...
};
for the tree, you’d do pretty much the same thing, with a little difference:
class tree : public plant
{
public:
// ...
void draw_leaves()
{
// draws leaves
}
// ditto...
void draw_branches();
void draw()
{
// you get the idea
for (...)
{
draw_branches();
draw_leaves();
}
}
// ...
};
and to tie it all together, you can do something like this in your program:
// wherever you declared your variables
tree myTree[10];
flower myFlower[10];
// ...
// whatever function you use to draw the entire scene
for (int i = 0; i < 10; i++)
{
myTree[i].draw(); // draws trees
myFlower[i].draw(); // draws flowers
}
and with that you can cleverly change each “object” or “plant’s” position by changing their x, y, and z values.
the important thing to notice is, you’ve made each “thing” an “object”. and by identifying objects are the first steps in object-oriented design. next is their relationships/inheritance, and then their interactions. if this is new to you, definitely look it up - it’s great stuff and an interesting approach to programming.
i know this was long but i hope it is understandable.
:regards: