2020年3月24日 星期二

week4 不同角度看世界



如伸縮 與轉角度

glTranslatef(h,i,j) h=往左往右  i=往上往下 j=近遠伸縮

glRotatef(a,b,c,d) 可轉不同角度   b,c,d 分別代表x,y,z軸 a則是負責移動;

glScalef(f,g,h) 分別是長寬高;






如何利用滑鼠轉角度




先叫出之前的圓球旋轉圖

先設
void motion(int x,int y)  //Mouse motion 現在移動到哪
{
    myAngel=x;   // 我的角度,就是x值
}

main裡
glutMotionFunc(motion);  加入mouse motion涵式,可捕捉mouse的動作



float myAngel=0;// 變數的宣告

static void display(void) 裡//

const double a = myAngel;// 把角度輸入 //t*90







#include <GL/glut.h>

float myAngel=0;  ////2.設立變數當角度
void motion(int x,int y)  ///3.motion是當滑鼠移動時會發生的程式碼
{
    myAngel =x;
}
void display()
{

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //6.清除殘影
        glRotatef(myAngel, 0,0,1);  //5.對z軸做旋轉
        glutSolidTeapot(0.3);
        glutSwapBuffers();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week 04 rotate");

    glutMotionFunc(motion);  ///1.先加入motion涵式 上面才能加void motion

    glutDisplayFunc(display);
    glutMainLoop();
}



沒有留言:

張貼留言