2018年3月19日 星期一

Week04

電腦圖學week04筆記 

1.下載data win32 glut32.dll  將win32解壓縮 再把glut data放到windows
2.glRotatef 角度x軸y軸z軸
(改變z軸角度)
3.解釋旋轉移動放大縮小的程式碼(重點)

4.把glRotated(60,1,0,0)變注解

5.這個是自動旋轉的茶壺(一直在跑的就是角度)

#include <stdio.h>
#include <GL/glut.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(angle,0,0,1);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
    printf("%.1f\n",angle);
    angle++;
}

int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("05160133_week04 transformation");

    glutIdleFunc(display);
    glutDisplayFunc(display);
    glutMainLoop();
}
6.手動旋轉的茶壺~

#include <stdio.h>
#include <GL/glut.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(angle,0,0,1);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
    ///Now:printf("%.1f\n",angle);
    ///Now:angle++;///每次角度加一
}
void mouse(int button,int state,int x,int y)
{

}
void motion(int x,int y)
{///Now:當mouse在drag notion時
    angle=x;///now:去改變angle值
    glutPostRedisplay();///now:請畫面重劃
}

int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("05160133_week04 transformation");
    glutMouseFunc(mouse);///now:mouse
    glutMotionFunc(motion);///now:motion
    ///glutIdleFunc(display);////很閒//idle去重劃
    glutDisplayFunc(display);
    glutMainLoop();

}



沒有留言:

張貼留言