2019年3月15日 星期五

O_o|||的電腦圖學

旋轉角度


移動茶壺
程式碼:
#include <GL/glut.h>
float x=0,y=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef((x-150)/150.0, -(y-150)/150.0,0);
        glutSolidTeapot(0.3);
    glPopMatrix();///還原矩陣,恢復

    glutSwapBuffers();
}
void motion(int nowx, int nowy)
{
    x=nowx; y=nowy;
    display();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week04_06160221");
    glutDisplayFunc(display);
    glutMotionFunc(motion);

    glutMainLoop();
}



旋轉茶壺
程式碼:
#include <GL/glut.h>
float x=0,y=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(x,0,1,0);//旋轉
        glutSolidTeapot(0.3);
    glPopMatrix();///還原矩陣,恢復

    glutSwapBuffers();
}
void motion(int nowx, int nowy)
{
    x=nowx; y=nowy;
    display();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week04_06160221");
    glutDisplayFunc(display);
    glutMotionFunc(motion);

    glutMainLoop();
}



沒有留言:

張貼留言