2022年5月9日 星期一

xyt week12

 week12

1.到 https://jsyeh.org/3dcg10/

下載data、win32,將win32解壓縮並把data丟進win32,並開啟Transformation.exe

切換swap translate/rotate 查看公轉以及自轉的差別 

2.進入https://120.125.80.50/GL/親自實測TRT之間的關係

3.白色旋轉茶壺

  • 開啟CodeBlocks新增Glut檔 檔名為week12_TRT
  • 將白色茶壺程式碼丟進去,並調整Tranformation使茶壺把手為中心點

```c
#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();
    return 0;
}
```

4.將紅色茶壺掛在白色茶壺上

  • 開啟CodeBlocks新增Glut檔 檔名為week12_TRT_TRT

```c
#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.2, 0 , 0);///把下面旋轉中的物品掛在某處
        glRotatef( angle, 0, 0, 1 );///旋轉
        glTranslatef( 0.2, -0.07, 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();
    return 0;
}
```

5.紅色茶壺2掛在紅色茶壺1上 紅色茶壺1掛在白色茶壺上

```c
#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.07, 0 );///往右下移動
        glColor3f(1, 0, 0 );///紅色的
        glutSolidTeapot( 0.2 );///茶壺
        glPushMatrix();
            glTranslatef(0.3, 0 , 0);///把下面旋轉中的物品掛在某處
            glRotatef( angle, 0, 0, 1 );///旋轉
            glTranslatef( 0.2, -0.07, 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();
    return 0;
}
```



沒有留言:

張貼留言