顯示具有 00161081_李惠筠 標籤的文章。 顯示所有文章
顯示具有 00161081_李惠筠 標籤的文章。 顯示所有文章

2013年5月17日 星期五

第十三周上課內容

1.旋轉茶壺:
程式碼:

#include<GL/glut.h>
#include<stdio.h>
float rot=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(rot,0,0,1);
glutSolidTeapot(0.1);
glPopMatrix();
glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y)
{
if(key=='a') rot++;
printf("%f\n",rot);
glutPostRedisplay();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("text");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;

}
圖片:

旋轉後(按a鍵):

轉轉長方形:


#include<GL/glut.h>
#include<stdio.h>
float rot=0;

void body()
{
glBegin(GL_POLYGON);
glVertex2f(-0.3,-0.1);
glVertex2f(0.3,-0.1);
glVertex2f(0.3,0.1);
glVertex2f(-0.3,0.1);
glEnd();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glColor3f(1,1,1);
glutSolidTeapot(0.3);
glRotatef(rot,0,0,1);
glTranslatef(0.3,0.1,0);
glColor3f(1,0,0);
body();
glPopMatrix();
glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y)
{
if(key=='a') rot++;
printf("%f\n",rot);
glutPostRedisplay();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("text");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;

}
圖:
3.移動方形:
程式碼:

#include<GL/glut.h>
#include<stdio.h>
float rot=0;

