顯示具有 Week14 標籤的文章。 顯示所有文章
顯示具有 Week14 標籤的文章。 顯示所有文章

2015年5月28日 星期四

02160111_鄭庭峰_week14

(1)期末作品
(2)會跳舞的機器人
(3)T-R-T 對關節轉
(4)小考 : T-R-T 觀念
(5)作業問題
(6) AlwaysOnTopMaker  一個能讓視窗往上得程式


ver1: 打光茶壺


ver2 : 茶壺往右移

ver3 : 茶壺整盤自動旋轉

#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); ///ver 3 :ratating teapot on the handle
        glTranslatef(0.5, 0, 0); ///ver 2 :teapot on the right
        glutSolidTeapot(0.3); ///ver 1 : A teapot
    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("TRT 3D");
    glutDisplayFunc(display);
    glutTimerFunc(20, timer, 0);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}


(4)ver4: 旋轉軸心掛到想放的位置

glPushMatrix();
        glTranslatef(0.45, 0.14, 0); ///ver 4 : 把樓下的整個在轉的   往右掛在某個地方 (最終終點)
        glRotatef(angle, 0, 0, 1); ///ver 3 :ratating teapot on the handle (旋轉)
        glTranslatef(0.45, -0.1, 0); ///ver 2 :teapot on the right (從起始點移動到中點)
        glutSolidTeapot(0.3); ///ver 1 : A teapot  畫東西
glPopMatrix();


做出一個貌似運動的人





WEEK14智智

電腦圖學week14
(1)展示期末作品
(2)會跳舞的機器人
(3)T-R-T對關節軸
(4)小考:T-R-T觀念



#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);
    glutSolidTeapot(0.3);
    glFlush();
}
int main(int argc,char **argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("TRT 3D");
    glutDisplayFunc(display);

    glutMainLoop();
}
#include <GL/glut.h>
float angle=0;
float 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 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("TRT 3D");
    glutDisplayFunc(display);
    glutTimerFunc(20,timer,0);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}


#include <GL/glut.h>
float angle=0;
float 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.43,0.13,0);///version 4:把樓下的整個在轉....往右掛在某個地方
        glRotatef(angle,0,0,1);///version 3:rotating teapot on the handle
        glTranslatef(0.45,-0.1,0);///version 2:teapot on the right
        glutSolidTeapot(0.3);///version 1:create a teapot
    glPopMatrix();
    glutSolidTeapot(0.3);
    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("TRT 3D");
    glutDisplayFunc(display);
    glutTimerFunc(20,timer,0);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}

02160350_喻挽晴 week14


#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 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("TRT 3D");
    glutDisplayFunc(display);
    glutTimerFunc(20,timer,0);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();



}


#include <GL/glut.h>
float angle=0,oldX,oldY;;
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.45,0.14,0);
        glRotatef(angle,0,0,1);
        glTranslatef(0.45,-0.1,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSolidTeapot(0.3);
    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("TRT 3D");
    glutDisplayFunc(display);
    glutTimerFunc(20,timer,0);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();



}


#include <GL/glut.h>
float angle=0,oldX,oldY;
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);
    glRotatef(angle,0,0,1);
    glTranslatef(0.25,0,0);
    drawArm();
    glPushMatrix();


    glTranslatef(0.25,0,0);
    glRotatef(angle,0,0,1);
    glTranslatef(0.25,0,0);
    drawArm();
    glPopMatrix();
    glPopMatrix();

        glPushMatrix();
    glTranslatef(-0.15,0,0);
        glRotatef(angle,0,0,1);
        glTranslatef(-0.25,0,0);
        drawArm();


        glPushMatrix();
    glTranslatef(-0.25,0,0);
        glRotatef(angle,0,0,1);
        glTranslatef(-0.25,0,0);
        drawArm();
    glPopMatrix();
    glPopMatrix();
drawBody();

    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("TRT 3D");
    glutDisplayFunc(display);
    glutTimerFunc(20,timer,0);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();



}






02160074_張凱晴 week14

本週重點:T-R-T對關節轉


人物往右下移動,中心是人物本身,因此旋轉時是自轉


中心在視窗正中間,人物像公轉一樣,繞著中心轉

先畫一個茶壺並打光
 茶壺以視窗中間點為中心公轉


T:右邊茶壺掛到中間茶壺(旋轉中心)
R:旋轉
T:右邊的茶壺依照中心點旋轉
Teap():右邊的茶壺
Teap():中間的茶壺

