2020年3月25日 星期三

牛奶巧克力

  Ⅰ.Transformation

 1.http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/下載[data][win32],[ glut32.dll ]檔。

 2.使用window檔裡頭的transformation軟體。


 3.安培右手定則尋找軸


  ※(旋轉,x,y,z)  ///x,y,z決定軸的方向。


********************************************************
********************************************************
********************************************************

  ※旋轉茶壺(未完成)

#include <GL/glut.h>
float myAngle=0;
void motion(int x,int y)
{
    myAngle=x;
    glutPostRedisplay();
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);///清理畫面
    glPopMatrix();
        glRotatef(myAngle,0,0,1);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week04");

    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}
※遭遇的問題:旋轉有問題,滑鼠點左邊茶壺為正面,點右邊茶壺為反面。


#include <GL/glut.h>
float myAngle=0,oldX=0;
void motion(int x,int y)
{
    myAngle+=(x-oldX);///新舊角度替代
    oldX=x;
    glutPostRedisplay();
}

void mouse(int button,int state, int x,int y)
{
    oldX=x;
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPopMatrix();
        glRotatef(myAngle,0,0,1);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}


int main(int argc, char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week04");

    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMouseFunc(mouse);
    glutMainLoop();
}
 ※原理為如下

沒有留言:

張貼留言