2016年5月16日 星期一

[閒聊] VR色情發展起來還會想打砲嗎

Step 1
#include <GL/glut.h>
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();
}
Step 2
念咒語
Step 3 
設定 Build option
按編譯就可以得到個茶壺版的人行蜈蚣

課堂作業2
Step1
#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();
}
在作業一新增上述紅色那些程式碼
就可以用滑鼠讓他公轉
課堂作業3
#include <GL/glut.h>
float rot1=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glutSolidTeapot(0.2);
        glTranslatef(0.33,0.05,0);//把
        glRotatef(rot1,0,0,1);
        glTranslatef(0.25,0,0);
        glutSolidTeapot(0.2);

         glTranslatef(0.33,0.05,0);
        glRotatef(rot1,0,0,1);
        glTranslatef(0.25,0,0);
        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();
}
茶壺就可以向關節一樣旋轉

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

         glPushMatrix();
            glTranslatef(0.15,0.1,0);//設定旋轉軸
            glRotatef(rot1,0,0,1);
            glTranslatef(0.05,0,0);//設定方塊中心
            glutWireCube(0.1);

            glTranslatef(0.05,0,0);//設定旋轉軸
            glRotatef(rot1,0,0,1);
            glTranslatef(0.05,0,0);//設定方塊中心
            glutWireCube(0.1);

            glTranslatef(0.05,0,0);//設定旋轉軸
            glRotatef(rot1,0,0,1);
            glTranslatef(0.05,0,0);//設定方塊中心
            glutWireCube(0.1);
         glPopMatrix();

         glPushMatrix();

         glTranslatef(-0.15,0.1,0);//設定旋轉軸
            glRotatef(-rot1,0,0,1);
            glTranslatef(-0.05,0,0);//設定方塊中心
            glutWireCube(0.1);

            glTranslatef(-0.05,0,0);//設定旋轉軸
            glRotatef(-rot1,0,0,1);
            glTranslatef(-0.05,0,0);//設定方塊中心
            glutWireCube(0.1);

            glTranslatef(-0.05,0,0);//設定旋轉軸
            glRotatef(-rot1,0,0,1);
            glTranslatef(-0.05,0,0);//設定方塊中心
            glutWireCube(0.1);
    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();
}

你的機器人就可以跳LOCKING











沒有留言:

張貼留言