2021年3月22日 星期一

是我是我詐騙 Week05

 

先旋轉再移動 vs. 先移動再旋轉


1.開啟Transformation


2.試試看不同的操作


這個是公轉(轉的中心軸是中間點)

glRotatef(32,0,1,0);
glTranslatef(0.5,0,0);

由下往上看
先是車子(glBegin)
大小(glScalef)
位置(glTranslatef)
旋轉(glRotatef)

🎠這樣才是以中心點旋轉🎠



用swap切換


這個是自轉(轉的中心軸是自己)


glTranslatef(0.62,0,0);
glRotatef(208,0,1,0,);

一樣下往上看
先是車子(glBegin)
大小(glScalef)
旋轉(glRotatef)
位置(glTranslatef)

🎠這樣就變成自己是中心點轉🎠



3.用線作畫



程式碼如下:


#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++)
    {
        glVertex2f(vx[i],vy[i]);
    }
    glEnd();
    glutSwapBuffers();
}
void mouse(int buttin,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("08160554");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);      ///按下去彈起來
    glutMotionFunc(motion);    ///mouse motion 在動
    glutMainLoop();
}


4.改變顏色!!!


程式碼如下:


#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(0,0,30);   ///換顏色
    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)
{
    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("08160554");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}


5.用github把程式丟上來




沒有留言:

張貼留言

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

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