2019年4月25日 星期四

Week10_玄的筆記

Week10上課筆記


期中考 必備10個函式

複習: 移動,旋轉,縮放

主題: T-R-T旋轉 (改變旋轉軸)


複習移動,旋轉,縮放

自轉標示圖

公轉標示圖


主題: T-R-T旋轉 (改變旋轉軸)



//////////
程式碼:
#include<GL/glut.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
    glTranslated(0,0.5,0); ///往上移動
    glColor3f(0,1,0); /// 改成綠色
    glutSolidTeapot(0.3); ///創造一個茶壺
    glPopMatrix();

    glPushMatrix();
    glTranslated(0.5,0.625,0); /// X軸移動到0.5,Y軸移動到0.625(掛在茶壺嘴)
    glRotated(angle,0,0,1); /// 跟著滑鼠轉動
    glTranslated(0.6,0,0); /// X軸移動0.6
    glRotatef(-90,0,1,0); /// 三角錐體
    glColor3f(1,0,0); /// 改成紅色
    glutSolidCone(0.2,0.6,30,30); /// 創造一個錐體
    glPopMatrix();
    glutSwapBuffers();
}

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



沒有留言:

張貼留言