2016年3月15日 星期二

Week 04 吳東峻

課堂作業一
作業互評上傳
用7-Zip解壓縮
小心別用Adobe打開

挑出你認為最好的5張上傳











課堂作業二

從網址下載: sorce , date , win32 ,glut32.dll ( jsyeh.org/3dcg10 )



解壓縮win32
把 data 打開,將裡面的資料夾複製到上面解壓縮後的window32資料夾
再將 glut32.dll 移至window32資料夾


執行Transformation


soccerball


AI Capone


F16 Jet


Dolphins


Flower


Rose


點glTranslatef 移動



點glRotatef旋轉



點glScalef縮放大小



課堂作業三
Mouse 操作

茶壺會一直移動


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

void display()
{
    glClearColor(1,1,0,1);
    glClear(GL_COLOR_BUFFER_BIT);

    glTranslatef(0, -0.1, 0);///按一下往下0.1
    glColor3f(1,0,0);
    glutSolidTeapot(0.3);


    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Hello");

    glutDisplayFunc(display);


    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();///備份Mstrix
    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("Hello 3D");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();

}


課堂作業四

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(1,1,0,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();///備份Mstrix
    glTranslatef(nowX,nowY,0);///怎麼越動越多??
    glColor3f(1,0,0);
    ///glutSolidTeapot(0.3);
    glBegin(GL_POLYGON);
        for(float angle=0; angle<3.14159235358979*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();
}



沒有留言:

張貼留言