2017年3月28日 星期二

17/03/28 Te-Yu,Lu的電腦圖學筆記

2017電腦圖學(computer Graphics)
2017-03-28 Week08第06週進度:


  1. 期中考考題
  2. 畫茶壺關節

期中複習考題:

  1. glPushMartrix( );///備份矩陣
  2. glTranslatef(x,y,z);///移動
  3. glRotatef(angle,x,y,z);///旋轉
  4. glScalef(x,y,z);///縮放
  5. glBegin(GL_POLYGON );///開始
  6. glTexCoord2f(tx,ty);///貼圖
  7. glNormal3f(nx,ny,nz);///打光法向量
  8. glColor3f(r,g,b);///顏色
  9. glVertex3f(x,y,z);
  10. glEnd( );///結束
  11. glPopMartrix( );///還原矩陣

畫茶壺關節:

#include <GL/glut.h>
float mouseX=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(mouseX,0,0,1);
        glColor3f(1,0,0);
        glutSolidTeapot(0.3);
        glPushMatrix();
            glTranslatef(0.5, 0.14,0);
            glRotatef(mouseX,0,0,1);
            glTranslatef(0.41,-0.05,0);
            glColor3f(1,1,1);
            glutSolidTeapot(0.3);
        glPopMatrix();
    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();
}

呈現結果:

沒有留言:

張貼留言