PDA

View Full Version : Creating teapot more than once

Orange_82
06-01-2004, 06:45 AM
Hi, i need to know how to create more than 1 teapot in Borland C

Regards,
Orange_82

SirKnight
06-01-2004, 07:50 AM

for( int i = 0; i < numTeapots; ++i )
teapot_array[i] = CreateTeapot();-SirKnight

Orange_82
06-02-2004, 06:03 AM
Originally posted by SirKnight:

for( int i = 0; i < numTeapots; ++i )
teapot_array[i] = CreateTeapot();-SirKnightYa, I know sorry, i didn't put in the whole question. What I meant is creating 16 teapots and perform translation on them.

nexusone
06-02-2004, 06:10 PM
What function are you using to draw the teapot?

This example will work under any C/C++ compiler:

glPushMatrix();
glTranslatef( 0,0,0); // location of first teapot
glutSolidTeapot(1); // Draw teapot
glPopMatrix();

glPushMatrix();
glTranslatef( 1,0,0); //location of second teapot
glutSolidTeapot(1);
glPopMatrix();
// repeat above with a new location for each teapot.

Originally posted by Orange_82:
Hi, i need to know how to create more than 1 teapot in Borland C

Regards,
Orange_82

Orange_82
06-02-2004, 08:54 PM
Originally posted by nexusone:
What function are you using to draw the teapot?

This example will work under any C/C++ compiler:

glPushMatrix();
glTranslatef( 0,0,0); // location of first teapot
glutSolidTeapot(1); // Draw teapot
glPopMatrix();

glPushMatrix();
glTranslatef( 1,0,0); //location of second teapot
glutSolidTeapot(1);
glPopMatrix();
// repeat above with a new location for each teapot.

Originally posted by Orange_82:
Hi, i need to know how to create more than 1 teapot in Borland C

Regards,
Orange_82Ermm, i am creating 16 teapots. And I am thinking of using arrays for the glTranslatef but I am not good @ arrays, do you think you can tell me how 2 do it?

CrazyButcher
06-02-2004, 11:21 PM
try to familiarize yourself with arrays as soon as possible, its absolutely crucial to programming !

anyway how do you want to arrange your teapots ?
like a 4x4 square, or how ?

4x4 square would be easiest with

for (x = 0; x < 4; x++){
for (y = 0; y < 4; y++){
glPushMatrix();
glTranslatef( x*2,y*2,0); // location with gaps of 2
glutSolidTeapot(1); // Draw teapot
glPopMatrix();
}
}if you use a single array to store the teapots positions like 16 * 3 floats
e.g.
GLfloat teaPos = {0,0,1, 0,0,2 ,0,0,3 ...};

you could do

for (i = 0; i < 16; i++){
glPushMatrix();
glTranslatef(teaPos[i*3],teaPos[i*3+1],teaPos[i*3+2]); // location
glutSolidTeapot(1); // Draw teapot
glPopMatrix();
}