2022年5月9日 星期一

YJ week12

T-R-T 對特定軸轉動

 1. Transformation.exe切換Swap T R 看差別

 -> 到https://jsyeh.org/3dcg10/下載win32.zip和data.zip

-> 將data資料夾放入windows資料夾中,並將Transformation.exe打開


->在下方按下滑鼠右鍵可切換



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. 將紅色茶壺掛在白色茶壺上當作手臂

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

    glutIdleFunc(display);
    glutDisplayFunc(display);
    glutMainLoop();
}



4. 再增加一個紅色小茶壺當手

#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.01;
}
int main(int argc,char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week12 TRT_TRT");
    glutIdleFunc(display);
    glutDisplayFunc(display);

    glutMainLoop();
}






沒有留言:

張貼留言