2016年3月14日 星期一

week04_03161076

課堂作業week04




課堂作業1



作業互評票選





課堂作業2


使用glTranslate 改變位置
glRotatef 旋轉角度
使用glScalef 改變模型的長寬以及亮度













課堂作業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(1,1,1,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glutSwapBuffers();

    glColor3f(135/255.0,203/255.0,240/255.0);
    glBegin(GL_POLYGON);
glVertex2f((135-150)/150.0,(69-150)/150.0);
glVertex2f((65-150)/150.0,(150-150)/150.0);
glVertex2f((144-150)/150.0,(223-150)/150.0);
glVertex2f((253-150)/150.0,(162-150)/150.0);
    glEnd();
    glutSwapBuffers();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);//開啟
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);//雙重顯示模式
    glutCreateWindow("Hello 3D");//開視窗
    glutMouseFunc(mouse);
    glutDisplayFunc(display);//執行display程式
    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(1,1,1,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glutSwapBuffers();
    glColor3f(255/255.0,0/255.0,0/255.0);


    glPushMatrix();
    glTranslatef(0,0,0);
    glBegin(GL_POLYGON);
    for(float angle=0; angle<3.1415926535*2 ; angle+=0.1) //*2就是一個圓,*1只有半圓
    {
            glVertex2f(0.3*cos(angle), 0.3*sin(angle)); //調整圓的大小
    }
    glEnd();
    glPopMatrix();


    glPushMatrix();
    glTranslatef(0.3,0.3,0);
//改變位置
    glBegin(GL_POLYGON);
    for(float angle=0; angle<3.1415926535 *2; angle+=0.1)
    {
            glVertex2f(0.2*cos(angle), 0.2*sin(angle));
    }
    glEnd();
    glPopMatrix();


    glPushMatrix();
    glTranslatef(-0.3,0.3,0);
    glBegin(GL_POLYGON);
    for(float angle=0; angle<3.1415926535 *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 3D");//開視窗
    glutMouseFunc(mouse);
    glutDisplayFunc(display);//執行display程式
    glutMainLoop();
}

沒有留言:

張貼留言