2020年3月24日 星期二

week 04旋轉跳躍

去fb點網址下載glut32.dll windows.zip data.zip之後把windows解壓縮glut32放進去壓縮那data也放進去壓縮那,點開Transformation會有圖片
x軸設1會上下轉

y軸設1會左右轉


z軸設1會烤乳豬轉。

接下來教可以自己用手動轉動不是他自己轉動

再來教把茶壺旋轉
#include <GL/glut.h>
float myAngle=0;///宣告變數
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清畫面
    glPushMatrix();///輩分
        glRotatef(myAngle,0,0,1);///對z軸做旋轉
        glutSolidTeapot( 0.3 );
    glPopMatrix();///還原
    glutSwapBuffers();
}
void motion(int x,int y)
{
    myAngle = x;///我的叫角度,等下藥拿來用
    display();///每次做動作,就重畫畫面
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week 04 rotate");

    glutMotionFunc(motion);///加motion函示
    glutDisplayFunc(display);
    glutMainLoop();
}
更完整的他可以把杯子一步一步的動作,不會亂掉
#include <GL/glut.h>
float myAngle=0;///宣告變數
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清畫面
    glPushMatrix();///輩分
        glRotatef(myAngle,0,0,1);///對z軸做旋轉
        glutSolidTeapot( 0.3 );
    glPopMatrix();///還原
    glutSwapBuffers();
}
int oldX=0;///宣告變數
void mouse(int button, int state, int x,int y)
{           ///(1)按下去時,要記一下你在哪???
    if(state==GLUT_DOWN) oldX = x;
}
void motion(int x,int y)
{
    myAngle += (x-oldX);///你加了多少度
    oldX = x;
    display();///每次做動作,就重畫畫面
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week 04 rotate");

    glutMotionFunc(motion);///加motion函示
    glutMouseFunc(mouse);
    glutDisplayFunc(display);
    glutMainLoop();
}

沒有留言:

張貼留言