2022年5月10日 星期二

week12

 http://jsyeh.org/3dcg10下載

  windows.zip >下載\windows\Transformation.exe

  data.zip >下載\windows\data\模型

  source.zip

T移動、R轉動,右鍵 swap交換T R

```cpp

glTransslatef(0..9,0.0,0.0); //移右邊

glRotatef(角度,0,1,0); //轉動

```

2.

```cpp

glpushMatrix();

    glRotatef(angle,0,0,1);

    myDrawObject(1);//畫手臂

glPopMatrix();

```

step02

```cpp

glpushMatrix();

    myDrawObject(0);//畫身體

    glRotatef(angle,0,0,1);

    glTranslatef(-0.3,-0.19,0);//往左下移

    myDrawObject(1);//畫手臂

glPopMatrix();

```


```cpp

glpushMatrix();

    myDrawObject(0);//畫身體

    glTranslatef(0.29,0.31,0);//往右上移

    glRotatef(angle,0,0,1);

    glTranslatef(-0.3,-0.19,0);//往左下移

    myDrawObject(1);//畫手臂

glPopMatrix();

```

2.

```cpp

glpushMatrix();

    glTranslatef(0.29,0.31,0);//往右上移

    glRotatef(-45,0,0,1);

    glTranslatef(-0.8,0.9,0);

    glTranslatef(-0.8,0.9,0);;

    drawHand();

glPopMatrix();

```
3.
codeblocks week12_TRT
gl 10行
TRT 6行
```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);
        glutSolidTeapot(0.2);
    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();
}
```

step03
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.2,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();
}
```


2.回家作業
3D模型  TRT程式

3.左右手
```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,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();

    glPushMatrix();///左手
        glTranslatef(-0.2,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 TRT");
    glutIdleFunc(display);
    glutDisplayFunc(display);
    glutMainLoop();
}
```

沒有留言:

張貼留言

VERY BEAUTIFUL, VERY POWERFUL

一.     一樣先安裝且設定好freeglut,OpecCV, 開啟CodeBlocks建立新專案 week11_gundam,                 把 MyGundam.zip下載解壓縮後的data資料夾放到freeglut/bin裡面 把week09_openc...