2016年3月14日 星期一

03160490

課堂作業 1

作業互評











課堂作業 2

先去 http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/ 
下載 
1. data  2. window32  3. glut32dill
解壓縮檔
解壓縮window32到桌面
解壓縮data到window32裡
把glut32dill執行檔放到winow32裡面
然後執行shapes

*f是浮點數
glTranslatef(x,y,z); //移位
glRotatef(角度, x,y,z); //旋轉
glScalef(x, y, z); //變形

課堂作業 3

使用滑鼠快速寫程式



#include <GL/glut.h>
#include <stdio.h>
void mouse(int button,int state,int x,int y)
{
    if(state==GLUT_DOWN)
        printf("        glVertex2f((%d-150)/150.0, -(%d-150)/150.0 ); \n",x,y);
}
void display()
{
    glClearColor(150/255.0,170/255.0,55/255.2,1);
    glClear(GL_COLOR_BUFFER_BIT);

    glColor3ub(175,193,81);
    glBegin(GL_POLYGON);
    glVertex2f((145-150)/150.0, -(93-150)/150.0 );
      glVertex2f((58-150)/150.0, -(144-150)/150.0 );
      glVertex2f((143-150)/150.0, -(231-150)/150.0 );
      glVertex2f((222-150)/150.0, -(167-150)/150.0 );

*此區使用小黑窗複製貼上
    glEnd();

glutSwapBuffers();

}
int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("hello");
    glutDisplayFunc(display);
    glutMouseFunc(mouse); //用滑鼠來取點
    glutMainLoop();
}

課堂作業 4


#include <GL/glut.h>
#include <stdio.h>
#include <math.h> *要記得用三角函式
void mouse(int button,int state,int x,int y)
{
    if(state==GLUT_DOWN)
        printf("        glVertex2f((%d-150)/150.0, -(%d-150)/150.0 ); \n",x,y);
}
void display()
{
    glClearColor(150/255.0,170/255.0,55/255.2,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3ub(175,193,81);

    glPushMatrix(); //把位置備份起來
        glBegin(GL_POLYGON);
        for(float angle=0; angle<3.14159265357989 *2; angle+=0.1){
            glVertex2f(0.2*cos(angle), 0.2*sin(angle));
        }
        glEnd();
    glPopMatrix(); //移動位置後再把原本備份的拿出來
    glPushMatrix();
        glTranslatef(0,0.5,0);
        glBegin(GL_POLYGON);
        for(float angle=0; angle<3.14159265357989 *2; angle+=0.1){
            glVertex2f(0.2*cos(angle), 0.2*sin(angle));
        }
        glEnd();
    glPopMatrix();
    glPushMatrix();
        glTranslatef(-0.5,0,0);
        glBegin(GL_POLYGON);
        for(float angle=0; angle<3.14159265357989 *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("hello");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();
}

沒有留言:

張貼留言