2016年3月15日 星期二

Week 04 鄧玉婷

課堂作業1:

作業互評 7-Zip解壓縮>上傳到moodle




課堂作業2:

一樣下載3個檔案後>開啟 Transformation 練習

本週3個重點程式碼:
glTranslatef(x,y,z);
glRotatef(角度,x,y,z);
glScalef(x,y,z);


*小技巧-箭頭方向為右手大拇指
剩下的四隻手指就是旋轉方向!


練習glRotatef(角度,x,y,z); !!!

課堂作業3:


[移動小視窗茶壺也會跟著動]

#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("hello3D");

    glutDisplayFunc(display);
    ///glutMouseFunc(mouse);

    glutMainLoop();
}


[茶壺會移到滑鼠點擊的地方]

#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("hello3D");

    glutDisplayFunc(display);
    glutMouseFunc(mouse);

    glutMainLoop();
}


課堂作業4:

練習用程式碼畫圓>>米老鼠


[☆=重要程式碼 框框=沒*2是半圓 底線=調整圓大小]

#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,1,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();///備份Matrix
        glTranslatef(nowX, nowY,0);///怎麼越動越多?
        glColor3f(0,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("hello3D");

    glutDisplayFunc(display);
    glutMouseFunc(mouse);

    glutMainLoop();
}





沒有留言:

張貼留言