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

2014年5月29日 星期四

01163052_高健智, HW11, Week11


#include <GL/glut.h>
float angleX=0,angle1=0,angle2;
void display()
{
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
    glRotatef(angleX, 0,1,0);
    
   // glutSolidTeapot(0.3); 
     glutWireTeapot(0.3);//網狀 
     
     
     
     //包起來 <右手>  
     
   glPushMatrix();
    glTranslatef(0.4,0,0);//球移出 
    glutSolidSphere(0.2,30,30);
    glPushMatrix();//手臂<右> 
        glRotatef(angle1,0,0,1);
        glTranslatef(0.3,0,0);//移出 
          glScalef(2,0.8,0.8);//方塊方向 
          glutSolidCube(0.2);
      glPopMatrix();
    
    glPopMatrix();
    
    
   //包起來 <左> 
   
    glPushMatrix();
       glTranslatef(-0.4,0,0);//球移出 
       glutSolidSphere(0.2,30,30);
        
        glPushMatrix();//手臂<左> 
        glRotatef(angle1,0,0,1);
        glTranslatef(-0.3,0,0);//移出 
          glScalef(2,0.8,0.8);//方塊方向 
          glutSolidCube(0.2);
      glPopMatrix();
    glPopMatrix();
  
  //頭 
    glPushMatrix();//包起來 <上> 
       glTranslatef(0,0.4,0);//球移出 
       glutSolidSphere(0.2,30,30);
     
    glPopMatrix();
    
    //腳左 
    glPushMatrix();//大腿 
       glTranslatef(-0.2,-0.2,0);//球移出 
       glRotatef(angle1,0,0,1);
       glTranslatef(0,-0.36/2,0);//移出 
      glPushMatrix();
          glScalef(0.2,0.36,0.2);//方塊方向 
          glutSolidCube(1);
      glPopMatrix(); 
       
      glPushMatrix();//小腿 
         glTranslatef(0,-0.18,0);//球移出 
         glRotatef(angle1,0,0,1);
         glTranslatef(0,-0.36/2,0);//移出 
         glScalef(0.2,0.36,0.2);//方塊方向 
         glutSolidCube(1);
       
      glPopMatrix();     
    glPopMatrix();
    
    
    //腳右 
    glPushMatrix();//大腿 
       glTranslatef(0.2,-0.2,0);//球移出 
       glRotatef(angle1,0,0,1);
       glTranslatef(0,-0.36/2,0);//移出 
      glPushMatrix();
          glScalef(0.2,0.36,0.2);//方塊方向 
          glutSolidCube(1);
      glPopMatrix(); 
       
      glPushMatrix();//小腿 
         glTranslatef(0,-0.18,0);//球移出 
         glRotatef(angle1,0,0,1);
         glTranslatef(0,-0.36/2,0);//移出 
         glScalef(0.2,0.36,0.2);//方塊方向 
         glutSolidCube(1);
       
      glPopMatrix();     
    glPopMatrix();
  
  
        glPopMatrix();
    glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{
     if(key=='a') angleX+=3;
     if(key=='b') angleX-=3;
     if(key=='1') angle1+=3;
     if(key=='2') angle2+=3;
     
     glutPostRedisplay();
        
}
void myLight()
{
     const GLfloat light_position[] = { 2.0f, 5.0f, -5.0f, 0.0f };
     glEnable(GL_LIGHT0);
     glEnable(GL_NORMALIZE);
     glEnable(GL_COLOR_MATERIAL);
     glEnable(GL_LIGHTING);  
     glLightfv(GL_LIGHT0, GL_POSITION, light_position); 
}
int main()
{
     glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
     glutCreateWindow("week11");
     glutDisplayFunc(display);
     glutKeyboardFunc(keyboard);
     myLight();
     glutMainLoop();
}




2014年5月8日 星期四

01160306_呂季樺_第十二周

今天的目標: 做出會動的木頭人偶

1. 今天先用一個 T-R-T 對特定軸轉動的小考, 來讓同學複習這個關鍵技術
1.1. 洩題: 用 LINE 饅頭人, 來進行考試
1.2. 最後答案:
glPushMatrix();
  glTranslatef( -0.5, 0.5, 0 ); //Step 3
  glRotatef( -30,  0, 0, 1);// Step 2 (有陷阱哦!)
  glTranslatef( -0.4, 0, 0);// Step 1
  drawHand();
glPopMatrix();

2. 我們開始用木頭人的圖, 進行示範
2.1. 上網找出一張木頭人, 開始裁出 n 張圖

3. 寫出程式的內容 (可以剪貼哦!)
3.1. 安裝 glut 及 opencv 的 DevPak 讓 Dev C++ 可以寫有貼圖的程式
3.2. 在 blog 裡面找一下程式來剪貼啦 (ex. tag: 000葉正聖老師, 然後找裡面的 texture 及上週的程式碼)
3.3. 請注意, 要把排版 TAB 設定好
3.4. link error 時, 要把 Alt-P (Project-Option設定) 裡面的 Link 設定好, 加入咒語 -lcv -lcxcore -lhighgui
(要小心要用空格與後面的格開哦!)
3.5. 執行時出現 dll 檔的錯誤時, 請把 c:\dev-cpp\bin\opencv\ 目錄裡面所有的 .dll 檔案, 都放到 c:\windows\system32 裡面

#include <GL/glut.h>
#include <opencv/highgui.h>
#include <opencv/cv.h>
IplImage *img1, *img2 ,*img3, *img4, *img5;
GLuint id1, id2, id3, id4, id5;
float angleX=0;

void myTexture()
{
img1=cvLoadImage("man.jpg");
img2=cvLoadImage("L-hand.jpg");
img3=cvLoadImage("R-hand.jpg");
img4=cvLoadImage("L-foot.jpg");
img5=cvLoadImage("R-foot.jpg");

cvCvtColor(img1, img1, CV_BGR2RGB);
cvCvtColor(img2, img2, CV_BGR2RGB);
cvCvtColor(img3, img3, CV_BGR2RGB);
cvCvtColor(img4, img4, CV_BGR2RGB);
cvCvtColor(img5, img5, CV_BGR2RGB);
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &id1);
glGenTextures(1, &id2);
glGenTextures(1, &id3);
glGenTextures(1, &id4);
glGenTextures(1, &id5);

glBindTexture(GL_TEXTURE_2D, id1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img1->width, img1->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img1->imageData);

glBindTexture(GL_TEXTURE_2D, id2);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img2->width, img2->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img2->imageData);

