Hello and Good day!
I would like to ask if it is efficient that each glDrawCalls has its own matrix?
e.g:
class Object
{
public:
void draw();
int x;
int y;
int z;
protected:
Object* child;
};
//Implementation # 1
void Object::draw()
{
glPushMatrix();
glTranslatef(x, y, z);
...
glPopMatrix();
//Use separate matrix for every this->child
for (auto &i : child)
{
i->draw();
}
}
//Implementation # 2
void Object::draw()
{
glPushMatrix();
glTranslatef(x, y, z);
...
//Used single matrix on each this->child
for (auto &i : child)
{
i->draw();
}
glPopMatrix();
}
The child I am referring to is/are the object(s) the will be drawn on top of the parent.
The child's coordinate(x, y) will almost always lie on the parent's body.
This implementation is easy to write and easy to comprehend but,
I'm not satisfied because I could have just use glPushMatrix and glPopMatrix once for every parent I will render then glTranslatex a little bit the child object but,
if I do it this way, it'll be hard for me to find the child's coordinate.
For example in a hover effect this would become:
if (obj->contains(parent.x + mouse.x, parent.y + moue.y))
{
//do hover effect!
}
instead of just
if (obj->contains(mouse.x, mouse.y)
{
//do hover effect!
}
I will need an extra calculation for this to achieve and my code will become more messy. What could be the alternative way to figure out the location of each object drawn by the parent?
Thanks and regards