2021年3月22日 星期一

上課Day

 開啟程式複習上週課程內容

使用切換功能 將Translate和Rotate交換
調整數值,發現從自轉變成繞中心旋轉
新程式碼做出簡易畫板

#include <GL/glut.h>
#include <stdio.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 botton,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();
}
int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("08160465 大宇 Week05 宣告陣列");

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

GL_LINE_LOOP改成GL_TRIANGLE_FAN
從線條變成多個三角形組成的扇面

#include <GL/glut.h>
#include <stdio.h>
float vx[2000],vy[2000];
int N=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glBegin(GL_TRIANGLE_FAN);
    glColor3ub(28,107,240);
    for(int i=0; i<N; i++){
        glVertex2f(vx[i],vy[i]);
    }
    glEnd();
    glutSwapBuffers();
}
void mouse(int botton,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();
}
int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("08160465 大宇 Week05 宣告陣列");

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

利用老師作的模擬考程式,練習GL必備程式碼
1.   glPushMatrix();備份的矩陣
2.   glTranslatef(x,y,z);移動
3.   glRotatef(angle,x,y,z);旋轉
4.   glScalef(x,y,z);大小
5.   glBegin(GL_POLYGON);畫開始
6.    glColor3f(r,g,b);顏色
7.    glTexCoord2f(tx,ty);貼圖座標
8.    glNormal3f(nx,nt,nz);打光
9.    glVertex3f(x,y,z);頂點
10. glEnd();畫結束
11. glPopMatrix();還原的的矩陣



==========



沒有留言:

張貼留言

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

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