2019年3月14日 星期四

金魚腦波學W4


電腦圖學

1.     主題:移動
2.     示範:glTranslatef(x,y,z)
3.     主題:滑鼠

*Transformation移動
右手原則
1.下載data,win32,glut32.dll
2.window解壓縮至E
3.data壓縮檔打開丟入window
4.glut32.dll移動到window


Codeblocks開glut

1.搜尋freeglut windows>>MinGW>>Download>>放桌面解壓縮>>lib資料夾>>libfreeglut.a,複製>>命名libglut32.a>>複製偽製貼codeblocks

W3作業

快吐血了!

茶壺叫出來
#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("week04");
    glutDisplayFunc(display);
    glutMainLoop();
}

實作:滑鼠移動茶壺

#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();
}
*motion滑動




沒有留言:

張貼留言