2022年3月8日 星期二

(圖學筆記)電腦圖學Week03

 week03

step01-1 打開網頁https://jsyeh.org/3dcg10/ 下載win32.zip 以及data.zip

step01-2 解壓縮 windows至windows資料夾並且將data資料夾放入windows資料夾

step01-3 打開Tranformation.exe 嘗試使用

            (右鍵切換模型)(下方可以控制)



step02-1打開上周的程式碼

step02-2

    #include<GL/glut.h>

void display()

{

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();

        glTranslatef(0.5,0.5,0);//位置

        glColor3f(1,1,0);//色彩

        glutSolidTeapot(0.3);

    glPopMatrix();

    glutSwapBuffers();

}

int main(int argc,char** argv)

{

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("week03移動");

    glutDisplayFunc(display);

    glutMainLoop();

}


step02-3 執行可看到茶壺在右上角



step02-4更改程式碼為

#include<GL/glut.h>

void myTeapot(float x,float y)

{

    glPushMatrix();

        glTranslatef(x,y,0);

        glColor3f(1,1,0);

        glutSolidTeapot(0.3);

    glPopMatrix();

}

void display()

{

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    myTeapot(0.5,0.5);//位置

    myTeapot(0.5,-0.5);

    myTeapot(-0.5,-0.5);

    myTeapot(-0.5,0.5);

    glutSwapBuffers();

}

int main(int argc,char** argv)

{

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("week03移動");

    glutDisplayFunc(display);

    glutMainLoop();

}

step02-5可看到分別在四角的茶壺

step02-6更改程式
#include<GL/glut.h>
float mousex=0,mousey=0;//滑鼠座標
void myTeapot(float x,float y)
{
    glPushMatrix();
        glTranslatef(x,y,0);
        glColor3f(1,1,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
}
void display()
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    myTeapot((mousex-150)/150.0,-(mousey-150)/150.0);
    glutSwapBuffers();
}
void mouse(int button,int state,int x,int y)//滑鼠函式
{
    mousex=x;mousey=y;
}
int main(int argc,char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week03移動");
    glutDisplayFunc(display);

    glutMouseFunc(mouse);//滑鼠事件
    glutMainLoop();
}
step02-7可得到用滑鼠移動的茶壺




沒有留言:

張貼留言

VERY BEAUTIFUL, VERY POWERFUL

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