2021年3月22日 星期一

腳麻掉 Week05

 

電腦圖學 Week05

先複習上周講到的Transformation



1. 用左耳接住左手臂來看程式碼

   分別依序就是 車子=>胖胖的=>移到右邊=> 在餐桌中心轉動


2. 如果把一跟二交換,就會是自轉跟公轉的差別

   分別依序就是 車子=>胖胖的=>自轉中的=> 整個移動




開始做能用滑鼠來畫畫的程式

1. 紅色是新的程式碼



#include <GL/glut.h>                               ///使用GLUT外掛
#include <stdio.h>
float vx[2000], vy[2000];    ///準備一堆頂點,等一下要畫!! 介於 -1 ~ +1
int N=0;                               ///有N個頂點
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);      ///清空
    glBegin(GL_LINE_LOOP);
    for(int i=0;i<N;i++){
        glVertex2f( vx[i],vy[i]);
    }
    glEnd();
    glutSwapBuffers();             ///交換兩倍的buffers
}
void mouse(int buttin,int state,int x,int y)
{

}
void motion(int x,int y)           ///mouse motion 的函式
{
    printf("%d %d\n",x,y);    ///把頂點記起來,等一下要畫
    vx[N]=(x-150)/150.0;          ///很像這樣的寫法,記錄起來
    vy[N]=-(y-150)/150.0;
    N++;
    display();                              ///可以讓畫面很流暢
}                                                ///減一半,再除一半,y加負號
int main(int argc,char ** argv)
{
    glutInit( &argc,argv);                                                                     ///GLUT初始設定
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);       ///顯示模式
    glutCreateWindow("08161106 腳麻掉");                                    ///開視窗

    glutDisplayFunc(display);            ///等一下要顯示的函式
    glutMouseFunc( mouse );             ///滑鼠按下去,彈起來
    glutMotionFunc( motion );           ///準備mouse motion移動時(拖曳)
    glutMainLoop();                            ///主要迴圈
}

考試用的程式碼

1. 120.125.80.50/GL




沒有留言:

張貼留言

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

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