void body()
{
glBegin(GL_POLYGON);
glVertex2f(-0.3,-0.1);
glVertex2f(0.3,-0.1);
glVertex2f(0.3,0.1);
glVertex2f(-0.3,0.1);
glEnd();
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glColor3f(1,1,1);
glutSolidTeapot(0.3);
glTranslatef(0.5,0.13,0);//第3步把轉動物體移到右上角 
glRotatef(rot,0,0,1);//第1步有個轉動中心 
glTranslatef(0.3,0.1,0);//第3步把旋轉中心移動 
glColor3f(1,0,0);
body();
glPopMatrix();
glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y)
{
if(key=='a') rot++;
printf("%f\n",rot);
glutPostRedisplay();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("text");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
圖:
 
作業:
#include <GL/glut.h>
#include <stdio.h>
#include <opencv/highgui.h>
#include <opencv/cv.h>
GLuint gun, gundam;
GLuint leftlower;

float rot=0;//角度初始為0
void drawLeftLower()//盾牌
{
    glEnable(GL_TEXTURE_2D);
 glBindTexture(GL_TEXTURE_2D,leftlower);
    glBegin(GL_POLYGON);
  glTexCoord2f(0,0);glVertex3f(-0.9,-0.15,0);//貼圖座標
  glTexCoord2f(1,0);glVertex3f(0.9,-0.15,0);//貼圖座標
  glTexCoord2f(1,1);glVertex3f(0.9,0.15,0);//貼圖座標
  glTexCoord2f(0,1);glVertex3f(-0.9,0.15,0);//貼圖座標
 glEnd();        
}
void drawGun()//槍
{
    glEnable(GL_TEXTURE_2D);
 glBindTexture(GL_TEXTURE_2D,gun);
    glBegin(GL_POLYGON);
  glTexCoord2f(0,0);glVertex3f(-1,-0.3,0);//貼圖座標
  glTexCoord2f(1,0);glVertex3f(1,-0.3,0);//貼圖座標
  glTexCoord2f(1,1);glVertex3f(1,0.3,0);//貼圖座標
  glTexCoord2f(0,1);glVertex3f(-1,0.3,0);//貼圖座標
 glEnd();       
}
void drawGundam()//鋼彈模型
{
    glEnable(GL_TEXTURE_2D);
 glBindTexture(GL_TEXTURE_2D,gundam);
    glBegin(GL_POLYGON);
  glTexCoord2f(0,0);glVertex3f(-2,-1,0);//貼圖座標
  glTexCoord2f(1,0);glVertex3f(1,-1,0);//貼圖座標
  glTexCoord2f(1,1);glVertex3f(1,1,0);//貼圖座標
  glTexCoord2f(0,1);glVertex3f(-2,1,0);//貼圖座標
 glEnd();       
}
void myTexture(GLuint &id, char * filename)
{
//Texture image file by OpenCV
 IplImage * img = cvLoadImage(filename);
 cvCvtColor(img,img,CV_BGR2RGB);
//Texture image file by OpenGL
 glEnable(GL_TEXTURE_2D);
 glGenTextures(1,&id);
 glBindTexture(GL_TEXTURE_2D,id);
 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,img->width,img->height,0,GL_RGB,GL_UNSIGNED_BYTE,img->imageData);
//Texture End
}
void display()
{
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 glPushMatrix();
  drawGundam();
      glPushMatrix();//備份matrix
  
                glTranslatef(-1, 0.2,0);//移動旋轉角度位置
       glRotatef(rot, 0,0,1);//旋轉角度
       glTranslatef(0, 0.2, 0 );//移動圖形
                drawGun();//槍
            glPopMatrix();//還原//matrix
   glPushMatrix();//備份matrix
    glTranslatef(0,0,0);//移動旋轉角度位置
    glRotatef(rot, 0,0,1);//旋轉角度
    glTranslatef(0,0,0);//移動圖形
    drawLeftLower();//盾牌
 
           glPopMatrix();//還原//matrix
 glPopMatrix();
 glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{
 if(key=='a') rot++;//按a逆時針走
 else if(key=='A') rot--;//按A順時針走

 printf("%f\n", rot);
 glutPostRedisplay();
}
int main()
{
 glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
 glutCreateWindow("00161081");
 myTexture(gun,"gun.png");
 myTexture(gundam,"gundam.png");
 myTexture(leftlower, "sh.png");

 glutDisplayFunc(display);
 glutKeyboardFunc(keyboard);

 glutMainLoop();
 return 0;
}
damo:
 



2013年5月10日 星期五

第十二周上課內容

1.

#include<GL/glut.h>
float dx=0.2,dy=1.3;
float x=0,y=-10;
void display()
{
     x+=dx;
     y+=dy;
     dy-=0.098;
     glPushMatrix();
        glScalef(0.1,0.1,0.1);
        glTranslatef(x,y,0);
        glutSolidTeapot(0.1);
     glPopMatrix();
     glutSwapBuffers();
 }
 int main()
 {
 glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
 glutCreateWindow("a");
 glutDisplayFunc(display);
 glutIdleFunc(display);
 glutMainLoop();
 return 0;

 }

#include<stdio.h>
#include<GL/glut.h>
float dx=0.2,dy=1.3;
float x=0,y=-10;
void display()
{
     x+=dx;
     y+=dy;
     dy-=0.098;
     glPushMatrix();
        glScalef(0.1,0.1,0.1);
        glTranslatef(x,y,0);
        glutSolidTeapot(0.1);
     glPopMatrix();
     glutSwapBuffers();
 }
 void keyboard(unsigned char key,int keyx,int keyy)
 {
  x=0;
  y=-10;
  dx=0.2;
  dy=1.3;
  printf("%f %f %f %f\n",x,y,dx,dy);
  glutPostRedisplay();
  }
 int main()
 {
 glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
 glutCreateWindow("a");
 glutDisplayFunc(display);
 glutIdleFunc(display);
 glutKeyboardFunc(keyboard);
 glutMainLoop();
 return 0;

 }


2013年5月3日 星期五

第十一周上課內容

1.會轉的茶壺:
程式碼:

#include<GL/glut.h>
float rot=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(rot,0,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void timer(int t)
{
glutTimerFunc(10,timer,t+1);
rot++;
glutPostRedisplay();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("0016108");
glutDisplayFunc(display);
glutTimerFunc(2000,timer,0);
glutMainLoop();

return 0;

}
圖:
2.會叫的聲音:
程式碼:
#include<windows.h>
#include<GL/glut.h>
float rot=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(rot,0,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void timer(int t)
{
glutTimerFunc(10,timer,t+1);
rot++;
glutPostRedisplay();
}
void oioi(int t)
{
glutTimerFunc(6000,oioi,0);
PlaySound("o.wav",NULL,SND_ASYNC);

}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("0016108");
glutDisplayFunc(display);
glutTimerFunc(2000,timer,0);
glutTimerFunc(6000,oioi,0);
glutMainLoop();

return 0;

}
3.MP3聲音:


#include<windows.h>
#include<GL/glut.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
float rot=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(rot,0,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void timer(int t)
{
glutTimerFunc(10,timer,t+1);
rot++;
glutPostRedisplay();
}
void oioi(int t)
{
glutTimerFunc(6000,oioi,0);
//PlaySound("o.wav",NULL,SND_ASYNC);

}
int main()
{
myMP3.Load("dance.mp3");
myMP3.Play();
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("0016108");
glutDisplayFunc(display);
glutTimerFunc(2000,timer,0);
// glutTimerFunc(6000,oioi,0);
glutMainLoop();

return 0;

}
4.音符聲音:

#include<windows.h>
#include<GL/glut.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
float rot=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(rot,0,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void timer(int t)
{
glutTimerFunc(10,timer,t+1);
rot++;
glutPostRedisplay();
}
void oioi(int t)
{
glutTimerFunc(6000,oioi,0);
//PlaySound("o.wav",NULL,SND_ASYNC);

}
void keyboard(unsigned char key,int x,int y)
{
if(key=='1')PlaySound("do.wav",NULL,SND_ASYNC);
if(key=='2')PlaySound("re.wav",NULL,SND_ASYNC);
if(key=='3')PlaySound("mi.wav",NULL,SND_ASYNC);
if(key=='4')PlaySound("fa.wav",NULL,SND_ASYNC);
if(key=='5')PlaySound("sol.wav",NULL,SND_ASYNC);
if(key=='6')PlaySound("la.wav",NULL,SND_ASYNC);
if(key=='7')PlaySound("ti.wav",NULL,SND_ASYNC);
if(key=='8')PlaySound("doHigh.wav",NULL,SND_ASYNC);
}
int main()
{

glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("0016108");
glutDisplayFunc(display);
glutTimerFunc(2000,timer,0);
glutKeyboardFunc(keyboard);
glutMainLoop();

return 0;

}






2013年4月12日 星期五

第八周上課內容

1.用opencv秀圖:

 
程式碼:
#include <opencv/highgui.h>
int main()
{
IplImage * image1=cvLoadImage("images.jpg");
cvNamedWindow("00161081");
cvShowImage("00161081",image1);
cvWaitKey(0);
return 0;
}

2.旋轉鬱金香:

3.茶壺+地圖轉動:
程式碼:
#include <GL/glut.h>
#include <opencv/highgui.h>
#include <opencv/cv.h>
GLuint id;
float rot=0;
void display()
{
 glEnable(GL_DEPTH_TEST);
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 glEnable(GL_TEXTURE_2D);
 glBindTexture(GL_TEXTURE_2D,id);
    glPushMatrix();
        glRotated(rot,1,0,0);
      glutSolidTeapot(0.3);
       
        glBegin(GL_POLYGON);
   glTexCoord2f(0,0);glVertex3f(-1,-1,0);
   glTexCoord2f(1,0);glVertex3f(1,-1,0);
   glTexCoord2f(1,1);glVertex3f(1,1,0);
   glTexCoord2f(0,1);glVertex3f(-1,1,0);
  glEnd();       
    glPopMatrix();
 glDisable(GL_TEXTURE_2D);

    glutSwapBuffers();
}
void idle()
{
 rot++;
 glutPostRedisplay();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("0161081_hw8");
glutDisplayFunc(display);
glutIdleFunc(idle);
//Texture image file by OpenCV
IplImage * img=cvLoadImage("images.jpg");
 cvCvtColor(img,img,CV_BGR2RGB);
//Texture image file by OpenGL
 glEnable(GL_TEXTURE_2D);
 glGenTextures(1,&id);
 glBindTexture(GL_TEXTURE_2D,id);
 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,img->width,img->height,0,GL_RGB,GL_UNSIGNED_BYTE,img->imageData);
//Texture End
    glutMainLoop();

cvNamedWindow("00161081");
cvShowImage("00161081",img);
cvWaitKey(0);
return 0;
}
圖片:
 
4.旋轉地球:

程式碼:
#include <GL/glut.h>
#include <opencv/highgui.h>
#include <opencv/cv.h>
GLUquadric *quad=NULL;
GLuint id;
float rot=0;
void display()
{
 glEnable(GL_DEPTH_TEST);
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 glEnable(GL_TEXTURE_2D);
 glBindTexture(GL_TEXTURE_2D,id);
    glPushMatrix();
        glRotatef(60,1,0,0);
        glRotatef(rot,0,0,1);
        gluQuadricTexture(quad,true);
        gluSphere(quad,1,30,30);
  glEnd();       
    glPopMatrix();
 glDisable(GL_TEXTURE_2D);

    glutSwapBuffers();
}
void idle()
{
 rot++;
 glutPostRedisplay();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("0161081_hw8");
glutDisplayFunc(display);
glutIdleFunc(idle);
//Texture image file by OpenCV
IplImage * img=cvLoadImage("images.jpg");
 cvCvtColor(img,img,CV_BGR2RGB);
//Texture image file by OpenGL
 glEnable(GL_TEXTURE_2D);
 glGenTextures(1,&id);
 glBindTexture(GL_TEXTURE_2D,id);
 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,img->width,img->height,0,GL_RGB,GL_UNSIGNED_BYTE,img->imageData);
//Texture End
    quad=gluNewQuadric();
    glutMainLoop();

cvNamedWindow("00161081");
cvShowImage("00161081",img);
cvWaitKey(0);
return 0;
}
圖片:

 


2013年3月22日 星期五

第五周上課進度

上課進度:
多拉A夢圓形
1.立體圓形+打光:
2.圓形的臉:
程式碼:

3.用鍵盤控制臉的位置:
程式碼(畫線部分維修改或增加的部分)
圖:
4.眼睛+旋轉
程式碼(畫線為增加或修改部分):
圖:
未轉之前




轉之後:
\
5.可用鍵盤來控制或查詢位址(Translatef)&大小(Scalef)
程式碼(畫線為增加部分):









2013年3月15日 星期五

第四周上課進度

課堂練習:
1.練習茶壺轉動:
程式碼+圖片:

圖片:

程式碼:

2.立體長方形+轉動+顏色+深度:

圖加程式碼:

圖片:

程式碼:

3.轉動的機器手臂:
 圖片+程式碼:

圖片:

程式碼:








                                                                                                                                                                   

2013年3月8日 星期五

第三週上課內容

第三週上課練習:
旋轉180度:

備份、移動、放大:
   
程式碼:

回家作業:

                                  


2013年3月1日 星期五

第二週上課練習

第二週上課練習:
回顧之前練習的:

三角形:

未設背景:

設背景:
回家作業截圖:


2013年2月22日 星期五

第一周上課內容

1.第一張圖,OpenGL


2.第二張圖,gult


3.這是我自己打出來的程式

4.第一週作業:
在家可執行OpenGL:
家裡電腦規格:
程式發展環境:Dev C++
設備:
   1.RAM:4069MB
   2.CPU:Intel(R) Core(TM) i5-2430M CPU @2.40GHz(4CPU)~2.4GHz
   3.硬碟大小:
          (1)C:288GB
          (2)D:289GB
      共:577GB
   4.作業系統:Window 7
   5.網路:Google
   6.顯示卡等級:NVIDIA GeForce GT 540M
     顯示卡價錢:5599