2022年5月9日 星期一

Kuo's Graphic_Note_Week12

 

Step 1 : Using Example (Light Material.exe) to Know What We Want to Make.

    1-1.Download Example (URL: https://jsyeh.org/3dcg10/)

    

    1-2. Put file "data" to file "windows"


    1-3. Open example (Path:windows/Transformation.exe)


    1-4. Open Transformation.exe


    1-5. Where is the axis of rotation and how to rotate



     1-6. Rotating



     1-7. Swap translate/rotate


    
     1-8. Where is the axis of rotation and how to rotate


    1-9. Rotating


     1-10. Grouping and explanation


     1-11. Grouping and explanation


Step 2 : Using the Website to Simulate OpenGL

    2-1. Open the website      

    (URL:https://120.125.80.50/GL/opengl_TRT_demo.html)

   2-2. Using this website to draw a graphics


   2-3. Change the place of "myDrawObject(0);" , then press "Space" to rotate the triangle


Step 3 :  Using CodeBlocks to Make "TRT".

    3-1. Coding (Make a white teapot)


    3-2. Build & Run


    3-3. Coding



    3-4. Build & Run



    3-5. Coding



    3-6. Build & Run



Final Code:

#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++;
}
int main(int argc,char**argv){
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week12 TRT");
    glutIdleFunc(display);
    glutDisplayFunc(display);
    glutMainLoop();
}


Step 4 :  Using CodeBlocks to Make "TRT".

    4-1. Coding


    4-2. Build & Run


    4-3. Coding

    4-4. Build & Run


    4-5. Coding


   4-6. Build & Run

Final Code:

#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++;
}
int main(int argc,char**argv){
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week12 TRT");
    glutIdleFunc(display);
    glutDisplayFunc(display);
    glutMainLoop();

}


沒有留言:

張貼留言