2022年5月10日 星期二

OuO圖學筆記Week12

 step:1-1.在 https://jsyeh.org/3dcg10,下載data , win32

 step:1-2.解壓縮,把data放到windows裡

 step:1-3.開Transformation.exe


step:2-1.打 120.125.80.50/GL 練習

step:2-2.點 ToDraw,可在左邊黑色方塊畫圖(如下圖)

step:2-3.ctrl+R Reload可以清空

step:2-4.畫身體跟手臂,改程式碼順序,按angle 再按空白建,會自動旋轉



step:2-5.點 glTranslatef ,可以移動左邊的東西


step:3-1.開 CodeBlocks/GLUT/GLUT
step:3-2.貼十行程式 ///茶壺會一直轉

#include <GL/glut.h>

float angle=0;

void display()

{

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glPushMatrix();

        ///glTranslatef(0,0,0);

        glRotatef(angle,0,0,1);

        ///glTranslatef(0,0,0);

        glutSolidTeapot(0.3);

    glPopMatrix();

    glutSwapBuffers();

    angle+=0.02;///速度太快再加一個0

}

int main(int argc,char**argv)

{

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);

    glutCreateWindow("Week12 TRT");

    glutIdleFunc(display);

    glutDisplayFunc(display);

    glutMainLoop();

}


#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.4, 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();
}

#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.4,0,0);///把茶壺掛右邊
        glRotatef(angle,0,0,1);///旋轉
        glTranslatef(0.2,0,0);///軸心放中間
        glColor3f(1,0,0);///紅
        glutSolidTeapot(0.2);///手臂茶壺
        glPushMatrix();
            glTranslatef(0.4,0,0);///把茶壺掛右邊
            glRotatef(angle,0,0,1);///旋轉
            glTranslatef(0.2,0,0);///軸心放中間
            glColor3f(1,0,0);///紅
            glutSolidTeapot(0.2);///手臂茶壺
        glPopMatrix();
    glPopMatrix();

    glPushMatrix();///左手臂
        glTranslatef(-0.4,0,0);///把茶壺掛右邊
        glRotatef(-angle,0,0,1);///旋轉
        glTranslatef(-0.2,0,0);///軸心放中間
        glColor3f(1,0,0);///紅
        glutSolidTeapot(0.2);///手臂茶壺
        glPushMatrix();
            glTranslatef(-0.4,0,0);///把茶壺掛右邊
            glRotatef(-angle,0,0,1);///旋轉
            glTranslatef(-0.2,0,0);///軸心放中間
            glColor3f(1,0,0);///紅
            glutSolidTeapot(0.2);///手臂茶壺
        glPopMatrix();
    glPopMatrix();

    glutSwapBuffers();
    angle+=0.05;
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Week12 TRT");

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


沒有留言:

張貼留言

VERY BEAUTIFUL, VERY POWERFUL

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