2022年3月15日 星期二

(OwO)電腦圖學week04_3/15

 1.去老師的網址: https://jsyeh.org/3dcg10/ 


windows.zip ~> 解壓縮至windows裡 \ transformation.exe

data.zip ~> 解壓縮到windows裡 \ data \ 模型


示範:旋轉軸不同轉動方向也不同(可用安培右手定則找出





點擊滑鼠旋轉茶壺

#include <GL/glut.h>///簡化程式

void display()

{


    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );///畫圖前先清理畫面

    glPopMatrix();///備份矩陣

    glRotatef(90, 0,0,1);

    glutSolidTeapot(0.3);


    glPopMatrix();///還原矩陣
    glutSwapBuffers();///畫好後換出來



}



int main (int argc, char** argv)

{


    glutInit( &argc, argv);///送給glutInit 初始化

    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 );///畫圖前先清理畫面

    glPopMatrix();///備份矩陣

        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);///送給glutInit 初始化

    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );

    glutCreateWindow("第4周程式!");


    glutDisplayFunc(display);
    glutMotionFunc(motion);///mouse motion動

    glutMainLoop();


}


常按壓滑鼠旋轉(可從上個點繼續轉動)

#include <GL/glut.h>///簡化程式
float angle=0,oldX=0;
void display()
{

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );///畫圖前先清理畫面

    glPopMatrix();///備份矩陣

        glRotatef(angle, 0,0,1);
        glutSolidTeapot(0.3);

    glPopMatrix();///還原矩陣
    glutSwapBuffers();///畫好後換出來

}
void motion(int x,int y)
{
    angle += (x-oldX);
    oldX = x;
    display();///重畫畫面
}
void mouse(int button,int state ,int x,int y)
{
    oldX = x;///定點
}

int main (int argc, char** argv)

{

    glutInit( &argc, argv);///送給glutInit 初始化

    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );

    glutCreateWindow("第4周程式!");



    glutDisplayFunc(display);
    glutMotionFunc(motion);///mouse motion動
    glutMouseFunc(mouse);


    glutMainLoop();


}


沒有留言:

張貼留言

VERY BEAUTIFUL, VERY POWERFUL

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