2023年3月16日 星期四

toto_week05

 Week05

step01-1

至https://jsyeh.org/3dcg10,下載windows.zip and data.zip

        -windows.zip 解壓縮 下載 \windows\Transformation.exe

        -data.zip         解壓縮 下載\windows\data\有3D模型



複習上周的「移動-旋轉」和「旋轉-移動」




step01-2
CodeBlocks-File_New_Project,GLUT專案,檔名為week05-1_TRT_translates_rotate



///旋轉軸改成0,0,1 z軸,再複製成紅色、綠色
#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();
        glRotatef(angle*1.5,0,0,1);
        glTranslatef(0.8,0,0);
        glutSolidTeapot(0.3);
    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();
}


step02-1
利用老師的openg1_TRT_demo的互動程式,跑起來。暗助ToDraw可以畫出身體、畫頭、畫手。按住程式碼,移動他的位置。先只放一個選轉(在手的前面,只影響手)會對著正中心旋轉,有點怪怪的。改成移動,讓手臂的觀及移到正中心。再來,把轉動加上去,手臂會在肚臍上轉動。最後,把移動加上去,讓旋轉中的手臂「掛」在肩膀上。

‵‵‵‵cpp
myDrawObject(0);
glPushMatrix();
    glTranslatef(0.17,0.38,0);
glRotatef(angle,0,0,1);
glTranslatef(-0.17,-0.38,0);
myDrqwObject(1);
glPopMatrix();
```

step02-2
講解下周的考試題目,以奇異博士手上拿著寶石為例,drawHand()可以畫手但他的旋轉中心沒有放在正中心,怎麼辦(1)先把關節移到正中心(2)上面再加上轉動,小心轉動軸不要寫錯、角度的正負號也不能寫錯(3)最後,最上面,就簡單地把會轉動的手拼在一起,手肘上面去。


step03-1
CodeBlocks-File_New_Project,GLUT專案,檔名為week05-1_TRT_robot

#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);
        myCube();
    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();
}

step03-2
看兩部影片

step04-1
上傳github







沒有留言:

張貼留言