2019年3月21日 星期四

ˊ_>ˋ_week5

(1)主題:旋轉Rotation

前置作業:

老師雲端網址:120.125.89.81
http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/下載(前幾周都有下載的三個檔案)
-->Win32/data/glut32.dll
並依照以下步驟:
把windows檔解壓縮到windows\(E)-->打開解壓縮後的windows檔-->把data壓縮檔裡的data直接拉進windows檔裡-->再把glut32.dll檔也拉進去windows檔案夾裡
最後:Windows 打開 Transformation.exe檔


和軸垂直方向便是旋轉方向

轉Z軸:100度

轉X軸:60度

轉Y軸:60度

(2)實作:glRotatef()



#include <GL/glut.h>
float angle=0; ///今天新教的~
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(angle, 0, 1, 0); ///今天新教的~ 轉轉轉
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
    angle+=1; ///今天新教的~ 每執行到這,角度便增加。

}

int main (int argc, char**argv)
{
    glutInit( &argc, argv );
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week05 rotate");
    glutDisplayFunc(display);
    glutIdleFunc(display); ///今天新教的~ Idle閒閒沒事,便重畫。
    glutMainLoop();
}

(3)滑鼠轉,自動轉:



#include <GL/glut.h>
float angle=0; ///今天新教的~
void display()
{   ///沒有使用glClear()去清畫面,會有殘影。
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();  ///PUSH備份保護Matrix
        glRotatef(angle, 0, 1, 0); ///今天新教的~ 轉轉轉
        glutSolidTeapot(0.3);
    glPopMatrix(); ///pop還原Matrix
    glutSwapBuffers();
    ///angle+=1; ///今天新教的~ 每執行到這,角度便增加。

}
void motion(int x, int y )
{///當滑鼠在做拖行的動作時。
    angle = x;
    display();
}
#include <stdio.h>
void mouse (int button, int state, int x, int y)
{
/// button 0左鍵 1中鍵 2右鍵 3滾輪前划 4滾輪後划
printf( "%d %d %d %d\n", button, state , x, y );

}

int main (int argc, char**argv)
{
    glutInit( &argc, argv );
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week05 rotate");

    glutDisplayFunc(display);
    glutIdleFunc(display); ///今天新教的~ Idle閒閒沒事,便重畫。
    glutMotionFunc(motion);
    glutMouseFunc(mouse);

    glutMainLoop(); ///沒有寫到這一行或是少了 () 就會直接離開。
}


沒有留言:

張貼留言