2016年3月15日 星期二

Week 04 蔡宜真

課堂作業1

作業互評,選五張你覺得最好的作品



















課堂作業2

點選教材:Transformation

glTranslatef(x,y,z);
glRoates(角度,x,y,z);
glScalef(x,y,z);

練習Roates

(圖一)箭頭代表x軸




















(圖二)箭頭代表y軸























(圖三)圈起來的是旋轉角度























大拇指代表的是箭頭
4根手指頭是旋轉的角度方向(右手安培定律)


課堂作業三

part1.

加入glTranslatef(0,0.1,0); 這行
茶壺會向上移動,跑出視窗外
















part2

加入紅色程式碼,
就可以點選你想要的位置,
如下:


















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

    glutDisplayFunc (display);
    glutMouseFunc(mouse);
    glutMainLoop ();
}

part3

加入#include<math.h>
可以做數學運算,做出可愛的圓型

透過游標點選想要的位置,可以印出座標(x,y)




#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();
        glTranslatef(nowx,nowy,0);
        glColor3f (0,0,0);
        
        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();
    glutSwapBuffers();

}

int main (int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow ("hello");
    glutDisplayFunc (display);
    glutMouseFunc(mouse);
    glutMainLoop ();

}

*老師額外補充





沒有留言:

張貼留言