程式碼:
#include <GL/glut.h>
float angle=0, oldX=0, oldY=0;
void drawArm()
{
    glPushMatrix();
        glScalef(0.5, 0.15, 0.15);
        glutSolidCube(1);
    glPopMatrix();
}
void drawBody()
{
    glPushMatrix();
        glTranslatef(0, -0.5, 0);///將身體往下移0.5
        glRotatef(-90, 1, 0, 0);
        glutSolidCone(0.3, 0.8, 30, 30);
    glPopMatrix();
}
void display()
{
    {///打光的程式6行
    GLfloat pos[]= {0.0, 0.0, -1.0, 0.0};
    glLightfv(GL_LIGHT0, GL_POSITION, pos);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    }
    glPushMatrix();
        glTranslatef(0.15, 0, 0);
        glRotatef(angle, 0, 0, 1);
        glTranslatef(0.25, 0, 0);
        drawArm();///右手1
        glPushMatrix();
            glTranslatef(0.25, 0, 0);
            glRotatef(angle, 0, 0, 1);
            glTranslatef(0.25, 0, 0);
            drawArm();///右手2
        glPopMatrix();
    glPopMatrix();

    glPushMatrix();
        glTranslatef(-0.15, 0, 0);
        glRotatef(-angle, 0, 0, 1);
        glTranslatef(-0.25, 0, 0);
        drawArm();///左手1
        glPushMatrix();
            glTranslatef(-0.25, 0, 0);
            glRotatef(-angle, 0, 0, 1);
            glTranslatef(-0.25, 0, 0);
            drawArm();///左手2
        glPopMatrix();
    glPopMatrix();
    drawBody();
    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("TRT 3D");
    glutDisplayFunc(display);

    glutTimerFunc(20, timer, 0);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}

week14_T-R-T關節移動_呂登祐

1)期末作品
2)會跳舞的機器人
3)T-R-T觀念
*****************************************************
1.茶壺旋轉並移動旋轉軸

#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); ///v3: rotating teapot on the handle
    glTranslatef(0.5,0,0);  ///v2: teapot on the right
    glutSolidTeapot(0.3);  ///v1: a teapot
    glPopMatrix();
    glFlush();
}
void timer(int t)
{
    glutTimerFunc(20, timer, 0);
    angle++;
    glutPostRedisplay();
}
int main(int argc,char **argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("3D_0031");
    glutDisplayFunc(display);
    glutTimerFunc(20,timer,0);
    glutMainLoop();
}

2.滑鼠拖曳旋轉位


#include <GL/glut.h>
float angle, oldX, 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);///v3: rotating teapot on the handle
    glTranslatef(0.5,0,0);///v2: teapot on the right
    glutSolidTeapot(0.3);///v1: a teapot
    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("3D_0031");
    glutDisplayFunc(display);
    glutTimerFunc(20,timer,0);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}

3.掛軸心

#include <GL/glut.h>
float angle, oldX, 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.45, 0.14, 0);///v4: 掛上去
    glRotatef(angle,0,0,1);///v3: rotating teapot on the handle
    glTranslatef(0.45, -0.1, 0);///v2: teapot on the right
    glutSolidTeapot(0.3);///v1: a teapot
    glPopMatrix();
    glutSolidTeapot(0.3);
    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("3D_0031");
    glutDisplayFunc(display);
    glutTimerFunc(20,timer,0);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}

簡單來說T-R-T,第一個T就是移動整個物體,第二個R就是轉動角度。第三個T就是移動軸心


4.滑鼠控制手臂

#include <GL/glut.h>

float angle, oldX, 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);///v4: 掛上去
        glRotatef(angle,0,0,1);///v3: rotating teapot on the handle
        glTranslatef(0.25, 0, 0);///v2: teapot on the right
        drawArm();/// right upper-arm
      glPushMatrix();
        glTranslatef(0.25, 0, 0);///v4: 掛上去
        glRotatef(angle,0,0,1);///v3: rotating teapot on the handle
        glTranslatef(0.25, 0, 0);///v2: teapot on the right
        drawArm();/// right lower-arm
        glPopMatrix();
    glPopMatrix();

    glPushMatrix();
        glTranslatef(-0.15, 0, 0);///v4: 掛上去
        glRotatef(-angle,0,0,1);///v3: rotating teapot on the handle
        glTranslatef(-0.25, 0, 0);///v2: teapot on the right
        drawArm();/// left upper-arm
      glPushMatrix();
        glTranslatef(-0.25, 0, 0);///v4: 掛上去
        glRotatef(-angle,0,0,1);///v3: rotating teapot on the handle
        glTranslatef(-0.25, 0, 0);///v2: teapot on the right
        drawArm();/// left lower-arm
       glPopMatrix();
    glPopMatrix();

    drawBody();
    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("3D_0031");
    glutDisplayFunc(display);
    glutTimerFunc(20,timer,0);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}