2018年3月23日 星期五

week04-李昱佑



此篇是要教"角度" 旋轉

x 軸 是 手的大拇指橫插為軸 做旋轉
y軸  是 手的大拇指直插為軸 做旋轉
z軸  是 手的大拇指面插為軸 做旋轉

-----codeblock----
  #include <stdio.h>
     #include <GL/glut.h>
     float teapotX=0, teapotY=0,angle=0;
     void display()
    {
    glClear(GL_COLOR_BUFFER_BIT  | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();//備份矩陣
    glTranslatef(teapotX, teapotY, 0); //依照茶壺的座標移動
    glRotatef(angle,0,0,1);/////角度旋轉
    glutSolidTeapot(0.3);
    glPopMatrix();//還原矩陣
    glutSwapBuffers(); //搭配GLUT_DOUBLE兩倍顯示
    }
    void motion(int x, int y) //mouse motion 事件
   {
    //teapotX = (x-150)/150.0; // 依照motion時的x來改teapot的座標
    //teapotY = (150-y)/150.0;// 依照motion時的y來改teapot的座標
    angle =x; //將angle 設為滑鼠的x座標

    glutPostRedisplay(); //重畫畫面
   }
   int main(int argc, char** argv)
  {
   glutInit(&argc,argv);
   glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
   glutCreateWindow("Week03 Mouse");
   glutDisplayFunc(display);
   //glutMouseFunc(mouse);
   glutMotionFunc(motion);
   glutMainLoop();//主要GLUT迴圈
  }

沒有留言:

張貼留言