顯示具有 01160422_彭胤峰 標籤的文章。 顯示所有文章
顯示具有 01160422_彭胤峰 標籤的文章。 顯示所有文章

2014年5月2日 星期五

01160422_彭胤峰

#include <GL/glut.h>
float angleX=0;
float angleY=0;
float angle1=0;
float angle2=0;
float angle3=0;
float angle4=0;
void keyboard(unsigned char key, int x, int y)
{
     if(key=='1') angle1+=5;
     if(key=='2') angle1-=5;
     if(key=='3') angle2+=5;
     if(key=='4') angle2-=5;
     if(key=='5') angle3+=5;
     if(key=='6') angle3-=5;
     if(key=='7') angle4+=5;
     if(key=='8') angle4-=5;
     if(key=='9') angleX+=5;
     if(key=='0') angleX-=5;
     if(key=='z') angleY+=5;
     if(key=='x') angleY-=5;
     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);
}

void display()
{
     glEnable(GL_DEPTH_TEST);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     glPushMatrix();
     glRotatef(angleX,0,1,0);
     glRotatef(angleY,1,0,0);
     glPushMatrix(); //頭部
       glTranslatef(0,0.3,0);
       glutSolidSphere(0.1,100,100);
     glPopMatrix();
 
     glPushMatrix(); //身體
       glTranslatef(0,0,0);
       glutSolidSphere(0.2,100,100);
     glPopMatrix();
 
    glPushMatrix(); //右手軸
      glTranslatef(0.3,0,0);
      glutSolidSphere(0.1,100,100);
        glPushMatrix(); //右手
          glRotatef(angle1,0,0,1);
          glTranslatef(0.2,0,0);
          glScalef(0.3,0.1,0.1);
          glutSolidCube(1);
       glPopMatrix();
     glPopMatrix();
 
  glPushMatrix(); //左手軸
    glTranslatef(-0.3,0,0);
    glutSolidSphere(0.1,100,100);
    glPushMatrix(); //左手
        glRotatef(angle2,0,0,1);
        glTranslatef(-0.2,0,0);
        glScalef(0.3,0.1,0.1);
        glutSolidCube(1);
    glPopMatrix();
  glPopMatrix();
 
  glPushMatrix();
    glTranslatef(0.3,-0.3,0);
    glutSolidSphere(0.1,100,100);
    glPushMatrix();
        glRotatef(angle3,1,0,0);
        glTranslatef(0,-0.1,0);
        glScalef(0.1,0.3,0.1);
        glutSolidCube(1);
    glPopMatrix();
  glPopMatrix();
 
   glPushMatrix();
    glTranslatef(-0.3,-0.3,0);
    glutSolidSphere(0.1,100,100);
    glPushMatrix();
        glRotatef(angle4,1,0,0);
        glTranslatef(0,-0.1,0);
        glScalef(0.1,0.3,0.1);
        glutSolidCube(1);
    glPopMatrix();
  glPopMatrix();
 
 
 glPopMatrix();
 glutSwapBuffers();
}

int main()
{
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week11");

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);

    myLight();
    glutMainLoop();
}

2014年4月25日 星期五

01160422_彭胤峰




/*keyboard event + Command*/

#include <GL/glut.h>
#include <stdio.h>
#include <math.h>
float anglex=0 , angley=0 , startx=0 , starty=0;
float m[16]={1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};
void keyboard(unsigned char key , int x , int y)
{
     printf("%c %d %d\n",key,x,y);
     if(key=='a') anglex+=3;
     if(key=='b') anglex-=3;
     glutPostRedisplay();
}
void mouse(int button , int state /*按住0 放開1 */ , int x , int y)
{
     printf("%d %d %d %d\n",button,state,x,y);
     startx=x;
     starty=y;
}
void motion(int x , int y) //拖曳function
{
     printf("%d %d\n",x,y);
     anglex+=x-startx; startx=x; //拖曳之後 到下一個點
     angley+=y-starty; starty=y;
     glutPostRedisplay();
}
void display()
{
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); //清除畫面的方法
     glPushMatrix();
        float dist =sqrt(anglex*anglex + angley*angley);
        glRotatef(dist,-angley, -anglex , 0);
        glMultMatrixf(m);
        glGetFloatv(GL_MODELVIEW_MATRIX,m);
        glRotatef(anglex,0,-1,0); /*移動x 中心軸y*/
        glRotatef(angley,-1,0,0); /*移動y 中心軸x*/
        glutSolidTeapot(0.3);
     glPopMatrix();
     glutSwapBuffers();
}
void light()
{
     glEnable(GL_DEPTH_TEST); //深度測試
     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);
    glutMouseFunc(mouse);
    glutMotionFunc(motion); //拖曳
   
    light();
   
    glutMainLoop();
}

2014年3月28日 星期五

01160422_彭胤峰


#include <opencv/highgui.h>

int main()
{
    IplImage *img = cvLoadImage("earth.jpg");
    cvNamedWindow("01160422");
    cvShowImage("01160422",img);
    cvWaitKey(0);
}

2014年3月14日 星期五

01160422_彭胤峰

   
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//清畫面要清兩種東西(color繪出結果&depth深度值測試結果)  
glRotatef(2,0,1,0);
//角度,x,y,z
glutWireTeapot(0.3);
//網狀茶壺
glutPostRedisplay();
//再畫一次