2021年3月24日 星期三

chjyuʕ •ᴥ•ʔ week05 旋轉移動

 1.Transfromation(swap 交換)


順序很重要!
(1)移動Rotate時,人在原地選轉
(2)當swap,Rotate&Translate
移動Rotate時,左手為定點會隨著y軸旋轉

理解兩者有何不同:


-原地選轉
由下往上理解程式
(藍色車子-胖胖的-原地旋轉的-搬到右邊的)


-辦桌轉動圓桌(swap)
(藍色車子-胖胖的-搬到右邊的-圓桌轉動)

*其中.小考.swap範例網址(120.125.80.50/GL)


2.選轉圖片 (GitHub開啟04周的程式碼)

程式碼:
#include <GL/glut.h>
int N=0, vx[3000], vy[3000];
float angle=0;
void display()
{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix(); ///備份矩陣
        glRotatef(angle, 0, 0, 1); ///旋轉角度
        glBegin(GL_LINE_LOOP);
        for(int i=0; i<N; i++){
            glVertex2f((vx[i]-150)/150.0, -(vy[i]-150)/150.0);
    }
    glEnd();
    glPopMatrix(); ///還原矩陣
    glutSwapBuffers();

}
void keyboard( unsigned char key, int x, int y)
{
    angle++; ///角度增加
    display();
}
void motion(int x,int y)
{
    vx[N]=x; vy[N]=y;
    N++;
    display();
}

int main(int argc, char *argv[])

{

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("08160910 GOOD!");
    glutDisplayFunc(display);
    glutKeyboardFunc( keyboard ); ///按空白建,就會轉動
    glutMotionFunc(motion);
    glutMainLoop();

}
        :新增程式碼
























沒有留言:

張貼留言

距地表面160 Week11

 #include "glm.h" GLMmodel* pmodel = NULL; void drawmodel(void) {     if (!pmodel) { pmodel = glmReadOBJ("data/porsche.obj...