2017年3月20日 星期一

Week 04 20170320 鄭雅至的課堂筆記

Week 04 課堂筆記


HW 1

1.  到網頁上(jsyeh.org/3dcg10)下載data.zipwindow.zipglut32.dll
2.  打開window.zip裡的 Transformation.exe 。




HW 2


開啟GLUT的程式,比上週多寫一行程式碼。




程式碼:

#include <GL/glut.h>
void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
    glTranslatef(0.5,0,0);
    glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}


HW 3


移動。



程式碼:

#include <GL/glut.h>
float mouseX=0, mouseY=0;
void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(mouseX,mouseY,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}

void motion(int x, int y)
{
    mouseX= (x-150)/150.0;
    mouseY=-(y-150)/150.0;
    glutPostRedisplay;
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("GLUT Shapes");

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


HW 4


放大縮小。




程式碼:

void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glScalef(mouseX,mouseY,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}


**小精靈





程式碼:

#include <GL/glut.h>
#include <math.h>
float mouth=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ///把畫面清空,才能再重畫的時候沒有殘影
    glColor3f(1,1,0); ///顏色
    glBegin(GL_TRIANGLE_FAN); ///開始畫
        glVertex2f(0,0); ///圓心
        for(float angle = 0+mouth;angle <= 3.1415926*2-mouth;angle += 0.01){
            glVertex2f( cos(angle), sin(angle));
        }
    glEnd(); ///結束畫
    glutSwapBuffers();
}

void motion(int x, int y)
{
    mouth=x/300.0;
    glutPostRedisplay;
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("GLUT Shapes");

    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();

}


沒有留言:

張貼留言