2019年3月14日 星期四

Week 04 移動

1.開啟http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/

2.Examples下載win32、data

3.other examples下載glut32.dll

4.解壓縮windows資料夾

5.將data壓縮檔打開(不要解壓縮),直接拖曳到windows資料夾中

6.將glut32.dll放入windows資料夾中

7.打開Transformation.exe即可使用

延續第一週下載FreeGLUT並修改程式碼

#include<GL/glut.h>
void display()
{
    glPushMatrix(); //備份矩陣
        glTranslatef( 0.3, 0.3, 0); //移動 (會改矩陣)
        glutSolidTeapot(0.3);
    glPopMatrix(); //還原矩陣,才不會在下次有舊的殘值。
    glutSwapBuffers();
}

int main(int argc,char**argv)

{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Week04");
    glutDisplayFunc(display);
    glutMainLoop();
}


滑鼠移動程式碼

#include<GL/glut.h>
float x=0,y=0; ///滑鼠motion
void display()
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix(); ///備份矩陣
        glTranslatef( (x-150)/150.0, -(y-150)/150.0, 0); ///滑鼠motion
        glutSolidTeapot(0.3);
    glPopMatrix(); ///還原矩陣,才不會在下次有舊的殘值
    glutSwapBuffers();
}

void motion(int nowX, int nowY) ///滑鼠motion
{///滑鼠motion
    x=nowX; y=nowY; ///滑鼠motion
    display(); ///滑鼠motion 馬上更新
}///滑鼠motion

int main(int argc,char**argv)

{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Week04");
    glutDisplayFunc(display);
    glutMotionFunc(motion); ///滑鼠motion

    glutMainLoop();

}



沒有留言:

張貼留言