2019年3月15日 星期五

棗酒母湯


glRotatef( 0.0 , 0.00 , 0.00 , 0.00)
              ( 角度 , X軸 , Y軸 , Z軸 ) 
                                ↓↓↓
               用右手大拇指當XYZ軸
               右手其他手指當旋轉角度

加入程式碼可以用滑鼠移動茶壺↓↓↓↓↓

#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");
    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");
    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(y,1,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");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}


執行結果↓↓↓↓↓


沒有留言:

張貼留言