1.練習期中考題
glPushMatrix(); //備份矩陣 10%
glRotatef(angle,x,y,z); //旋轉 30%
glTranslatef(x,y,z); //移動 40%
glScalef(x,y,z); //縮放 50%
glBegin(GL_POLYGON); //開始畫 60%
glNormal3f(nx,ny,nz); //打光的法向量 90%
glTexcoord2f(tx,ty); //貼圖座標 100%
glColor3f(r,g,b); //顏色 70%
glVertex3f(x,y,z); //頂點 80%
glEnd(); //結束畫
glPopMatrix(); //還原矩陣 20%
2.理解Case1.Case2
Case 1: 自轉
{glRotatef(angle,x,y,z);
{glTranslatef(x,y,z);
{glScalef(x,y,z);
{glBegin(GL_POLYGON);
glNormal3f(nx,ny,nz);
glTexcoord2f(tx,ty);
glColor3f(r,g,b);
glVertex3f(x,y,z); }車子
glEnd();
glPopMatrix(); }移動}旋轉}縮放
Case 2:轉整個大圓盤
3. T-R-T
錯誤示範:
正確示範:
#include <GL/glut.h>
float mouseX=0;
static void display(void)
{
float mouseX=0;
static void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glPushMatrix();
glRotatef(mouseX,0,0,1);
glColor3f(1,0,0);
glutSolidTeapot(0.3);
glPushMatrix();
///3.掛上去
glTranslatef(0.5,0.14,0); ///3.把整個樓下的東西,移到紅色茶壺嘴
glRotatef(mouseX,0,0,1); ///2.會轉動
glTranslatef(0.41,-0.05,0);///1.把手移到轉盤中心
glColor3f(1,1,1);
glutSolidTeapot(0.3);
glPushMatrix();
glPopMatrix();
glutSwapBuffers();
}
void motion(int x,int y)
{
mouseX=x;
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glColor3f(1,0,0);
glutSolidTeapot(0.3);
glPushMatrix();
///3.掛上去
glTranslatef(0.5,0.14,0); ///3.把整個樓下的東西,移到紅色茶壺嘴
glRotatef(mouseX,0,0,1); ///2.會轉動
glTranslatef(0.41,-0.05,0);///1.把手移到轉盤中心
glColor3f(1,1,1);
glutSolidTeapot(0.3);
glPushMatrix();
glPopMatrix();
glutSwapBuffers();
}
void motion(int x,int y)
{
mouseX=x;
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("TRT robot");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
return EXIT_SUCCESS;
}
}


沒有留言:
張貼留言