2019年3月15日 星期五

week04





今天目標是練習Rotate (旋轉)
今天一上課照著上一堂課的內容重做一次
http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
下載        win32  data  socure
在下載一個叫  glut32.dll檔下載下來

把data.zip 跟windows.zip 解壓縮資料夾
把glut32.dll 移進資料夾

開啟 Transformation.exe 執行


2.
在來是照著作業上面重新練習一次讓茶壺可以跟著滑鼠移動
程式碼
#include <GL/glut.h>
float x=0,y=0;
void display()

{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glColor3f(1,0,0);
        glTranslated((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();

}
執行結果


3.
今天的重點 讓茶壺旋轉
第一個 對X軸的旋轉
glRotated(x,0,1,0);

第二個 對Y軸旋轉
glRotated(y,1,0,0);

程式碼
#include <GL/glut.h>
float x=0,y=0;
void display()

{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glColor3f(1,0,0);
        ///glTranslated((x-150)/150.0,-(y-150)/150.0,0);
        glRotated(x,0,1,0);
        glRotated(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();

}
執行結果




沒有留言:

張貼留言