2018年3月21日 星期三

week4 fish

week04:

下載: http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
1.data
2.win32
3.glut32.dll
開啟Transformation
可以左右上下移動 放大縮小
去調整旋轉角度
glRotatef(旋轉角度,x軸,y軸,z軸)



按右鍵選擇圖型





glRotatef(旋轉角度,x軸,y軸,z軸)




自動旋轉
#include <GL/glut.h>//使用GLUT外掛
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);//2種模式
    glPushMatrix();//備份矩陣
        glRotatef(angle,0,0,1);//旋轉angle度
        glutSolidTeapot(0.3);
    glPopMatrix();//還原矩陣
    glutSwapBuffers();//交換畫面buffer便會顯示
    angle++;//每次角度加1度
}
int main(int argc, char**argv)//進階的main()參數(個數,字串)
{
    glutInit(&argc,argv);//進階參數,初始GLUT
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);//開始2種模式
    glutCreateWindow("Week04");//盡量不要用中文
    glutIdleFunc(display);//很閒/Idle,去重畫
    glutDisplayFunc(display);//等一下樓上要準備 void display()
    glutMainLoop();//主要迴圈
}


手動旋轉
#include <GL/glut.h>//使用GLUT外掛
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);//2種模式
    glPushMatrix();//備份矩陣
        glRotatef(angle,0,0,1);//旋轉angle度
        glutSolidTeapot(0.3);
    glPopMatrix();//還原矩陣
    glutSwapBuffers();//交換畫面buffer便會顯示
    angle++;//每次角度加1度
    //Now:printf("%.1f\n",angle);///Now:angle++;//每次角度加1度
}
void mouse(int button,int state,int x,int y)
{
}
void motion(int x,int y)
{///Now:當mouse在drag motion時
    angle=x;//Now:去改變angle值
    glutPostRedisplay();//Now:請畫面重畫
}
int main(int argc, char**argv)//進階的main()參數(個數,字串)
{
    glutInit(&argc,argv);//進階參數,初始GLUT
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);//開始2種模式
    glutCreateWindow("Week04");//盡量不要用中文
    glutMouseFunc(mouse);//Now:mouse
    glutMotionFunc(motion);//Now:motion
    ///Now:glutIdleFunc(disolay);///很閒/Idle,去重畫
    glutDisplayFunc(display);//等一下樓上要準備 void display()
    glutMainLoop();//主要迴圈
}








沒有留言:

張貼留言