2017年3月28日 星期二

week06 邊緣人的日常

Hw01: 在Blog練習期中考題

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%
 
 
 
 
 
 
 
 
Hw02:嘗試用Transformation  去變換車子的位子
 
 
選擇 Swap Translate  更改旋轉方式
 
 
 
 
 
 
 
 
 
 
Hw03 : 新增專案  並更改程式碼
#include <GL/glut.h>
float mouseX=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glutSolidTeapot(0.3);
        glPushMatrix();
            glRotatef(mouseX, 0,0,1);
            glTranslatef(0.5, 0,0);
            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();
}



 
 
 
 
 
 
 
 
 
Hw04: 新增第二個茶壺 並且接在茶壺嘴上

           並且更改顏色加上旋轉

程式碼為
#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();
}
 



沒有留言:

張貼留言