2022年5月10日 星期二

電腦圖學筆記

 


主題主題: T-R-T (移動、旋輚、移動)對特定軸轉動

打開windows裡的Transformation.exe

下方右鍵點選Swap Translate/Rotate讓車子看起來在轉

glTranslatef( 0.9 , 0.0 , 0.0 );移動

glrotatef(角度,0,1,0);旋轉

=========================================================================

https://120.125.80.50/GL/ 期中考、小考題

Ctrl-R Reload可以清空

畫個身體 叫 MyDrawObject(0)

畫個手臂 叫 MyDrawObject(1)

可以改程式碼順序 再按空白鍵 會改變成動畫


下禮拜考試題目


=========================================================================

#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.0,0.0,0);

        glutSolidTeapot(0.3);

    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();

}

白色旋轉茶壺
=========================================================================
#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();

}
加一個紅色茶壺當手臂
=========================================================================

#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.1;

}

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.2,0,0);///(3)掛到右邊(整個往動)
        glRotatef(angle, 0,0,1);///(2)旋轉
        glTranslatef(0.2,0,0);
        glColor3f(1,0,0);
        glutSolidTeapot(0.2);///小茶壺,當作小手臂
        glPushMatrix();
            glTranslatef(0.2,0,0);///(3)掛到右邊(整個往動)
            glRotatef(angle, 0,0,1);///(2)旋轉
            glTranslatef(0.2,0,0);
            glColor3f(1,0,0);
            glutSolidTeapot(0.2);///小茶壺,當作小手肘
        glPopMatrix();
    glPopMatrix();

    glPushMatrix();///左邊的手臂手肘
        glTranslatef(-0.2,0,0);///(3)掛到左邊(整個往動)
        glRotatef(-angle, 0,0,1);///(2)旋轉
        glTranslatef(-0.2,0,0);
        glColor3f(1,0,0);
        glutSolidTeapot(0.2);///小茶壺,當作小手臂
        glPushMatrix();
            glTranslatef(-0.2,0,0);///(3)掛到左邊(整個往動)
            glRotatef(-angle, 0,0,1);///(2)旋轉
            glTranslatef(-0.2,0,0);
            glColor3f(1,0,0);
            glutSolidTeapot(0.2);///小茶壺,當作小手肘
        glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();
    angle+=0.01; ///每次執行 display() 加1度
}
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...