2021年3月15日 星期一

我不想出錢 Week04

我不想出錢 Week04

[start]

複習的部分













又是你,茶壺





















程式碼:

#include <GL/glut.h>
#include <stdio.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glutSolidTeapot(0.3);
    glutSwapBuffers();
}
void mouse( int button, int state, int x, int y)
{
    printf("button:%d state:%d x:%d y:%d\n",button, state, x,y);
}
int main(int argc, char ** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week04 mouse");

    glutDisplayFunc( display );
    glutMouseFunc( mouse );
    glutMainLoop();
}

按茶壺的邊緣,讓程式碼跑出來
程式碼:















複製上一個小黑框裡的程式,貼到原本的程式裡,再加幾行程式






















#include <GL/glut.h>
#include <stdio.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glutSolidTeapot(0.3);
    glutSwapBuffers();
}
void mouse( int button, int state, int x, int y)
{
    if( state==GLUT_DOWN)
    {
        printf(" glVertex3f( (%d-150)/150.0,-(%d-150)/150.0, 0);\n", x, y);
    }

}
int main(int argc, char ** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week04 mouse");

    glutDisplayFunc( display );
    glutMouseFunc( mouse );
    glutMainLoop();
}
























程式碼:

#include <GL/glut.h>
#include <stdio.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    //glutSolidTeapot(0.3);
    //glutSwapBuffers();
    glBegin(GL_POLYGON);
        glVertex3f( (140-150)/150.0,-(135-150)/150.0, 0);
        glVertex3f( (118-150)/150.0,-(118-150)/150.0, 0);
        glVertex3f( (143-150)/150.0,-(148-150)/150.0, 0);
        glVertex3f( (208-150)/150.0,-(110-150)/150.0, 0);
        glVertex3f( (207-150)/150.0,-(163-150)/150.0, 0);
        glVertex3f( (237-150)/150.0,-(156-150)/150.0, 0);
        glVertex3f( (206-150)/150.0,-(160-150)/150.0, 0);
        glVertex3f( (159-150)/150.0,-(173-150)/150.0, 0);
        glVertex3f( (124-150)/150.0,-(179-150)/150.0, 0);
        glVertex3f( (106-150)/150.0,-(153-150)/150.0, 0);
        glVertex3f( (93-150)/150.0,-(157-150)/150.0, 0);
        glVertex3f( (91-150)/150.0,-(138-150)/150.0, 0);
        glVertex3f( (111-150)/150.0,-(137-150)/150.0, 0);
        glVertex3f( (154-150)/150.0,-(153-150)/150.0, 0);
        glVertex3f( (148-150)/150.0,-(110-150)/150.0, 0);
        glVertex3f( (156-150)/150.0,-(123-150)/150.0, 0);
    glEnd();
    glutSwapBuffers();
}
void mouse( int button, int state, int x, int y)
{
    if( state==GLUT_DOWN)
    {
        printf(" glVertex3f( (%d-150)/150.0,-(%d-150)/150.0, 0);\n", x, y);
    }

}
int main(int argc, char ** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week04 mouse");

    glutDisplayFunc( display );
    glutMouseFunc( mouse );
    glutMainLoop();
}

茶壺可以跟箭頭一起動





















程式碼:

#include <GL/glut.h>
#include <stdio.h>
float teapotX=0, teapotY=0/// 茶壺的座標 -1.0.....+1.0
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
            glTranslatef(teapotX,teapotY, 0); ///照著座標,移動
            glutSolidTeapot(0.3);
    glPopMatrix(); ///矩陣還原
    glEnd();
    glutSwapBuffers();
}
void motion( int x, int y)
{
    teapotX = (x-150)/150.0; ///換算座標
    teapotY = -(y-150)/150.0;
    display();
}
int main(int argc, char ** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week04 mouse");

    glutDisplayFunc( display ); ///display顯示函式
    glutMotionFunc( motion ); ///準備mouse motion 移動時的函式
    //glutMouseFunc( mouse ); ///mouse滑鼠的函式
    glutMainLoop();
}

用老師給的檔案練習"旋轉"的概念
以X軸當基準,拿出"右手"去理解旋轉方向(藍線)






















以Y軸當基準,拿出"右手"去理解旋轉方向(藍線)


以Z軸當基準,拿出"右手"去理解旋轉方向(藍線)





















[加課時間]

GitHub做1個新網站






















把 main 改成 gh-pages





















成功開通自己的網站!(step:settings👉change theme 隨便選一個當背景👉select theme👉最下面更新👉打上自己名字去自己的網站)




沒有留言:

張貼留言

Week18期末作業(橘貓的跳舞熊熊)

 期末作業(橘貓的跳舞熊熊) 影片: https://youtu.be/R89tptMaQZw 程式碼: #include <opencv/highgui.h> #include <opencv/cv.h> #include <GL/glut.h...