glBindTexture(GL_TEXTURE_2D, id3);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img3->width, img3->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img3->imageData);

glBindTexture(GL_TEXTURE_2D, id4);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img4->width, img4->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img4->imageData);

glBindTexture(GL_TEXTURE_2D, id5);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img5->width, img5->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img5->imageData);

}

2014年5月1日 星期四

01160235_謝采玲, HW11, Week11



01160563許翔皓,HW11,WEEK11


機器人手腳

   
    glutWireTeapot(0.3);//網狀
    glTranslatef(0.4,0,0);//球移出
    glutSolidSphere(0.2,30,30);

把程式碼包起來
glPushMatrix();//包起來 <右> 
  glTranslatef(-0.4,0.4,0);//球移出 
  glutSolidSphere(0.2,30,30);
glPopMatrix();



<右手>
glPushMatrix();//包起來 <右> 
    glTranslatef(0.4,0,0);//球移出 
    glutSolidSphere(0.2,30,30);
    
    glPushMatrix();//手臂<右> 
        glTranslatef(0.3,0,0);//移出 
          glScalef(2,0.8,0.8);//方塊方向 
          glutSolidCube(0.2);
      glPopMatrix();
    
    glPopMatrix();

<旋轉>
    glRotatef(angle1,0,0,1);


記得上面要宣告變數;
float angleX=0,angle1=0;
呼叫變數
if(key=='a') angleX+=3;
 if(key=='b') angleX-=3;
 if(key=='1') angle1+=3;

