2018年3月19日 星期一

Week04#Note!!!

----------------------------------------

Week04

(1)上週進展:mouse、移動
(2)主題:移動、旋轉、縮放
(3)範例:Transformation.exe
(4)期中考題

----------------------------------------

Homework-1

TODO:登入 Zuvio 回答 Week03
TODO:到 jsyeh.org/3dcg10 下載 windows.zip 、 data.zip 、glut32.dll 
                將 win32 解壓縮到桌面,glut32.dll & data 解壓縮後放置 win32 資料夾中
                使用 Transformation.exe 這個範例,換成 Rose 圖案
                
                換成 Soccerball 圖案
               

TODO:可以去試各種旋轉軸 -> glRotatef(角度 , X軸 , Y軸 , Z軸) ;

--------------------------------------------------------------------------------------------------------------------------

Homework-2


期中考題:

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();//結束畫 glBegin()對應
glPopMatrix();//還原矩陣

--------------------------------------------------------------------------------------------------------------------------

Homework-3

畫出會旋轉的茶壺

#include <GL/glut.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(angle, 0,0,1);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
    angle++;
}
int main(int argc, char*argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week04 transformation");
    glutIdleFunc(display);
    glutDisplayFunc(display);
    glutMainLoop();

}

--------------------------------------------------------------------------------------------------------------------------

畫出會旋轉的茶壺加上顯示角度

#include <stdio.h>
#include <GL/glut.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(angle, 0,0,1);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
    printf("%.1f\n",angle);
    angle++;
}
int main(int argc, char*argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week04 transformation");
    glutIdleFunc(display);
    glutDisplayFunc(display);
    glutMainLoop();

}
--------------------------------------------------------------------------------------------------------------------------

畫出茶壺能自己控制旋轉角度

#include <stdio.h>
#include <GL/glut.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(angle, 0,0,1);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
    ///printf("%.1f\n",angle);
    ///angle++;
}
void mouse(int button, int state, int x, int y)
{

}
void motion(int x, int y)
{
    angle=x;
    glutPostRedisplay();
}
int main(int argc, char*argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week04 transformation");
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    ///glutIdleFunc(display);
    glutDisplayFunc(display);
    glutMainLoop();

}

--------------------------------------------------------------------------------------------------------------------------

畫出茶壺

#include <stdio.h>
#include <GL/glut.h>
float angle=0, teapotX=0, teapotY=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();
    ///printf("%.1f\n",angle);
    ///angle++;
}
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;
}
void motion(int x, int y)
{
    if(nowRotate==1) angle=x;
    else{
        teapotX=x;
        teapotY=y;
    }
    glutPostRedisplay();
}
int main(int argc, char*argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week04 transformation");
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    ///glutIdleFunc(display);
    glutDisplayFunc(display);
    glutMainLoop();

}

--------------------------------------------------------------------------------------------------------------------------

沒有留言:

張貼留言