2018年3月23日 星期五

Week04-04160453

1.看看旋轉

a.下載上禮拜講的教學檔案
b.看看Projection檔案

2.旋轉

 a.把上周的程式拿來用
b.輸入
flofut teapotX=0, teapotY=0,angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(teapotX,teapotY,0);
        glRotatef(angle,0,0,1);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}


void motion(int x, int y)
{
    angle=x;
    glutPostRedisplay();
}
#include <stdio.h>
#include <GL/glut.h>
float teapotX=0, teapotY=0,angle=0;
int nowRotate=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(teapotX,teapotY,0);
        glRotatef(angle,0,0,1);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}


void motion(int x, int y)
{
    if(nowRotate==1) angle=x;
    else{
        teapotX=(x-150)/150.0;
        teapotY=(150-y)/150.0;
    }
    glutPostRedisplay();
}
void mouse(int button,int state,int x,int y)
{
    if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN) nowRotate=1;
    if(button==GLUT_RIGHT_BUTTON && state==GLUT_DOWN) nowRotate==0;
}

int main(int argc, char**argv)
{
    glutInit(&argc,argv);///初始的參數 照著丟進去
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);///兩個顯示的參數
    glutCreateWindow("Week04 Rotate");///本周的windows標題

    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);

    glutMainLoop();///主要的GLUT迴圈
}

3.期中考80分

glPushMatrix();  //備份矩陣
        glTranslatef(x,y,z);      //移動
        glRotatef(angle,x,y,z);      //轉動
        glScalef(x,y,z);      //縮放
        glBegin(GL_POLYGON);     //開始畫
                glColor3f(r,g,b);    //顏色
                glVertex3f(x,y,z);頂點
         glEnd();     //結束畫
glPopMatrix();     // 還原矩陣

沒有留言:

張貼留言