大腿小腿
//腳右 
    glPushMatrix();//大腿 
       glTranslatef(0.2,-0.2,0);//球移出 
       glRotatef(angle1,0,0,1);
       glTranslatef(0,-0.36/2,0);//移出 
      glPushMatrix();
          glScalef(0.2,0.36,0.2);//方塊方向 
          glutSolidCube(1);
      glPopMatrix(); 
       
      glPushMatrix();//小腿 
         glTranslatef(0,-0.18,0);//球移出 
         glRotatef(angle1,0,0,1);
         glTranslatef(0,-0.36/2,0);//移出 
         glScalef(0.2,0.36,0.2);//方塊方向 
         glutSolidCube(1);
       
      glPopMatrix();     
    glPopMatrix();
  


***本週程式碼***

#include <GL/glut.h>
float angleX=0,angle1=0,angle2;
void display()
{
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
    glRotatef(angleX, 0,1,0);
    
   // glutSolidTeapot(0.3); 
     glutWireTeapot(0.3);//網狀 
     
     
     
     //包起來 <右手>  
     
   glPushMatrix();
    glTranslatef(0.4,0,0);//球移出 
    glutSolidSphere(0.2,30,30);
    glPushMatrix();//手臂<右> 
        glRotatef(angle1,0,0,1);
        glTranslatef(0.3,0,0);//移出 
          glScalef(2,0.8,0.8);//方塊方向 
          glutSolidCube(0.2);
      glPopMatrix();
    
    glPopMatrix();
    
    
   //包起來 <左> 
   
    glPushMatrix();
       glTranslatef(-0.4,0,0);//球移出 
       glutSolidSphere(0.2,30,30);
        
        glPushMatrix();//手臂<左> 
        glRotatef(angle1,0,0,1);
        glTranslatef(-0.3,0,0);//移出 
          glScalef(2,0.8,0.8);//方塊方向 
          glutSolidCube(0.2);
      glPopMatrix();
    glPopMatrix();
  
  //頭 
    glPushMatrix();//包起來 <上> 
       glTranslatef(0,0.4,0);//球移出 
       glutSolidSphere(0.2,30,30);
     
    glPopMatrix();
    
    //腳左 
    glPushMatrix();//大腿 
       glTranslatef(-0.2,-0.2,0);//球移出 
       glRotatef(angle1,0,0,1);
       glTranslatef(0,-0.36/2,0);//移出 
      glPushMatrix();
          glScalef(0.2,0.36,0.2);//方塊方向 
          glutSolidCube(1);
      glPopMatrix(); 
       
      glPushMatrix();//小腿 
         glTranslatef(0,-0.18,0);//球移出 
         glRotatef(angle1,0,0,1);
         glTranslatef(0,-0.36/2,0);//移出 
         glScalef(0.2,0.36,0.2);//方塊方向 
         glutSolidCube(1);
       
      glPopMatrix();     
    glPopMatrix();
    
    
    //腳右 
    glPushMatrix();//大腿 
       glTranslatef(0.2,-0.2,0);//球移出 
       glRotatef(angle1,0,0,1);
       glTranslatef(0,-0.36/2,0);//移出 
      glPushMatrix();
          glScalef(0.2,0.36,0.2);//方塊方向 
          glutSolidCube(1);
      glPopMatrix(); 
       
      glPushMatrix();//小腿 
         glTranslatef(0,-0.18,0);//球移出 
         glRotatef(angle1,0,0,1);
         glTranslatef(0,-0.36/2,0);//移出 
         glScalef(0.2,0.36,0.2);//方塊方向 
         glutSolidCube(1);
       
      glPopMatrix();     
    glPopMatrix();
  
  
        glPopMatrix();
    glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{
     if(key=='a') angleX+=3;
     if(key=='b') angleX-=3;
     if(key=='1') angle1+=3;
     if(key=='2') angle2+=3;
     
     glutPostRedisplay();
        
}
void myLight()
{
     const GLfloat light_position[] = { 2.0f, 5.0f, -5.0f, 0.0f };
     glEnable(GL_LIGHT0);
     glEnable(GL_NORMALIZE);
     glEnable(GL_COLOR_MATERIAL);
     glEnable(GL_LIGHTING);  
     glLightfv(GL_LIGHT0, GL_POSITION, light_position); 
}
int main()
{
     glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
     glutCreateWindow("week11");
     glutDisplayFunc(display);
     glutKeyboardFunc(keyboard);
     myLight();
     glutMainLoop();
}





第十一週課堂作業

茶壺機器人
基礎型
#include <GL/glut.h>
float angleX=0;
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
 glRotatef(angleX, 0,1,0);
 glutSolidTeapot(0.3);   
glPopMatrix();
glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)//鍵盤
{
     if(key=='a') angleX+=3;
     if(key=='b') angleX-=3;
     glutPostRedisplay();
        
}
void myLight()//打光
{
const GLfloat light_position[] = { 2.0f, 5.0f, -5.0f, 0.0f };
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING); 
glLightfv(GL_LIGHT0, GL_POSITION, light_position); 
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
glutCreateWindow("week11");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
myLight();
glutMainLoop();
}
長出手臂的茶壺機器人
旋轉手臂關節
手腳關節轉動
關節轉動完整版



