我有一个时钟和一个立方体(作为一个房间)。我想把时钟放在其中一面墙上。但是当我旋转或移动相机时,屏幕上的时钟位置是固定的。我怎样才能在其中一面墙上修理时钟?
void room(){
if(flag){
glRotatef(rt,0.0f,1.0f,0.0f);
}
glEnable(GL_NORMALIZE);
glPushMatrix();
glBegin(GL_QUADS);
glColor3f(1.0, 1.0 ,1.0); //roof(white)
glNormal3f(0,-1,0);
glVertex3f( 3.0, 3.0,-3.0);
glVertex3f(-3.0, 3.0,-3.0);
glVertex3f(-3.0, 3.0, 3.0);
glVertex3f( 3.0, 3.0, 3.0);
glColor3f(1.0, 1.0 ,0.0); // floor(yellow)
glNormal3f(0,1,0);
glVertex3f( 3.0,-3.0, 3.0);
glVertex3f(-3.0,-3.0, 3.0);
glVertex3f(-3.0,-3.0,-3.0);
glVertex3f( 3.0,-3.0,-3.0);
glColor3f(1.0, 0.0 ,0.0); // front (red)
glNormal3f(0,0,-1);
glVertex3f( 3.0, 3.0, 3.0);
glVertex3f(-3.0, 3.0, 3.0);
glVertex3f(-3.0,-3.0, 3.0);
glVertex3f( 3.0,-3.0, 3.0);
glColor3f( 0.0, 1.0,1.0); // behind (cyan)
glNormal3f(0,0,1);
glVertex3f( 3.0,-3.0,-3.0);
glVertex3f(-3.0,-3.0,-3.0);
glVertex3f(-3.0, 3.0,-3.0);
glVertex3f( 3.0, 3.0,-3.0);
glColor3f(0.0 ,0.0,1.0); //left
glNormal3f(1,0,0);
glVertex3f(-3.0, 3.0, 3.0);
glVertex3f(-3.0, 3.0,-3.0);
glVertex3f(-3.0,-3.0,-3.0);
glVertex3f(-3.0,-3.0, 3.0);
glColor3f( 0.2, 0.4, 0.0); // right
glNormal3f(-1,0,0);
glVertex3f( 3.0, 3.0,-3.0);
glVertex3f( 3.0, 3.0, 3.0);
glVertex3f( 3.0,-3.0, 3.0);
glVertex3f( 3.0,-3.0,-3.0);
glEnd();
glPopMatrix();
}
void drawClock() {
char buff[100];
GLfloat x1=0.0;
GLfloat y1=2.5;
GLfloat z1= -2.9;
GLfloat radius = 1.5;
int angle;
glLoadIdentity();
// Draw circle
glPushMatrix();
glBegin(GL_TRIANGLE_FAN);
glColor3f(0.5,1.0,1.0);
glVertex3f(x1, y1, z1);
for(angle=0; angle <=360; angle +=1)
glVertex3f(x1 + cos(angle * PI/180.0f)* radius, y1 + sin(angle * PI/180.0f) * radius, z1);
glEnd();
glPopMatrix();
// draw ticks
glPushMatrix();
glColor3f(0.2,0.2,0.2);
glLineWidth(2);
for(angle=0; angle <= 360; angle +=30)
{
glBegin(GL_LINES);
//printf("Angle: %d\n", angle);
if(angle == 0.0 || angle==90.0 || angle == 180.0 || angle == 270.0 || angle == 360.0 )
{
glColor3f(1.0,0.2,0.2);
glVertex3f(x1 + cos(angle * PI/180.0f)* (radius+0.2), y1 + sin(angle * PI/180.0f) * (radius+0.2), z1);
glVertex3f(x1 + cos(angle * PI/180.0f)* radius, y1 + sin(angle * PI/180.0f) * radius, z1);
}
else
{
glColor3f(0.2,0.2,0.2);
glVertex3f(x1 + cos(angle * PI/180.0f)* (radius+0.05), y1 + sin(angle * PI/180.0f) * (radius+0.05), z1);
glVertex3f(x1 + cos(angle * PI/180.0f)* radius, y1 + sin(angle * PI/180.0f) * radius, z1);
}
glEnd();
}
glPopMatrix();
// Draw seconds line
glColor3f(1.0,1.0,1.0);
glLineWidth(2);
glPushMatrix();
glTranslatef(0.0,1.7,0.0);
glRotatef(-secAngle, 0.0, 0.0, 1.0);
glBegin(GL_LINES);
glVertex3f(0.0, 0.0 , -2);
glVertex3f(0.0, 1.0 , -2);
glEnd();
glPopMatrix();
// Draw minutes line
glColor3f(1.0,0.0,0.0);
glLineWidth(2);
glPushMatrix();
glTranslatef(0.0,1.7,0.0);
glRotatef(-minAngle, 0.0, 0.0, 1.0);
glBegin(GL_LINES);
glVertex3f(0.0, 0.0, -2);
glVertex3f(0.0, 0.8, -2);
glEnd();
glPopMatrix();
// Draw hour line
glColor3f(0.0,0.0,0.0);
glLineWidth(2);
glPushMatrix();
glTranslatef(0.0,1.7,0.0);
glRotatef(-hourAngle, 0.0, 0.0, 1.0);
glBegin(GL_LINES);
glVertex3f(0.0, 0.0, -2.0);
glVertex3f(0.0, 0.6, -2.0);
glEnd();
// Draw central point
glColor3f(0.0,0.0,0.0);
glPointSize(10.0);
glPushMatrix();
glTranslatef(0.0,1.7,0.0);
glBegin(GL_POINTS);
glVertex3f(0.0, 0.0, 2.0);
glEnd();
glPopMatrix();
glFlush();
}
我运行项目时如下:
然后旋转相机:
我这两张照片的时钟位置是固定的 。我怎样才能把它固定在墙上?