2016年5月16日 星期一

week13 和鋼鐵人一起拯救世界a柏廷

課堂作業1: 機器人

(1.) 新增貝殼專案


(2.) 語言選擇 C++


(3.) 路徑設定


(4.) 環境設定不用更改


(6.) 環境設定 (咒語設定)


(7.) 支援程式路徑設定


(8.) 支援程式路徑設定



(9.) 程式碼


(10.) 結果


#include <GL/glut.h>
float rot1=0;
void display()
{
    glPushMatrix();
        glutSolidTeapot(0.3);
        glTranslatef(0.5,0,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}
int main(int argc, char ** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Robot");
    glutDisplayFunc(display);
    glutMainLoop();

}


課堂作業二  兩個茶壺:用滑鼠旋轉

旋轉結果:


#include <GL/glut.h>
float rot1=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glutSolidTeapot(0.3);
        glRotatef(rot1,0,0,1);  ///公轉
        glTranslatef(0.5,0,0);
        glRotatef(rot1,0,0,1);  ///原地自轉
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}
void motion(int x ,int y)
{
    rot1=x;
    glutPostRedisplay();
}
int main(int argc, char ** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Robot");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();

}

課堂作業三 :手臂



#include <GL/glut.h>
float rot1=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glutSolidTeapot(0.3);
        glTranslatef(0.33,0.05,0);   ///Step 3: 掛在哪
        glRotatef(rot1,0,0,1);  ///公轉  //Step1:轉動
        glTranslatef(0.25,0,0);  ///Step2:轉的中心,放在中心
        glutSolidTeapot(0.2);

        glTranslatef(0.33,0.05,0); ///Step 3: 掛在哪
        glRotatef(rot1,0,0,1);  ///原地自轉 //Step1:轉動
        glTranslatef(0.25,0,0);  ///Step2:轉的中心,放在中心
        glutSolidTeapot(0.2);
    glPopMatrix();
    glutSwapBuffers();
}
void motion(int x ,int y)
{
    rot1=x;
    glutPostRedisplay();
}
int main(int argc, char ** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Robot");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();

}




作業四:  組裝機器人

//初始

#include <GL/glut.h>
float rot1=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glPushMatrix();
            glutWireCube(0.3);  ///body
            glPushMatrix();
                glTranslatef(0,0.2,0);
                glutWireCube(0.1); ///head
            glPopMatrix();

            glPushMatrix();
                glTranslatef(0.2,0.1,0);
                glutWireCube(0.1);   ///upper arm
                glTranslatef(0.1,0,0);
                glutWireCube(0.1);  ///lower arm
                glTranslatef(0.1,0,0);
                glutWireCube(0.1); ///right hand
            glPopMatrix();

            glPushMatrix();
                glTranslatef(-0.2,0.1,0);
                glutWireCube(0.1);   ///upper arm
                glTranslatef(-0.1,0,0);
                glutWireCube(0.1);  ///lower arm
                glTranslatef(-0.1,0,0);
                glutWireCube(0.1); ///right hand
            glPopMatrix();
          glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();
}
void motion(int x ,int y)
{
    rot1=x;
    glutPostRedisplay();
}
int main(int argc, char ** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Robot");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();

}


//修改


沒有留言:

張貼留言