2018年3月26日 星期一

Week05老王

連結:http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
下載Win32.zip / data.zip / glut32.dll 



開啟Transformation.exe.
旋轉方式是原地轉
另一種方式是沿著中心點公轉



執行公轉
轉不同方向


用不同方式轉動

茶壺程式碼



移動茶壺的角度(移動中心點位置)

#include <GL/glut.h>
float angle=0;
void motion(int x, int y)
{
    angle=x;
    glutPostRedisplay();
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
    
    glRotatef(angle, 0,0,1);
    glTranslatef(0.45, -0.08, 0);
    glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week05 TRT");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}






#include <GL/glut.h>float angle=0; void motion(int x,int y)  {    angle=x;    glutPostRedisplay(); }void display() {    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);     glPushMatrix();          glutSolidTeapot(0.3);                glTranslatef(0.5,0.15,0);         glRotatef(angle,0,0,1);         glTranslatef(0.45,-0.08,0);         glutSolidTeapot(0.3);     glPopMatrix();     glutSwapBuffers();}int main(int argc, char**argv){    glutInit(&argc,argv);    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);    glutCreateWindow("week05_TRT");    glutDisplayFunc(display);    glutMotionFunc(motion);    glutMainLoop();}
老師講解

#include<GL/glut.h>
float angle=0;
void motion(int x,int y)
{
    angle=x;
    glutPostRedisplay();
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glutSolidTeapot(0.3);
        glPushMatrix();
            glTranslatef(0.5,0.15,0);
            glRotatef(angle,0,0,1);
            glTranslatef(0.45,-0.08,0);
            glutSolidTeapot(0.3);
        glPushMatrix();
            glTranslatef(0.5,0.15,0);
            glRotatef(angle,0,0,1);
            glTranslatef(0.45,-0.08,0);
            glutSolidTeapot(0.3);
        glPopMatrix();
    glPopMatrix();


    glPushMatrix();
            glTranslatef(-0.5,0.15,0);
            glRotatef(angle,0,0,1);
            glTranslatef(-0.45,-0.08,0);
            glutSolidTeapot(0.3);

            glPushMatrix();
            glTranslatef(-0.5,0.15,0);
            glRotatef(angle,0,0,1);
            glTranslatef(-0.45,-0.08,0);
            glutSolidTeapot(0.3);
        glPopMatrix();
    glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();


}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week05 TRT");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}

老師講解

沒有留言:

張貼留言