PDA

View Full Version : Grouing Primitives for an Object... please help!



mystro
11-04-2005, 08:38 AM
Hi,
I am creating a 2D object using different primitives, namely; 2 Polygons and a Curve. I have put the drawing commands for each primitive in its own void function. Within each function there are also translation commands (along with glLoadIdentity), so that it is in the right place on the overall object. I then call each of the functions at render() and it renders them all out in the specified locations.

However....
I need to translate the object and create other instances of it. I could to this by copying the functions and renaming them, then changing the translation functions within each object. However this seems wastefull and tedious. Is there any way I can make it so that I can use one translation function for the whole object, not each primitive.

Maybe I need to use Pop and Push Matrix but im not sure where I would call them.

Your help would be much appreciated, and needed!
Thanks,
Jay

songho
11-04-2005, 09:10 AM
mystro,
I understand why you put glLoadIdentity() in your draw functions for each object, however, it is not necessary. Because the object is already in initial object coordinates. In other words, you don't need re-initialize matrix.

If you want duplicate(instantiate) it and place them into different positions, the code might look like this;


void drawAll()
{
// draw the object at position #1
glPushMatrix();
glTranslate2fv(p1);
drawObject();
glPopMatrix();

// draw the same object at position #2
glPushMatrix();
glTranslate2fv(p2);
drawObject();
glPopMatrix();

.... // draw more
}==song==