2022年3月15日 星期二

豪哥圖學筆記week04

 1.https://jsyeh.org/3dcg10/ 

下載win32,data

解壓縮windows.zip,data.zip

2.測試rotate方向,用安培右手定則可知道旋轉方向。





#include <GL/glut.h>

void display()

{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();

        glRotatef(90,0,0,1);

        glutSolidTeapot(0.3);

    glPopMatrix();

    glutSwapBuffers();

}

int main(int argc,char**argv)

{

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("Week04 Rotate");


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

}


第三個程式碼

#include <GL/glut.h>

float angle=0 , oldX=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-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);

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("Week04 Rotate");


    glutDisplayFunc(display);

    glutMotionFunc(motion);

    glutMouseFunc(mouse);

    glutMainLoop();

}



沒有留言:

張貼留言

VERY BEAUTIFUL, VERY POWERFUL

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