2015年5月28日 星期四

02160270_周冠羽_week14

(記者周冠羽銘傳大學播報)
電腦圖學第14週
(1)期末作品
(2)會跳舞的機器人
(3)T-R-T對關節轉
(4)小考:T-R-T觀念
(5)作業問題

TODO:試windows.7Zip中的Transformation.exe的

先旋轉再移動
v.s
先移動在旋轉


首先  我們先測試第一版本的
出現淡淡的茶壺立體影子

葉教授表示:因為打光方向相反了 所以要調整

經過數值調整正負即可秀出茶壺


再測試這個範例

#include<GL/glut.h>

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();
        glTranslatef(0.5,0,0); ///版本2 移動
        glutSolidTeapot(0.3);
    glPopMatrix();
    glFlush();
}

int main(int argc , char **argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("TRT_3D_冠羽");
    glutDisplayFunc(display);

    glutMainLoop();
}


#include<GL/glut.h>
float angle = 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); ///版本3 自轉
        glTranslatef(0.5,0,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glFlush();
}
void timer (int t)
{
    glutTimerFunc(20,timer,0);
    angle++;
    glutPostRedisplay();
}

int main(int argc , char **argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("TRT_3D_冠羽");
    glutDisplayFunc(display);
    glutTimerFunc(20,timer,0);
    glutMainLoop();
}


版本4. 滑鼠按住拖移調整旋轉速度
#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);
        glTranslatef(0.5,0,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glFlush();
}
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 ;
}
void timer (int t)
{
    glutTimerFunc(20,timer,0);
    angle++;
    glutPostRedisplay();
}

int main(int argc , char **argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("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 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();
        glTranslatef(0.41,0.1,0);///把樓下整個轉的...往右掛某個地方
        glRotatef(angle,0,0,1);
        glTranslatef(0.5,0,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSolidTeapot(0.3);
    glFlush();
}
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 ;
}
void timer (int t)
{
    glutTimerFunc(20,timer,0);
    ///angle++;
    glutPostRedisplay();
}

int main(int argc , char **argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("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();
        glTranslatef(0.15,0,0);///version 4:把樓下的整個在轉....往右掛在某個地方
        glRotatef(angle,0,0,1);///version 3:rotating teapot on the handle
        glTranslatef(0.25,0,0);///version 2:teapot on the right
        drawArm(); ///right lower-Arm
        glPushMatrix();
            glTranslatef(0.25,0,0);
            glRotatef(angle,0,0,1);
            glTranslatef(0.25,0,0);
            drawArm();
        glPopMatrix();
    glPopMatrix();
    ///------------------------------------------------------------------------
    glPushMatrix(); ///left lower-Arm
        glTranslatef(-0.15,0,0);///version 4:把樓下的整個在轉....往右掛在某個地方
        glRotatef(-angle,0,0,1);///version 3:rotating teapot on the handle
        glTranslatef(-0.25,0,0);///version 2:teapot on the right
        drawArm(); ///right lower-Arm
        glPushMatrix();
            glTranslatef(-0.25,0,0);
            glRotatef(-angle,0,0,1);
            glTranslatef(-0.25,0,0);
            drawArm();
        glPopMatrix();
    glPopMatrix();
    ///------------------------------------------------------------------------
    drawBody();
    
    glFlush();
}
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 ;
}
void timer (int t)
{
    glutTimerFunc(20,timer,0);
    ///angle++;
    glutPostRedisplay();
}

int main(int argc , char **argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("TRT_3D_冠羽");
    glutDisplayFunc(display);
    glutTimerFunc(20,timer,0);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}


沒有留言:

張貼留言