2022年3月15日 星期二

week04電腦圖學

 week04

旋轉 rotate,旋轉角度,旋轉軸,glRotatef(angle,x,y,z)

1.看範例:https://jsyeh.org/3dcg10/ >>>下載win32 , data >>>解壓縮>>transformation




使用右手定則


2.glRotatef(旋轉幅度,X軸,Y軸,Z軸)











開新專案
命名week04_mouse_motion


#include <GL/glut.h>
        void display()
        {
            glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            glPushMatrix();
                glRotatef(90,0,0,1); ///以z軸為主做90度的旋轉
                glutSolidTeapot(0.3);
            glPushMatrix();
            glutSwapBuffers();
        }
        int main(int argc, char** argv)
        {
            glutInit( &argc, argv );
            glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
            glutCreateWindow("第4週的程式");
            glutDisplayFunc(display);
            glutMainLoop();
        }



#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();

}

void motion (int x, int y)

{

    angle=x;

    display();///重畫畫面

}

int main (int argc,char**argv)

{

    glutInit( &argc,argv);

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("week04 Rotate");

    glutDisplayFunc(display);

    glutMotionFunc(motion); ///滑鼠動

    glutMainLoop();

}


沒有留言:

張貼留言

VERY BEAUTIFUL, VERY POWERFUL

一.     一樣先安裝且設定好freeglut,OpecCV, 開啟CodeBlocks建立新專案 week11_gundam,                 把 MyGundam.zip下載解壓縮後的data資料夾放到freeglut/bin裡面 把week09_openc...