2020年3月18日 星期三

(*^ω^*) 喵~Week03

➽ 複習上周(點、線、面)
  • 網址:http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
  • 下載 [data][win32][glut32.dll] 三個檔案
  • [windows]解壓縮>>開啟[windows]資料夾>>將[data]壓縮裡的資料夾和[glut32.dll]拉入[windows]資料夾
  • 開啟 Shapes.exe
  • 開啟 Transformation.exe
  
➽ Mouse函式
  • 同之前先下載freegult>>將lib裡的libfreeglut.a複製一份並改名libglut32.a
  • 開啟Codeblocks>>開啟new project>>OpenGL
  • 將程式碼複製貼上(白色茶壺版⬎) 
    • #include <GL/glut.h> ///蘋果電腦使用 <GLUT/glut.h>
    • void display()
    • {
    •     glutSolidTeapot(0.3);
    •     glutSwapBuffers();
    • }
    • int main(int argc, char *argv[])

    • {
    •     glutInit(&argc, argv);
    •     glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    •     glutCreateWindow("Week03!!!");
    •     glutDisplayFunc(display);
    •     glutMainLoop();
    • }
  • glutMainLoop();上一行加入 glutMouseFunc(mouse);
  • 並增加 mouse 函式⬎
    • void mouse(int button, int state, int x, int y)
    • {
    •     printf("%d %d %d %d\n", button, state, x, y);
    • }
        ◈ 補充: button 滑鼠左(0)中(1)右(2)鍵、state按下(0)放開(1)、xy座標(0~300)
  ◈ 因為有使用 printf 記得要加上 #include <stdio.h>
➷➷ 讓茶壺隨滑鼠點擊移動
    • float teapotX=0, teapotY=0;///放茶壺的xy座標
    • void display()
    • {
    •     glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);///清畫面
    •     glPushMatrix();///備份矩陣
    •         glTranslatef( teapotX, teapotY, 0);///茶壺的xyz
    •         glutSolidTeapot(0.3);
    •     glPopMatrix();///備份矩陣
    •     glutSwapBuffers();
    • }
    • void mouse(int button, int state, int x, int y)
    • {
    •     teapotX=(x-150)/150.0;///滑鼠座標和繪圖座標換算(口訣:減一半,除一半.0)
    •     teapotY=-(y-150)/150.0;
    • }

⧪⧪回家作業:用程式畫圖⧪⧪
  • 找一圖案,利用小畫家找頂點
  • 圖形框架如下(直線多邊形)
    • glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    • glBegin(GL_POLYGON);///全框300(減一半除一半.0)
    •     glVertex2f((227-150)/150.0, -(132-150)/150.0);///小畫家座標(227,132)
    •     glVertex2f((151-150)/150.0, -(115-150)/150.0);
    •     glVertex2f((85-150)/150.0, -(141-150)/150.0);
    •     glVertex2f((118-150)/150.0, -(188-150)/150.0);
    •     glVertex2f((180-150)/150.0, -(186-150)/150.0);
    • glEnd();


                • 圓形框架
                  • glBegin(GL_POLYGON);///全框300(減一半除一半.0)
                  •         for(float angle=0;angle<=3.1415926*2;angle+=0.01){
                  •             glVertex2f(0.3*cos(angle),0.5*sin(angle));///長(sin)寬(cos)
                  •         }
                  • glEnd();

                • 色彩框架
                  • glClearColor(255/255.0,194/255.0,101/255.0,1);///背景的RGBA(原色/255.0)
                  • glColor3f(1/255.0,195/255.0,115/255.0);

                    ◈如何看小畫家座標

                    ◈如何知道想要的色彩RGB
                    ◈成果展示

                沒有留言:

                張貼留言