2016年3月15日 星期二

Week 04 陳心瑜

一、
作業互評,選出自己最喜歡的五個作品


二、
實作 jsyeh.org/3dcg10
       glTranslatef(x,y,z);
       glRotatef(角度, x,y,z);
       glScalef(x,y,z);(1)右鍵上方換Model
(2)下方綠字可換drag
(3)下方右鍵可reset


三、

glClearColor//背景顏色
glClear(GL_COLOR_BUFFER_BIT);//清除背景
glTranslatef(x,y,z);//移動茶壺(可用mouse來動)
glColor3f//茶壺顏色



















加入glPushMatrix();//備份
glTranslatef(...);
glPopMatrix(); //還原



















四、圓for迴圈配上cos(),sin()

#include <GL/glut.h>
#include <stdio.h>//printf要宣告
#include <math.h>//cos,sin要宣告
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);
      //glutSolidTeapot(0.3);//茶壺圖案
   glBegin(GL_POLYGON);//開始畫圖//一個圖要一個BEGIN
   for(float angle=0;angle< 3.1415926358979*2;angle+=0.1){//*2兩倍ㄆㄞ=1個圓
       glVertex2f(0.2*cos(angle),0.2*sin(angle));//0.2是大小
   }
   glEnd();
   glPopMatrix();
   glutSwapBuffers();
   }
   int main(int argc,char**argv)
   {
   glutInit(&argc,argv);
   glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
   glutCreateWindow("Hello3D");
   glutDisplayFunc(mouse);
   glutMainLoop();
   }
















延伸
可以邊移動邊畫圓

沒有留言:

張貼留言