2021年3月22日 星期一

week05-08160616

 解釋每行程式碼


 



紀錄滑鼠移動位置

#include <GL/glut.h>
float vx[2000], vy[2000];
int N=0;
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();
}
void mouse( int buttin , int state, int x, int y)
{
}
void motion( int x, int y )
{
    vx[N]=(x-150)/150.0;
    vy[N]=-(y-150)/ 150.0;
    N++;
    display();
}
int main(int argc, char ** argv)
{
    glutInit( &argc, argv );
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week05 drawing");

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



期中考複習\





利用https://gist.github.com/把程式碼變成網址,貼在blogger即可找到


======

沒有留言:

張貼留言

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

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