2021年3月22日 星期一

宋鮭魚之夢 week05

 

     week05
開啟檔案Transformation
下方案右鍵,swap交換兩行觀察自轉公轉



程式碼:
#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 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();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week05 drawing");

    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}
程式碼:
#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);
    glColor3f(1,1,0);
    glBegin(GL_TRIANGLE_FAN);
    glVertex2f(0,0);
    for(int i=0;i<N;i++){
        glVertex2f(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();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week05 drawing");

    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}
期中考模擬練習
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,ny,nz);//打光的法向量
9.  glVertex2f(x,y);//頂點
10. glEnd();//結束畫
11. glPopMatrix();//還原矩陣
程式碼上傳Github






















沒有留言:

張貼留言

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

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