2022年5月9日 星期一

你的筆記 week12

 1-1 去 https://jsyeh.org/3dcg10 下載windows跟Transfomation並解壓縮

///有一台藍色的車子

1-2對特定軸轉動練習的網址:https://120.125.80.50/GL/opengl_TRT_demo.html

2-1 1.點擊ToDraw即可開始畫圖 2.將myDrawObject(0);移動到下面glTranslatef(0,0,0); 3.滑鼠點擊右上角的angle,並按下空白鍵,圖形就會進行旋轉 4.將myDrawObject(0);移動到glTranslatef(0,0,0); 5.點擊glTranslatef(0,0,0);就可以拖曳移動圖形位置

        

2-2

做旋轉的茶壺

程式碼:

#include <GL/glut.h>

float angle=0;

void display()


{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();

        glRotatef( angle,0,0,1);

        glTranslatef(0.4,-0.07,0);

        glutSolidTeapot(0.3);

    glPopMatrix();

    glutSwapBuffers();

    angle+=0.1;


}


int main(int argc,char**argv)


{

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("week12 TRT");

    glutIdleFunc(display);

    glutDisplayFunc(display);

    glutMainLoop();

}





3-1修改程式碼 有兩個茶壺 小的會轉

#include <GL/glut.h>

float angle=0;

void display()


{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glColor3f(1,1,1);

    glutSolidTeapot(0.3);

    glPushMatrix();

        glTranslatef(0.3,0,0);

        glRotatef( angle,0,0,1);

        glTranslatef(0.2,0,0);

        glColor3f(1,0,0);

        glutSolidTeapot(0.2);

    glPopMatrix();

    glutSwapBuffers();

    angle+=0.1;


}


int main(int argc,char**argv)


{

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("week12 TRT");

    glutIdleFunc(display);

    glutDisplayFunc(display);

    glutMainLoop();

}

3-2 多增加一個茶壺
#include <GL/glut.h>
float angle=0;
void display()

{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(1,1,1);
    glutSolidTeapot(0.3);
    glPushMatrix();
        glTranslatef(0.3,0,0);
        glRotatef( angle,0,0,1);
        glTranslatef(0.2,0,0);
        glColor3f(1,0,0);
        glutSolidTeapot(0.2);
        glPushMatrix();
            glTranslatef(0.2,0,0);
            glRotatef( angle,0,0,1);
            glTranslatef(0.2,0,0);
            glColor3f(1,0,0);
            glutSolidTeapot(0.2);
        glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();
    angle+=0.1;

}

int main(int argc,char**argv)

{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week12 TRT");
    glutIdleFunc(display);
    glutDisplayFunc(display);
    glutMainLoop();
}








沒有留言:

張貼留言