2018年3月19日 星期一

week4_竜神の剣を喰らえ

上周進度:
         mouse,移動

本周主題:
        移動,旋轉,縮放
範例:Transformation.exe
期中考題

1.到jsyeh.org/3dcg10下載
   windows.zip   ,   data.zip   ,   glut32.dll


2.把windows.zip解壓後
   將glut32.dll 丟進 windows


3.將data.zip裡的data拉進windows


即可打開Transformation.exe

4.

glTranslated(x,y,z); //移動
glRotated(angle,x,y,z); //轉動
glScalef(x,y,z); //放大縮小


5. 旋轉茶壺
程式碼
#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("05160372-week4");
    glutIdleFunc(display);
    glutDisplayFunc(display);
    glutMainLoop();
}


6.用滑鼠來轉動茶壺
#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);///旋轉angle度
        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("05160372-week4");
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutDisplayFunc(display);
    glutMainLoop();
}

沒有留言:

張貼留言