2016年3月15日 星期二

Week4

Class Work 1.作業互評








Class Work 2.





旋轉:類似安培右手定則,判定旋轉方向。

Class Work 3.



Source Code:

#include<GL/glut.h>

void display()
{

    glClearColor(1, 1, 0, 1);
    glClear(GL_COLOR_BUFFER_BIT);

    glTranslatef(0, 0.1, 0);//唉呦~怎麼越動越多呢?
    glColor3f(1, 0, 0);
    glutSolidTeapot(0.3);

    glutSwapBuffers();
}

int main(int argc, char**argv)
{

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("阿斯~");

    glutDisplayFunc(display);

    glutMainLoop();

}

Class Work 4.

















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

    glClearColor(1, 1, 0, 1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();//備份Matrix
    glTranslatef(nowX, nowY, 0);//唉呦~怎麼越動越多呢?
    glColor3f(1, 0, 0);
    glutSolidTeapot(0.3);
    glPopMatrix();//還原Matrix

    glutSwapBuffers();
}

int main(int argc, char**argv)
{

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("阿斯~");

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

Class Work 5.



#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;
}
void display()
{

    glClearColor(1, 1, 0, 1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();//備份Matrix
    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();//還原Matrix

    glutSwapBuffers();
}

int main(int argc, char**argv)
{

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("阿斯~");

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

}

會感動落淚的Code



沒有留言:

張貼留言