PDA

View Full Version : Two teapots!



GracefulEase
04-20-2009, 08:30 AM
In advance, thank you for any and all help! Basically all I want to do is be able to 'create' up to 5 Teapots whilst running, and control each of them separately. The code I've got so far lets me create one, and control it, but creating a second just replaces the first. Again, thank you for any help!


void display(void)
{
glPushMatrix();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gluLookAt(zoomx,zoomy,5, 0,0,0, 0,1,0);
glLightfv(GL_LIGHT0, GL_POSITION, light0_position);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective (40.0*zoomz, 1, 0.1, 20);

glMatrixMode(GL_MODELVIEW);

mat_shininess[0] = shiny;
mat_specular[0] = specx;
mat_specular[1] = specy;
mat_specular[2] = specz;
mat_specular[3] = specj;
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

if(Teapots==1){
TeapotOne();
}
if(Teapots==2){
TeapotTwo();
}
if(type2!=0)glShadeModel(type2);
glPolygonMode(GL_FRONT_AND_BACK, type);
glPopMatrix();
glutSwapBuffers();
}

void TeapotOne(){
if(selected==1){
glTranslatef(tranx ,trany,tranz);
glRotatef(rotatex,0,1.0,0);
glRotatef(rotatey,1.0,0,0);
glRotatef(rotatez,0,0,1.0);
glScalef(scalx, scaly, scalz);
}
glutSolidTeapot(0.5);
}
void TeapotTwo(){
if(selected==2){
glTranslatef(tranx ,trany,tranz);
glRotatef(rotatex,0,1.0,0);
glRotatef(rotatey,1.0,0,0);
glRotatef(rotatez,0,0,1.0);
glScalef(scalx, scaly, scalz);
}
glutSolidTeapot(0.5);
}

ZbuffeR
04-20-2009, 11:47 AM
try using this instead :


if(Teapots>=1){
TeapotOne();
}
if(Teapots>=2){
TeapotTwo();
}

that ways, if Teapots=2, both will be drawn.

GracefulEase
04-21-2009, 06:47 AM
So obvious! I can't believe I've missed that! To be fair though, I've been programming three courseworks over 16 hours a day for the last 5 days, so I'm not exactly 'on the ball'! Thanks for the help Zbuffer!

GracefulEase
04-21-2009, 02:31 PM
Okay, so I'm back with another problem!


for(tmp=1; tmp<=39; tmp++){
if(objList[tmp][0]==1) MakeOne(objList[tmp][1]);
}

void MakeOne(int number){
mat_shininess[0] = objVars[number][11];
mat_specular[0] = objVars[number][12];
mat_specular[1] = objVars[number][13];
mat_specular[2] = objVars[number][14];
mat_specular[3] = objVars[number][15];
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glTranslatef(objVars[number][3] ,objVars[number][4],objVars[number][5]);
glRotatef(objVars[number][0],0,1.0,0);
glRotatef(objVars[number][1],1.0,0,0);
glRotatef(objVars[number][2],0,0,1.0);

int temp = objVars[number][16];
glScalef(objVars[number][6], objVars[number][7], objVars[number][8]);
if(objVars[number][10]!=0)glShadeModel(objVars[number][10]);

glPolygonMode(GL_FRONT_AND_BACK, objVars[number][9]);

if(objVars[number][16]==1.0){glutSolidTeapot(0.5);
}
}

In this I use a for loop to call MakeOne() several times. Each MakeOne loads the rotate values, and translation values e.t.c from a huge table. The problem is that any Teapot made after Teapot X is affected whenever Teapot X is affected.

E.g I make Teapot 1 and Teapot 2. If I rotate Teapot 2 its all good, but if I rotate Teapot 1 they BOTH move, even though I am definitely only changing the fields of the array that affect Teapot1. What's the deal? It affects translation, rotation and scale, but not specularness/shininess.

Thanks again for any help!