2019年3月21日 星期四

Week 05 旋轉

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即可使用


試glRotatef(角度,x軸,y軸,z軸);






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


自動旋轉程式碼

#include<GL/glut.h>
float angle=0; ///今天新教的!!!!
void display()
{///沒有使用glClear()去清畫面,會有殘影...
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///Push備份Martix
        glRotatef(angle,0,1,0); ///今天新教的,對y軸,轉angle角度。
        glutSolidTeapot(0.3);
    glPopMatrix();///Pop還原Matrix
    glutSwapBuffers();
    angle+=3; ///今天新教的!!!! 每次執行到這行,加一點點
}

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

}


滑鼠移動旋轉程式碼


#include<GL/glut.h>
float angle=0; ///今天新教的!!!!
void display()
{///沒有使用glClear()去清畫面,會有殘影...
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///Push備份Martix
        glRotatef(angle,0,1,0); ///今天新教的,對y軸,轉angle角度。
        glutSolidTeapot(0.3);
    glPopMatrix();///Pop還原Matrix
    glutSwapBuffers();
    ///angle+=3; ///現在要新加的!!!!!!! 每次執行到這行,加一點點
}

void motion(int x,int y)///現在要新加的!!!
{///當你的Mouse去drag做motion的動作時,
    angle=x;///現在要新加的!!!
    display();///現在要新加的!!!
}

int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);///不要用錯了!glut配GLUT
    glutCreateWindow("Week05 Rotate");
    glutDisplayFunc(display);
    glutIdleFunc(display);///今天新教的!!Idle閒閒沒事,就重畫。
    glutMotionFunc(motion);///現在要新加的!!!
    glutMainLoop();///如果忘了寫glutMainLoop() 或是忘了寫圓括號()就會離開

}


偵側滑鼠位置

#include<GL/glut.h>
float angle=0; ///今天新教的!!!!
void display()
{///沒有使用glClear()去清畫面,會有殘影...
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///Push備份Martix
        glRotatef(angle,0,1,0); ///今天新教的,對y軸,轉angle角度。
        glutSolidTeapot(0.3);
    glPopMatrix();///Pop還原Matrix
    glutSwapBuffers();
    ///angle+=3; ///現在要新加的!!!!!!! 每次執行到這行,加一點點
}

void motion(int x,int y)///現在要新加的!!!
{///當你的Mouse去drag做motion的動作時,
    angle=x;///現在要新加的!!!
    display();///現在要新加的!!!
}

#include<stdio.h>
void mouse(int button,int state,int x,int y)///現在要新加的!!!!
{///要把大象放到冰箱:(1)Mouse按下去 (3)Mouse放開來
    printf("%d %d %d\n",button,state,x,y);///現在要新加的!!!!
}


int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);///不要用錯了!glut配GLUT
    glutCreateWindow("Week05 Rotate");

    glutDisplayFunc(display);
    glutIdleFunc(display);///今天新教的!!Idle閒閒沒事,就重畫。
    glutMotionFunc(motion);///現在要新加的!!!!
    glutMouseFunc(mouse);///現在要新加的!!!!

    glutMainLoop();///如果忘了寫glutMainLoop() 或是忘了寫圓括號()就會離開

}


沒有留言:

張貼留言