2016年3月15日 星期二

Week04 呂汶佶


Hw1

作業互評






Hw02

旋轉軸
右手安培定則




Hw3

glTranslatef(0, 0.1, 0); //每次移動0.1



Hw4

滑鼠點到哪茶壺動到哪


程式碼

#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("I LOVE APPLE PIE");  //視窗名稱
    glutDisplayFunc(display);  //展示
    glutMouseFunc(mouse);
    glutMainLoop();
}

補充畫圓<滑鼠點到哪圓動到哪>



      glBegin(GL_POLYGON);
      for(float angle=0; angle<3.14159265358979*2; angle+=0.1)
      {
        glVertex2f(0.2*cos(angle),0.2*sin(angle))  ;
      }







沒有留言:

張貼留言