2018年3月16日 星期五

Week03 吳姿諭

用shape來看繪製的圖形

先到http://jsyeh.org/3dcg10下載data、windows、glut32.dll檔案,解壓縮後把glut32.dll複製到windows裡面,再開啟shape即可


畫茶壺

#include <stdio.h>
#include <GL/glut.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glutSolidTeapot(0.3);
    glutSwapBuffers();
}

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week03 Mouse");

    glutDisplayFunc(display);
    glutMainLoop();
}

讓茶壺跟著滑鼠移動

#include <stdio.h>
#include <GL/glut.h>
float teapotX=0, teapotY=0;

void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(teapotX, teapotY, 0);
        glutSolidTeapot(0.3);
        glPopMatrix();
    glutSwapBuffers();
}

void mouse(int button, int state, int x, int y)
{

}

void motion(int x, int y)
{
    teapotX=(x-150)/150.0; teapotY=(150-y)/150.0;
    glutPostRedisplay();
}

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week03 Mouse");

    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}


沒有留言:

張貼留言