2018年3月23日 星期五

Week_04 林楷

主題:移動,選轉,縮放

按照上週作法,去到圖學網站
下載 data.zip , windows.zip , glu32.dll 三個檔案 
然後把glut32檔移動到windows檔裡,開啟transformation.exe


把上週的程式碼加上新的旋轉函式

#include<stdio.h>
#include<GL/glut.h>
///(1)我們要使用比較高級的GLUT (OpenGl User Toolkit)
float angle = 0 ; ///rotate要旋轉的角度
void display()
{
    glClear(GL_COLOR_BUFFER_BIT);///清畫面
    glPushMatrix();           ///Now: 備份矩陣
    glTranslatef(0, 0, 0);          ///Now: 依照茶壺的座標移動
    glRotatef(angle , 0 ,0 ,1 );///茶壺對準z軸旋轉angle角度
    glutSolidTeapot(0.3);///大小為0.3的茶壺
    glPopMatrix();///還原矩陣
    glutSwapBuffers(); /// 交換double buffers來顯示畫面
}

}
void motion(int x, int y)///滑鼠轉動
{
    angle = x ;
    glutPostRedisplay();///滑鼠的座標為轉的角度
}
int main(int argc , char **argv)///主要函式
{///這個參數的意思是,把作業系統參數塞進來
    glutInit(&argc,argv);///初始Iniitialize你的參數設定
    glutInitDisplayMode(GLUT_DOUBLE);///顯示模式:double buffers
    glutCreateWindow("week02 Triangle");///建立視窗

    
    glutMotionFunc(motion);///移動函式
    glutDisplayFunc(display);///顯式函式display()用來畫圖的
    glutMainLoop();///主要的迴圈,用來控制程式
}



沒有留言:

張貼留言