2021年3月22日 星期一

阿米君の電腦圖學小筆記_Week05

 ☆複習上週內容☆

移動、旋轉、放大縮小


自轉 v.s 公轉
(了解swap translate/rotate用意)



先旋轉再移動解釋用意


 Mouse畫物體

程式碼:
#include <GL/glut.h>
#include <stdio.h>
float vx[2000],vy[2000];    //準備頂點
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++)
     {
          glVertex2d(vx[i],vy[i]);
     }
     glEnd( );
     glutSwapBuffers( );
}

void mouse(int button,int state,int x,int y)
{
}

void motion(int x,int y)
{
     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);
     glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
     glutCreateWindow("Week05 畫圖");

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


講解期中考試題


網頁:120.125.80.50/GL  or 120.125.80.50/gl

★加課內容★
使用gist.github.com網址複製內容

切換HTML把複製的內容貼在最後面

成果如下

沒有留言:

張貼留言

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

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