2019年3月14日 星期四

小畫家亂畫筆記

電腦圖學第四周------移動


任務一:


下載老師給的網址裡的檔案,將檔案都放在window的底下,接著嘗試玩玩看程式 .

注意:













完成畫面:


任務二:

開啟glut,順著第一周講義的步驟,開啟一個新的glut專案.

模仿老師打入程式碼並執行.

#include <GL/glut.h>
void display()
{
    glPushMatrix();
        glTranslatef(0.3,0.3,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();
}

注意:














完成畫面:
















任務三:

寫滑鼠控制杯子移動的程式,照著老師fb的程式碼打.

程式碼:

#include <GL/glut.h>
float x=0,y=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef((x-150)/150.0,-(y-150)/150.0,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();

}
void motion(int nowX,int nowY)
{
    x=nowX;y=nowY;
    display();
}
int main(int argc ,char**argv)

{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Week04");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();

}


完成畫面:



沒有留言:

張貼留言