2016年3月14日 星期一

【03160135_吳亞芳】Week04

  • 幫同學互評作業


  • 安裝7-zip解壓縮

1.打開安裝檔按下install



2.開始/A.搜尋輸入 7
B.打開7-zip File Manager


3.工具/選項


4.按下"+"(多按幾次直到黃色區域都變成7-Zip)
讓壓縮檔都預設為7-Zip壓縮




下載 glut32.dll[data][win32]三個檔案


1.將window.zip(剛剛下載的win32)解壓縮成一資料夾在桌面


2.將glut32.dll移進1的資料夾


3.data.zip解壓縮成一資料夾也移進1(windows)

最終windows資料夾內部如圖





課堂作業2

主題:平移/旋轉/縮放



打開windows資料夾內的Transformation.exe

滑鼠調整下面

glTranslatef(移動)

glRotatef(旋轉)

glScalef(縮放大小)

由數值觀察變化


glTranslatef(X軸,Y軸,Z軸)




glRotatef(角度,X軸,Y軸,Z軸)


glRotatef的XYZ軸代表旋轉軸心(1~-1),像安培右手定

理。像一隻牙籤插進車子裡,大拇指方向為牙籤頭,往

其他手指方向旋轉。






glScalef(X軸,Y軸,Z軸)









課堂作業3


  • Code::Blocks新增GLUT 專案
  • 建立GLUTproject
  • 1.File/New/Project

  • 選擇GLUT project


  • 2.決定專案名跟儲存位置

3. freeglut資料夾解壓縮到桌面,複製freeglut所在位置



4.Please selest GLUT's loctoin: 貼上位置





用glutMouseFunc(mouse);配合自己的mouse函式



*-------------------*
#include <GL/glut.h>
#include <stdio.h>
void mouse(int button, int state, int x,int y)
{
   if(state==GLUT_DOWN)
        printf("        glVertex2f( (%d-150)/150.0, -(%d-150)/150.0 ); \n",x,y);
}
void display()
{
    glClearColor(0,0,255/255.0,1); //底圖顏色,不要忘了除以/225.0
    glClear(GL_COLOR_BUFFER_BIT);  
    glColor3ub(144,0,255);
    glBegin(GL_POLYGON);
        glVertex2f( (111-150)/150.0, -(101-150)/150.0 );
        glVertex2f( (228-150)/150.0, -(97-150)/150.0 );
        glVertex2f( (95-150)/150.0, -(232-150)/150.0 );
        glVertex2f( (237-150)/150.0, -(235-150)/150.0 );
    glEnd();
    glBegin(GL_POLYGON);
        glVertex2f( (57-150)/150.0, -(23-150)/150.0 );
        glVertex2f( (104-150)/150.0, -(28-150)/150.0 );
        glVertex2f( (98-150)/150.0, -(75-150)/150.0 );
        glVertex2f( (49-150)/150.0, -(71-150)/150.0 );
    glEnd();
    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("hello3D");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();
}

*---------------------*
重點是綠色部分
印出後可以直接點hello3D在想畫圖的位置
void mouse(int button, int state, int x,int y)
{
   if(state==GLUT_DOWN)
        printf("        glVertex2f( (%d-150)/150.0, -(%d-150)/150.0 ); \n",x,y);
}
可直接複製(程式上面視窗邊框右鍵後/編輯/標記)
選取後按下ENTER



glBegin(GL_POLYGON);
(貼在這裡)
glEnd();
在執行後就會畫出

畫出圓形



寫程式畫出圓(原理利用圓周率跟三角函式)

再新建一個GLUTproject

先貼上剛剛的程式碼
最前面要加上#include <math.h>
因為會用到cos、sin

開始畫圓

void display()
{
    glClearColor(0,0,255/255.0,1); //底圖顏色,不要忘了除以/225.0
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3ub(144,0,255);

    glPushMatrix();
        glBegin(GL_POLYGON);
        for(float angle=0; angle<3.14159265357989 *2;angle+=0.1)
        {
            glVertex2f(0.2*cos(angle), 0.2*sin(angle));
        }
        glEnd();
    glPopMatrix();
    glPushMatrix();
        glTranslatef(0,0.5,0);
        glBegin(GL_POLYGON);
        for(float angle=0; angle<3.14159265357989 *2;angle+=0.1)
        {
            glVertex2f(0.2*cos(angle), 0.2*sin(angle));
        }
        glEnd();
      glPopMatrix();

    glutSwapBuffers();
}

最終程式碼

#include <GL/glut.h>
#include <stdio.h>
#include <math.h>
void mouse(int button, int state, int x,int y)
{
   if(state==GLUT_DOWN)
        printf("        glVertex2f( (%d-150)/150.0, -(%d-150)/150.0 ); \n",x,y);
}
void display()
{
    glClearColor(0,0,255/255.0,1); //底圖顏色,不要忘了除以/225.0
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3ub(144,0,255);

    glPushMatrix();
        glBegin(GL_POLYGON);
        for(float angle=0; angle<3.14159265357989 *2;angle+=0.1)
        {
            glVertex2f(0.2*cos(angle), 0.2*sin(angle));
        }
        glEnd();
    glPopMatrix();
    glPushMatrix();
        glTranslatef(0,0.5,0);
        glBegin(GL_POLYGON);
        for(float angle=0; angle<3.14159265357989 *2;angle+=0.1)
        {
            glVertex2f(0.2*cos(angle), 0.2*sin(angle));
        }
        glEnd();
      glPopMatrix();

    glBegin(GL_POLYGON);
        glVertex2f( (57-150)/150.0, -(23-150)/150.0 );
        glVertex2f( (104-150)/150.0, -(28-150)/150.0 );
        glVertex2f( (98-150)/150.0, -(75-150)/150.0 );
        glVertex2f( (49-150)/150.0, -(71-150)/150.0 );
    glEnd();
    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("hello3D");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();
}



沒有留言:

張貼留言