hw11


#include <Gl/glut.h>
float teapotX=0,teapotY=0,angle1=0,angle2=0;
void keyboard(unsigned char key, int x, int y)
{

    if(key=='a' || key=='A') teapotX+=3;
    if(key=='b' || key=='B') teapotX-=3;
    if(key=='1') angle1+=3;
    if(key=='2') angle1-=3;
    if(key=='3') angle2+=3;
    if(key=='4') angle2-=3;


    glutPostRedisplay();
}

void display()
{
 glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(teapotX,0,1,0);
        glutWireTeapot(0.3);
       
        glPushMatrix();//右手 
            glTranslatef(0.4,0,0);
            glutSolidSphere(0.2,30,30);
            glPushMatrix();
              glRotatef(angle1,0,0,1);
              glTranslatef(0.3,0,0);
              glScalef(2,1,1);
              glutSolidCube(0.2);
            glPopMatrix();
       glPopMatrix();
        
       
       glPushMatrix();//左手 
         glTranslatef(-0.4,0,0);
         glutSolidSphere(0.2,30,30);
         glPushMatrix();
             glRotatef(angle1,0,0,1);  
             glTranslatef(-0.3,0,0);
             glScalef(2,1,1);
             glutSolidCube(0.2);
         glPopMatrix();
       glPopMatrix();
       
       
       glPushMatrix();//右腳 
            glTranslatef(0.2,-0.2,0);
            glRotatef(angle2,1,1,0);
            glTranslatef(0,-0.36/2,0);
            glPushMatrix(); 
              glScalef(0.2,0.36,0.2);
              glutSolidCube(1);
            glPopMatrix();
            glPushMatrix();
              glTranslatef(0,-0.18,0);
              glRotatef(angle2,0,0,1);
              glTranslatef(0,-0.36/2,0);
              glScalef(0.2,0.36,0.2);
              glutSolidCube(1);
            glPopMatrix();
       glPopMatrix();
       
       
       glPushMatrix();//左腳 
            glTranslatef(-0.2,-0.2,0);
            glRotatef(angle2,-1,1,0);
            glTranslatef(0,-0.36/2,0);
            glPushMatrix(); 
              glScalef(0.2,0.36,0.2);
              glutSolidCube(1);
            glPopMatrix();
            glPushMatrix();
              glTranslatef(0,-0.18,0);
              glRotatef(angle2,0,0,1);
              glTranslatef(0,-0.36/2,0);
              glScalef(0.2,0.36,0.2);
              glutSolidCube(1);
            glPopMatrix();
       glPopMatrix();
        
        
        glPushMatrix();//頭 
         glTranslatef(0,0.4,0);
         glutSolidSphere(0.2,30,30);
        glPopMatrix();
        
        
        
        
        
      
       
    glPopMatrix();

    glutSwapBuffers();
}
void myLight()
{
    const GLfloat light_position[] = { 2.0f, 5.0f, -5.0f, 0.0f };
    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_LIGHTING); 
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
}
int main()
{
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week10");
   
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    myLight();

    glutMainLoop();
}