2015年5月28日 星期四

02160820 林政華 week14

從先前提到的windows資料夾中 打開Transformation

照著圖中,右鍵點選AI Capone
變成


調整位置並點選下右鍵,swap
他可以修改中心點位置


用openGL
產生茶壺 打光
向右移動

自動旋轉

加入滑鼠,手動旋轉

程式碼變成
#include<GL/glut.h>
float angle=0,oldX=0,oldY=0;
void display()
{
    {
    GLfloat pos[]={0,0,-1,0};
    glLightfv(GL_LIGHT0,GL_POSITION,pos);
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHTING);
    }
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(angle,0,0,1);///version3 :rotating on handle
        glTranslatef(0.5,0,0);///version2 :ON THE RIGHT
        glutSolidTeapot(0.3);
    glPopMatrix();
    glFlush();

}
void timer(int t)
{
    glutTimerFunc(20, timer,0);
    //angle++;
    glutPostRedisplay();
}
void mouse(int button,int state,int x,int y)
{
    if(state==GLUT_DOWN) {oldX=x; oldY=y;}
}
void motion(int x,int y)
{
    angle+=(x -oldX);
    oldX=x;
}

int main (int argc,char **argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("02160820 TRT 3D");
    glutDisplayFunc(display);
    glutTimerFunc(20,timer,0);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);

    glutMainLoop();

}







#include<GL/glut.h>
float angle=0,oldX=0,oldY=0;
void drawArm()
{
    glPushMatrix();
    glScalef(0.5,0.25,0.25);
    glutSolidCube(1);
    glPopMatrix();
}
void drawBody()
{
  glPushMatrix();
  glTranslatef(0,-0.5,0); 
  glRotatef(-90,1,0,0);
  glutSolidCone(0.3,0.8,30,30); 
  glPopMatrix();
}

void display()
{
    {
    GLfloat pos[]={0,0,-1,0};
    glLightfv(GL_LIGHT0,GL_POSITION,pos);
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHTING);
    }
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
      
        glRotatef(angle,0,0,1);///version3 :rotating on handle
        glTranslatef(0.5,0,0);///version2 :ON THE RIGHT
        glutSolidTeapot(0.3);
    glPopMatrix();
    glFlush();

}
void timer(int t)
{
    glutTimerFunc(20, timer,0);
    //angle++;
    glutPostRedisplay();
}
void mouse(int button,int state,int x,int y)
{
    if(state==GLUT_DOWN) {oldX=x; oldY=y;}
}
void motion(int x,int y)
{
    angle+=(x -oldX);
    oldX=x;
}

int main (int argc,char **argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("02160820 TRT 3D");
    glutDisplayFunc(display);
    glutTimerFunc(20,timer,0);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);

    glutMainLoop();

}



沒有留言:

張貼留言