2021年5月26日 星期三

week14

課程一開始老師講解了上禮拜gundam的程式碼內容都有刮弧標註起來 

先開codeblocks的glut檔案,把原先的程式碼備份在notepad++

提醒了大家有 行程式碼很重要

後開始在codeblocks打程式碼,是在做出一個圓,而他改變視窗名稱成week14 timer


glutSolidSphere(0.3,30,30);//Solid實心(Wire線框,0.3是半徑。

途中的小框框有一段文字,是在說上方display的指標函示


void Timer(int t)
{
    glClearColor(1,0,0,0);///清背景色:紅色
    display();///重畫畫面
}我們打了一個Timer函式

在最下方打一個程式 

glutDisplayFunc(display);

    glutTimerFunc(3000,timer,0);叫了Timer的函式,3000等多久,這邊的timer就是上面的timer後面的0就是上面的(int"t")

    glutMainLoop();


#include<GL/glut.h>

float angle=0;

void display()///display()函式,其實display是函式指標。

{

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glPushMatrix();

        glRotatef(angle,0,0,1);

        glutSolidCube(0.3);///改變圖形

    glPopMatrix();

    glutSwapBuffers();

}

void timer(int t)

{

    glutTimerFunc(30,timer,t+1);

    glClearColor(1,0,0,0);///清背景色:紅色

    angle++;

    display();///重畫畫面

}

int main(int argc,char**argv)

{

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);

    glutCreateWindow("week14 timer");


    glutDisplayFunc(display);

    glutTimerFunc(3000,timer,0);

    glutMainLoop();

}

背景從黑色變成紅色,圖中的方塊開始慢慢旋轉

黃底的部分是新增加的內容


int diff=2;
void timer(int t)
{
    glutTimerFunc(20,timer,t+1);
    glClearColor(1,0,0,0);///清背景色:紅色
    if(angle>90)diff-=2;
    if(angle<0) diff=+2;
    angle+=diff;
    display();///重畫畫面
}
在timer函式的部分多加一些或修改程式碼,方塊會來回轉動


#include<GL/glut.h>
float angle=0;
void drawArm1(){
    glPushMatrix();
        glScalef(1,0.5,0.5);把手臂變細長
        glColor3f(0,1,0);glutSolidCube(0.2);
    glPopMatrix();
}做出手臂的程式碼
void display()///display()函式,其實display是函式指標。
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glColor3f(1,1,1);glutSolidCube(0.3);白色的身體
        glPushMatrix();
            glTranslatef(-0.2,0.2,0);掛上肩膀
            glRotatef(angle,0,0,1);轉動
            glTranslatef(-0.1,0,0);把旋轉中心(關節)移動到畫面最中心
            drawArm1();
        glPopMatrix();劃出手臂
    glPopMatrix();
    glutSwapBuffers();
}
int diff=2;
void timer(int t)
{
    glutTimerFunc(20,timer,t+1);
    ///glClearColor(1,0,0,0);///清背景色:紅色
    if(angle>90)diff-=2;
    if(angle<0) diff=+2;
    angle+=diff;
    display();///重畫畫面
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week14 timer");

    glutDisplayFunc(display);
    glutTimerFunc(3000,timer,0);
    glutMainLoop();
}



沒有留言:

張貼留言

距地表面160 Week11

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