2021年3月24日 星期三

week05電腦圖學

 1.點擊Swaps tanslate/rotate (旋轉跟移動兩行交換)



2.上下兩行程式碼交換有不同的運作方式



glTranslate在上   glRotate在下
(先旋轉再移動)




glTranslate在下   glRotate在上
(先移動再旋轉)

3.讓畫出來的圖加上按按鍵就可以轉動


程式碼:
#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_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("08160563 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...