2016年3月15日 星期二

01370984_Week_04_CW

Week_04
Class_Work_01

Choose  TOP 5 homework.





Class_Work_02

You can use your right hand and thumb to easily understand how to rotation.



Class_Work_03



Class_Work_04



Source Code:

#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();
    glTranslatef(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("01370984_Week4");

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

Class_Work_05


Source Code:

#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(0.6,0.4,0.8);

    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("01370984_Week4");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();
}

沒有留言:

張貼留言