2023年3月16日 星期四

Fafa的奇妙冒險

 Week 05

week 05-1

Step 1:先至 jsyeh.org/3dcg10 下載 05/04的 datawin32,解壓縮後將data資料夾拖入windows資料-夾中

Step 2:打開Transformation.exe,並觀察圖片









Step 3:

程式碼介紹
glRotatef 為:調整旋轉軸

glScalef 為:調整大小

glBegin 為:小藍車的實際執行

Step 4:打開CodeBlock並import GLUT project

Step 5:將下列程式碼複製進main.cpp檔案中

程式碼:
#include<GL/glut.h>
float angle = 0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glColor3f(1,0,0);
    glPushMatrix();
        glRotatef(angle,0,0,1);
        glTranslatef(0.8,0,0);
        glutSolidTeapot(0.3);
    glPopMatrix();

    glColor3f(0,1,0);
    glPushMatrix();
        glTranslatef(0.8,0,0);
        glRotatef(angle*1.5,0,0,1);
        glutSolidTeapot(0.3);
    glPopMatrix();

    glutSwapBuffers();
    angle++;
}

int main(int argc,char *argv[])

{

    glutInit(&argc , argv);

    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE |GL_DEPTH);



    glutCreateWindow("week05");



    glutDisplayFunc(display);

    glutIdleFunc(display);

    glutMainLoop();

}

Step 6:執行程式並觀察圖形移動方向,完成!
   
                                           

Week 05-2


Step 1:打開opengl_TRT_demo資料夾

Step 2:打開opengl_TRT_demo.pde

Step 3:功能介紹:1. 注意輸入法,必須為英文輸入法下執行
                                  2. 按下 ToDraw並在執行的黑視窗中可自由畫下圖案,並會在旁邊的程式碼                                         行自動創建一個object函式
                                  3. 程式碼的各種object均可透過滑鼠拖曳而改變程式碼位置
                                  4. 點選glTranslatef()並按下1 可調整位置
                                  5. 按下space鍵 可以觀察圖形的移動方向
Step 4:觀察圖形,完成!


Week 05-3

Step 1:打開 CodeBlock 並import GLUT project
Step 2:把程式碼複製進去main.cpp

程式碼:#include<GL/glut.h>
float angle = 0;
void myCube()
{
    glPushMatrix();
    glScalef(0.5,0.2,0.2);          ///條大小
    glutSolidCube(1);               ///正方塊
    glPopMatrix();
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glColor3f(1,1,1);               ///白色
    glutSolidCube(1);               ///身體

    glPushMatrix();
        glTranslatef(0.5,0.5,0);            ///掛到右上角去
        glRotatef(angle,0,0,1);             ///轉它
        glTranslatef(0.25,0,0);             ///
        glColor3f(0,1,0);
        myCube();

    glPopMatrix();

    glPushMatrix();
        glTranslatef(-0.5,0.5,0);
        glRotatef(angle,0,0,1);
        glTranslatef(0.25,0,0);
        glColor3f(0,1,0);
    glPopMatrix();

    glutSwapBuffers();
    angle++;
}

int main(int argc,char *argv[])

{

    glutInit(&argc , argv);

    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE |GL_DEPTH);



    glutCreateWindow("week05");



    glutDisplayFunc(display);

    glutIdleFunc(display);

    glutMainLoop();

}

Step 3:觀察圖形移動路徑,完成!







Week 05-3.2


Step 1:開啟CodeBlock並開啟GLUT projcet

Step 2:複製下列程式碼進GLUT project


程式碼:

#include <GL/glut.h>
float angle = 0;
void cube()
{
    glPushMatrix();
    glScalef(0.5,0.2,0.2);
    glutSolidCube(1);
    glPopMatrix();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glColor3f(1,1,1);
glutSolidCube(1);

glPushMatrix();
glTranslatef(0.5,0.5,0);
glRotatef(angle,0,0,1);
glTranslatef(0.25,0,0);
glColor3f(0,1,0);
cube();
glPopMatrix();

glPushMatrix();
glTranslatef(-0.5,0.5,0);
glRotatef(angle,0,0,1);
glTranslatef(0.25,0,0);
glColor3f(0,1,0);
cube();
glPopMatrix();

        glutSwapBuffers();
angle++;
}
int main(int argc,char *argv[])
    {
        glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE| GLUT_DEPTH);
    glutCreateWindow("week05");
    glutDisplayFunc(display);
glutIdleFunc(display);
    glutMainLoop();
    }


Step 3:觀察結果,結果變為雙手擺動完成!

沒有留言:

張貼留言