2016年3月15日 星期二

Week 04 張歆

作業1 作業互評







作業2 移動 旋轉 縮放
開啟 jsyeh.org/3dcg10
下載 data / windows / glut32.dll

開啟Transformation
glTranslatef (x, y, z)
glRotatef 角度 (旋轉, x, y, z)
glScalef調大小 (x, y, z)












作業3 教材與實作






移動滑鼠可移動茶壺位置
#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(0.8, 1, 0, 1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();///備份Matrix
        glTranslatef(nowX, nowY, 0);///移動
        glColor3f(0, 0, 1);
        glutSolidTeapot(0.3);
    glPopMatrix();///還原Matrix
    glutSwapBuffers();
}
int main(int argc,char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Hello 3D");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();
}


作業4 Mouse 進階




#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(0.8, 1, 0, 1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();///備份Matrix
        glTranslatef(nowX, nowY, 0);///移動
        glColor3f(0, 0.5, 1);
        //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("Hello 3D");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();
}

沒有留言:

張貼留言