2015年5月28日 星期四

WEEK14.Homework5/28.

程式碼:
#include <GL/glut.h>

void display()
{
    GLfloat pos[] = {0, 0, -1, 0};
    glLightfv(GL_LIGHT0, GL_POSITION, pos);
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHTING);
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glutSolidTeapot(0.3);
    glFlush();
}

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("TRT3D");
    glutDisplayFunc(display);

    glutMainLoop();
}

程式碼:
#include <GL/glut.h>

void display()
{
    {
        GLfloat pos[] = {0, 0, -1, 0};
        glLightfv(GL_LIGHT0, GL_POSITION, pos);
        glEnable(GL_LIGHT0);
        glEnable(GL_LIGHTING);
    }
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
    glTranslatef(0.5,0,0);///version 2: teapot on the right
    glutSolidTeapot(0.3);///version 1: A teapot
    glPopMatrix();
    glFlush();
}

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("TRT3D");
    glutDisplayFunc(display);

    glutMainLoop();
}

程式碼:
#include <GL/glut.h>
float angle=0;
void display()
{
    {
        GLfloat pos[] = {0, 0, -1, 0};
        glLightfv(GL_LIGHT0, GL_POSITION, pos);
        glEnable(GL_LIGHT0);
        glEnable(GL_LIGHTING);
    }
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(angle, 0, 0, 1);///versoin 3:rotating teapot on the handle
        glTranslatef(0.5,0,0);///version 2: teapot on the right
        glutSolidTeapot(0.3);///version 3: A teapot
    glPopMatrix();
    glFlush();
}
void timer(int t)
{
    glutTimerFunc(20, timer, 0);
    angle++;
    glutPostRedisplay();
}
int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("TRT3D");
    glutDisplayFunc(display);
    glutTimerFunc(20, timer, 0);
    glutMainLoop();
}

程式碼:
#include <GL/glut.h>
float angle=0, oldX=0, oldY=0;
void display()
{
    {
        GLfloat pos[] = {0, 0, -1, 0};
        glLightfv(GL_LIGHT0, GL_POSITION, pos);
        glEnable(GL_LIGHT0);
        glEnable(GL_LIGHTING);
    }
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(angle, 0, 0, 1);///versoin 3:rotating teapot on the handle
        glTranslatef(0.5,0,0);///version 2: teapot on the right
        glutSolidTeapot(0.3);///version 3: A teapot
    glPopMatrix();
    glFlush();
}
void timer(int t)
{
    glutTimerFunc(20, timer, 0);
    ///angle++;
    glutPostRedisplay();
}
void mouse(int button, int state, int x, int y)
{
    if(state==GLUT_DOWN) { oldX=x; oldY=y; }
}
void motion(int x, int y)
{
    angle += (x -oldX);
    oldX = x;
}
int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("TRT3D");
    glutDisplayFunc(display);
    glutTimerFunc(20, timer, 0);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}

程式碼:
#include <GL/glut.h>
float angle=0, oldX=0, oldY=0;
void display()
{
    {
        GLfloat pos[] = {0, 0, -1, 0};
        glLightfv(GL_LIGHT0, GL_POSITION, pos);
        glEnable(GL_LIGHT0);
        glEnable(GL_LIGHTING);
    }
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(0.45, 0.14, 0);///version 4:把樓下的整個在轉....往右掛在某個地方
        glRotatef(angle, 0, 0, 1);///versoin 3:rotating teapot on the handle
        glTranslatef(0.45, -0.1, 0);///version 2: teapot on the right
        glutSolidTeapot(0.3);///version 3: A teapot
    glPopMatrix();
    glutSolidTeapot(0.3);
    glFlush();
}
void timer(int t)
{
    glutTimerFunc(20, timer, 0);
    ///angle++;
    glutPostRedisplay();
}
void mouse(int button, int state, int x, int y)
{
    if(state==GLUT_DOWN) { oldX=x; oldY=y; }
}
void motion(int x, int y)
{
    angle += (x -oldX);
    oldX = x;
}
int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("TRT3D");
    glutDisplayFunc(display);
    glutTimerFunc(20, timer, 0);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}

程式碼:
#include <GL/glut.h>
float angle=0, oldX=0, oldY=0;
void drawArm()
{
    glPushMatrix();
    glScalef(0.5, 0.25, 0.25);
    glutSolidCube(1);
    glPopMatrix();
}
void drawBody()
{
    glPushMatrix();
    glTranslatef(0, -0.5, 0);
    glRotatef(-90, 1, 0, 0);
    glutSolidCone(0.3, 0.8, 30, 30);
    glPopMatrix();
}
void display()
{
    {
        GLfloat pos[] = {0, 0, -1, 0};
        glLightfv(GL_LIGHT0, GL_POSITION, pos);
        glEnable(GL_LIGHT0);
        glEnable(GL_LIGHTING);
    }
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(0.15, 0, 0);///version 4:把樓下的整個在轉....往右掛在某個地方
        glRotatef(angle, 0, 0, 1);///versoin 3:rotating teapot on the handle
        glTranslatef(0.25, 0, 0);///version 2: teapot on the right
        drawArm();///Right Upper-Arm
        glPushMatrix();
            glTranslatef(0.25, 0, 0);
            glRotatef(angle, 0, 0, 1);
            glTranslatef(0.25, 0, 0);
            drawArm();///Right Lower-Arm
        glPopMatrix();
    glPopMatrix();

    glPushMatrix();
        glTranslatef(-0.15, 0, 0);
        glRotatef(-angle, 0, 0, 1);
        glTranslatef(-0.25, 0, 0);
        drawArm();///Left Upper-Arm
        glPushMatrix();
            glTranslatef(-0.25, 0, 0);
            glRotatef(-angle, 0, 0, 1);
            glTranslatef(-0.25, 0, 0);
            drawArm();///Left Lower-Arm
        glPopMatrix();
    glPopMatrix();
    drawBody();//glutSolidTeapot(0.3);
    glFlush();
}
void timer(int t)
{
    glutTimerFunc(20, timer, 0);
    ///angle++;
    glutPostRedisplay();
}
void mouse(int button, int state, int x, int y)
{
    if(state==GLUT_DOWN) { oldX=x; oldY=y; }
}
void motion(int x, int y)
{
    angle += (x -oldX);
    oldX = x;
}
int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("TRT3D");
    glutDisplayFunc(display);
    glutTimerFunc(20, timer, 0);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}




沒有留言:

張貼留言