部屋を自分の周りで回転させるのに問題があります。その中心は (5,5,0) にあるので、部屋と部屋のオブジェクトを glTranslatef(5,5,5) で移動し、次に glRotatef(rotateroom,0,0,1) で移動してからアイテムを描画すると考えましたglTranslate(-5,-5,0) を使用すると、部屋とその中のすべてが 5,5,0 を中心に回転しますが、まだ (0,0,0) を中心に回転しているように見えます。私は間違っている。事前に助けてくれてありがとう。
void drawside(){
int i,j;
/*for (j = 0; j <= 8; j++) {
glBegin(GL_LINE_STRIP);
for (i = 0; i <= 30; i++)
glEvalCoord2f((GLfloat)i/30.0, (GLfloat)j/8.0);
glEnd();
glBegin(GL_LINE_STRIP);
for (i = 0; i <= 30; i++)
glEvalCoord2f((GLfloat)j/8.0, (GLfloat)i/30.0);
glEnd();
}*/
glEvalMesh2(GL_FILL, 0, 20, 0, 20);
}
void drawRoom(){
//floor
glBegin(GL_POLYGON);
glColor3f(1,1,1);
glNormal3f(0,0,0);
glVertex3f(0,0,0);
glNormal3f(0,10,0);
glVertex3f(0,10,0);
glNormal3f(10,10,0);
glVertex3f(10,10,0);
glNormal3f(10,0,0);
glVertex3f(10,0,0);
glEnd(
);
//wall
glBegin(GL_POLYGON);
glColor3f(0,0,1);
glNormal3f(0,10,0);
glVertex3f(0,10,0);
glNormal3f(0,10,10);
glVertex3f(0,10,10);
glNormal3f(10,10,10);
glVertex3f(10,10,10);
glNormal3f(10,10,0);
glVertex3f(10,10,0);
glEnd();
//wall2
glBegin(GL_POLYGON);
glColor3f(0,1,0);
glNormal3f(10,10,0);
glVertex3f(10,10,0);
glNormal3f(10,10,0);
glVertex3f(10,10,10);
glNormal3f(10,0,10);
glVertex3f(10,0,10);
glNormal3f(10,0,0);
glVertex3f(10,0,0);
glEnd();
}
void drawObjects(){
glColor3f(1,0,1);
glTranslatef(2,2,0);
if(conefill == 1)
glShadeModel(GL_FLAT);
else
glShadeModel(GL_SMOOTH);
glutSolidCone(cone,5,10,2);
glTranslatef(5,5,0);
glColor3f(1,0,0);
if(spherefill == 1)
glShadeModel(GL_FLAT);
else
glShadeModel(GL_SMOOTH);
glutSolidSphere(sphere,20,20);
}
void display(){
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(viewx,viewy, viewz,viewx +lx, 5, viewz + ly,0.0f, 0.0f, 1.0f);
//gluLookAt(viewx,viewy,viewz,headup,headright,5,0,0,1);
glClear(GL_COLOR_BUFFER_BIT);
GLfloat light_position[] = {-1.0,5.0,5.0,0.0};
//GLfloat light_direction[] = {-5,-5,-5};
//GLfloat amb[] = {0,0,0,1};
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
//glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION,light_direction);
//glLightfv(GL_LIGHT0, GL_AMBIENT,amb);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(5,5,0);
glRotatef(rotateroom,0,0,1);
glPushMatrix();
drawRoom();
glPopMatrix();
glColor3f(0.0, 0.0, 1.0);
glPushMatrix();
glTranslatef(6,3,1);
glPushMatrix ();
drawside();
glPopMatrix();
glPushMatrix();
//glTranslatef(5,0,0);
glRotatef(90,1,0,0);
//glTranslatef(-5,0,0);
glTranslatef(0,.5,.5);
drawside();
glPopMatrix();
glPushMatrix();
//glTranslatef(5,0,0);
glRotatef(180,1,0,0);
//glTranslatef(-5,0,0);
glTranslatef(0,1,0);
drawside();
glPopMatrix();
glPushMatrix();
glRotatef(90,0,0,1);
glTranslatef(-.5,.5,0);
drawside();
glPopMatrix();
glPushMatrix();
glRotatef(270,0,0,1);
glTranslatef(.5,.5,0);
drawside();
glPopMatrix();
glPopMatrix();
drawObjects();
glTranslatef(-5,-5,0);
glPopMatrix();
glutSwapBuffers();
glFlush();
}