2016年5月31日 星期二

week 04 鄭玉妮


課堂作業一

旋轉


課堂作業二

印出茶壺

移動


float nowx=0, nowy=0;
void mouse (int button,int state,int x,int y)
{
    nowx= (x-150)/150.0;
    nowy= -(y-150)/150.0;
}
void display()
{
    glClearColor(0,1,0,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
        glTranslated(nowx,nowy,0);
        glColor3f (1,0,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();

}

int main (int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow ("03161104鄭玉妮");

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

課堂作業三


#include <GL/glut.h>
#include <stdio.h>
#include <math.h>
float nowx=0, nowy=0;
void mouse (int button,int state,int x,int y)
{
    nowx= (x-150)/150.0;
    nowy= -(y-150)/150.0;
    printf("glTranslatef(%f,%f,0);\n",nowx,nowy);
}
void display()
{
    glClearColor(1,1,0,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(nowx,nowy,0);
        glColor3f (1,0,0);
        ///glutSolidTeapot(0.3);
        glBegin(GL_POLYGON);
            for(float angle=0;angle<3.14159265358979*2;angle+=0.1){
                glVertex2f (0.2*cos(angle),0.2*sin(angle));
            }
        glEnd();
    glPopMatrix();
    glutSwapBuffers();

}

int main (int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow ("03161104鄭玉妮");
    glutDisplayFunc (display);
    glutMouseFunc(mouse);
    glutMainLoop ();

}



沒有留言:

張貼留言