2021年3月22日 星期一

𝔍𝔒𝔗𝔇-week05

 

電腦圖學_week05

2021/03/22(一)

        
         今日的上課內容:
  1. 先試著Transformation.exe回憶上週旋轉和轉動
  2. 下方按右鍵,swap交換2行觀察自轉和公轉的差別
  3. 左耳碰左肩,從下到上拆解,讀懂程式(由下往上讀,會有自轉和公轉的差別)
  4. 理解程式如何跑動(由下往上看,且近的會先受影響,電腦是原x,y,z點乘上一個轉動加移動這樣只要做一次運算就好)
  5. 解壓縮freeglut並把lib中改檔名為libglut32.a\
  6. 下載自己github的上週檔案
  7. week04.cbp CodeBlocks Project
  8. 我的.cpp檔
  9. 運用上週架構改成可以用滑鼠畫圖的程式
  10. 進階:新增顏色程式碼可以更改畫筆顏色
  11. 加課:運用gist.github.com寫程式
  12. 加課:把上面網址複製
  13. 在blog中改成改成HTML模式加入複製好的網址(可用=====加 ctrl + f 找標註再刪除)
         今日的程式碼:
        (已嵌入gist.github中寫的程式碼)

  • #include <GL/glut.h> ///使用GLUT外掛
  • #include <stdio.h>
  • float vx[2000], vy[2000];///準備一堆頂點 等下要畫 介於 -1 ~ +1
  • int N = 0;///有N個頂點
  • void display()
  • {
  •  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ///清空
  •  glBegin(GL_LINE_LOOP);
  •  for(int i=0;i<N;i++)
  •  {
  •      glVertex2f(vx[i], vy[i]);
  •  }
  •  glEnd();
  •  glutSwapBuffers(); ///交換2倍的buffers
  • }
  • ///void mouse(int button, int state, int x, int y)
  • ///{
  • ///}
  • void motion(int x, int y)
  • {
  •     vx[N] = (x-150)/150.0;///頂點記起來 等下要畫
  •     vy[N] = -(y-150)/150.0;
  •     N++;
  •     display();///顯示刷新速度變快
  • }
  • int main(int argc, char ** argv)
  • {
  •  glutInit(&argc, argv); ///GLUT初始設定
  •  glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); ///顯示模式
  •  glutCreateWindow("week05 drawing"); ///開窗

  •  ///glutMouseFunc(mouse);
  •  glutDisplayFunc(display); ///等一下要顯示的函式
  •  glutMotionFunc(motion);///滑鼠移動的函式
  •  glutMainLoop(); ///主要迴圈
  • }

圖四
  • #include <GL/glut.h> ///使用GLUT外掛
  • #include <stdio.h>
  • float vx[2000], vy[2000];///準備一堆頂點 等下要畫 介於 -1 ~ +1
  • int N = 0;///有N個頂點
  • void display()
  • {
  •  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ///清空
  •  glBegin(GL_LINE_LOOP);
  •  glColor3f(0,255,0);///修改顏色的程式碼
  •  for(int i=0;i<N;i++)
  •  {
  •      glVertex2f(vx[i], vy[i]);
  •  }
  •  glEnd();
  •  glutSwapBuffers(); ///交換2倍的buffers
  • }
  • ///void mouse(int button, int state, int x, int y)
  • ///{
  • ///}
  • void motion(int x, int y)
  • {
  •     vx[N] = (x-150)/150.0;///頂點記起來 等下要畫
  •     vy[N] = -(y-150)/150.0;
  •     N++;
  •     display();///顯示刷新速度變快
  • }
  • int main(int argc, char ** argv)
  • {
  •  glutInit(&argc, argv); ///GLUT初始設定
  •  glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); ///顯示模式
  •  glutCreateWindow("week05 drawing"); ///開窗

  •  ///glutMouseFunc(mouse);
  •  glutDisplayFunc(display); ///等一下要顯示的函式
  •  glutMotionFunc(motion);///滑鼠移動的函式
  •  glutMainLoop(); ///主要迴圈
  • }

圖五
  • #include <GL/glut.h> ///使用GLUT外掛
  • #include <stdio.h>
  • float vx[2000], vy[2000];///準備一堆頂點 等下要畫 介於 -1 ~ +1
  • int N = 0;///有N個頂點
  • void display()
  • {
  •  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ///清空
  •  glColor3f(0,0,255);///藍色
  •  glBegin(GL_TRIANGLE_FAN);
  •  for(int i=0;i<N;i++)
  •  {
  •      glVertex2f(vx[i], vy[i]);
  •  }
  •  glEnd();
  •  glutSwapBuffers(); ///交換2倍的buffers
  • }
  • ///void mouse(int button, int state, int x, int y)
  • ///{
  • ///}
  • void motion(int x, int y)
  • {
  •     vx[N] = (x-150)/150.0;///頂點記起來 等下要畫
  •     vy[N] = -(y-150)/150.0;
  •     N++;
  •     display();///顯示刷新速度變快
  • }
  • int main(int argc, char ** argv)
  • {
  •  glutInit(&argc, argv); ///GLUT初始設定
  •  glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); ///顯示模式
  •  glutCreateWindow("week05 drawing"); ///開窗

  •  ///glutMouseFunc(mouse);
  •  glutDisplayFunc(display); ///等一下要顯示的函式
  •  glutMotionFunc(motion);///滑鼠移動的函式
  •  glutMainLoop(); ///主要迴圈
  • }



        今日的上課結果:
        
⬇️圖一
⬇️圖二
⬇️圖三
⬇️圖四
⬇️圖五
⬇️圖六(由下往上看)







沒有留言:

張貼留言

Week18期末作業(橘貓的跳舞熊熊)

 期末作業(橘貓的跳舞熊熊) 影片: https://youtu.be/R89tptMaQZw 程式碼: #include <opencv/highgui.h> #include <opencv/cv.h> #include <GL/glut.h...