2020年4月22日 星期三

時間


midterm today.



the first project we do is make a red cube by our scripts.



#include<GL/glut.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glPushMatrix();
        glColor3f(1,0,0);
        glScalef(0.5,0.2,0.2);
        glutSolidCube(1);
    glPopMatrix();

    glutSwapBuffers();
}

int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week09");

    glutDisplayFunc(display);
    glutMainLoop();
}


two cubes.

#include<GL/glut.h>

void myCube()
{
    glPushMatrix();
        glScalef(0.5,0.2,0.2);
        glutSolidCube(1);
    glPopMatrix();
}

void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glPushMatrix();
        glColor3f(1,0,0);
        myCube();

        glTranslatef(0.4,0,0);
        glColor3f(1,1,1);
        myCube();
    glPopMatrix();

    glutSwapBuffers();
}

int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week09");

    glutDisplayFunc(display);
    glutMainLoop();
}


rotate:


#include<GL/glut.h>

void myCube()
{
    glPushMatrix();
        glScalef(0.5,0.2,0.2);
        glutSolidCube(1);
    glPopMatrix();
}

float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glPushMatrix();
        glRotatef(angle,0,0,1);
        glColor3f(1,0,0);
        myCube();

        glTranslatef(0.4,0,0);
        glColor3f(1,1,1);
        myCube();
    glPopMatrix();
    angle++;
    glutSwapBuffers();
}

int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week09");
    glutIdleFunc(display);
    glutDisplayFunc(display);
    glutMainLoop();
}





glPushMatrix();
        glRotatef(angle,0,0,1);
        glTranslatef(0.22,0,0);//以畫面中央當作旋轉軸心
        glColor3f(1,0,0);
        myCube();



(覺得很像時鐘)

  glPushMatrix();
        glColor3f(1,1,1);
        glutSolidCube(0.6);
        glRotatef(angle,0,0,1);
        glTranslatef(0.22,0,0);
        glColor3f(1,0,0);
        myCube();


沒有留言:

張貼留言