顯示具有 05161163_鄭岢庭 標籤的文章。 顯示所有文章
顯示具有 05161163_鄭岢庭 標籤的文章。 顯示所有文章

2018年5月28日 星期一

Week14_攝影機-投影矩陣

1.到 jsyeh.org/3dcg10\ 下載 data,win32,glut32.dll 開啟 projection.exe

















2.

















3.















static void resize(int width, int height)
{
    const float ar = (float) width / (float) height; /// aspect ratio 長寬比

    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
    ///因為這個透視投影很奇怪, camera 投影中心,在0,0,0
    ///但茶壺也在0,0,0, 茶壺裡面中心點,看不到茶壺
 

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0,0,2,  0,0,0,  0,1,0);/// 新加程式
}

2018年5月21日 星期一

Week13 寫檔,讀檔

1. 讀檔














#include <stdio.h>///使用standard輸入輸出IO
int main()
{
    FILE * fout=fopen("output.txt", "w+");
     ///FILE * 檔案指標 fout
     ///                   檔案 file
     ///                      open開啟
     ///                          "要開啟的檔名","w+"表示要寫/+檔案
    printf("Hellow world\n");
    fprintf(fout,"Hello world\n");
}

















int n;
scanf("%d", &n);///只是故意讓程式卡住,檔案就沒正常關閉
///檔案長度就會是0



#include <GL/glut.h>
#include <stdio.h>
FILE * fout=NULL;///檔案一開始是空的 NULL
float angle=0;
int oldX=0;
void mouse(int button, int state, int x, int y)
{
    oldX=x;
}
void motion(int x, int y)///用 mouse motion 來改關節 angle
{
    angle+=x-oldX;///角度稍微增減,以前教過把大象放到冰箱去的程式碼
    oldX=x;///把舊的更新成新的
    if(fout==NULL)///一開始是空指標,所以會進來 if(....)
    {
        fout = fopen("output.txt", "w+");///開檔
    }///之後就不再是空指標了
    fprintf(fout, "%.3f\n",angle)///把角度印到檔案裡
    printf("%.3f\n",angle);///把角度印出來
    glutPostRedisplay();///重畫畫面

}

→先用滑鼠作出想要的動畫,在按空白鍵跑出剛剛的動畫








2018年5月14日 星期一

Week12-計時器 Timer

1.下載聲音檔存到 C:\Users\user\Desktop\freeglut\bin
   開啟 glut專案加入

   #include<mmsystem.h>
   int main(int argc, char *argv[])
  {
       PlaySoundA("shot.wav", NULL, SND_ASYNC); ....














2.利用MP3檔播放

#include <mmsystem.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
int main(int argc, char *argv[])
{
    myMP3.Load("123.mp3");
    myMP3.Play(); ....

3.加入計時器
#include <mmsystem.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
void timer(int t)
{
    glutTimerFunc(2000, timer, 0);
    PlaySound("Shot.wav", NULL, SND_ASYNC);
}
int main(int argc, char *argv[])
{
    ///myMP3.Load("123.mp3");
    ///myMP3.Play();
    .
    .
    .
    .
    .
    glutReshapeFunc(resize);
    glutDisplayFunc(display);
    glutKeyboardFunc(key);
    glutIdleFunc(idle);
    glutTimerFunc(3000, timer, 0);


2018年5月7日 星期一

week11音效,音樂

1. 到http://billor.chsh.chc.edu.tw/sound/mz.htm
   下載聲音檔存到 C:\Users\user\Desktop\freeglut\bin
   開啟 glut專案加入

   #include<mmsystem.h>
   int main(int argc, char *argv[])
  {
       PlaySoundA("bass.wav", NULL, SND_ASYNC);....
















2.利用鍵盤發出聲音















#include<mmsystem.h>
static void key(unsigned char key, int x, int y)
{
    switch (key)
    {
        case '1': PlaySound("Do.wav", NULL, SND_ASYNC);
            break;

        case '2': PlaySound("Re.wav", NULL, SND_ASYNC);
            break;

        case '3': PlaySound("Mi.wav", NULL, SND_ASYNC);
            break;

        case '4': PlaySound("Fa.wav", NULL, SND_ASYNC);
            break;

        case '5': PlaySound("So.wav", NULL, SND_ASYNC);
            break;

        case '6': PlaySound("La.wav", NULL, SND_ASYNC);
            break;

        case '7': PlaySound("Si.wav", NULL, SND_ASYNC);
            break;

3. 點擊滑鼠發出聲音


2018年4月30日 星期一

week10-貼圖

1.到 jsyeh.org/3dcg10/ 下載 data.zip、windows.zip、glut32.dll,將 windows.zip解壓縮,把 data.zip、 glut32.dll 移到 windows 資料夾裡,開啟 Texture.exe















2."最簡單的讀圖秀圖" →到moodle下載 OpenCV-2.1.0-win32-vs2008.exe ,開啟 glut專案














2018年4月16日 星期一

Week08-打光

1.到 jsyeh.org/3dcg10/ 下載 data.zip、windows.zip、glut32.dll、source.zip,將 windows.zip解壓縮,把 data.zip、 glut32.dll 移到 windows 資料夾裡,開啟 Light Material.exe 


2.打光







2018年4月9日 星期一

Week07-3D模型

1.到 Moodle 下載 3D Exploration→到 jsyeh.org/3dcg10/ 下載 data.zip 移到桌面
   →用 3D Exporer開啟





























2.到 jsyeh.org/3dcg10/ 下載 source.zip 解壓縮→複製 glm.h, glm.c(改成 glm.cpp ),
   transformation.c(改成 transformation.cpp )到專案的資料夾,複製 data 到 freeglut/bin
   開啟 codebloks glut 專案 , setting Compiler 把勾勾清掉
 
   記得把 main.cpp程式碼刪掉














3.自己打造3D模型程式















記得把 transformation.cpp 程式碼刪掉

#include "glm.h"
GLMmodel * pmodel=NULL;

void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    if (!pmodel) {
pmodel = glmReadOBJ("data/porsche.obj");
if (!pmodel) exit(0);
glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);
    }

    glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);

    glutSwapBuffers();
}
int main(int argc, char ** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week07 我自己的3D模型讀進來");

    glutDisplayFunc(display);
    glutMainLoop();
}























2018年3月26日 星期一

Week05_T-R-T 特定轉軸

1. 看Transformation.exe 改順序
    進入http://jsyeh.org/3dcg10
    下載 win32 , data , glut32.dll
    解壓縮 windows → 開啟 data , 拖曳 data資料夾和 glut32.dll 到 windows 資料夾
    →開啟 Transformation.exe















2.















#include <GL/glut.h>
float angle=0;///旋轉的角度
void motion (int x, int y)///mouse motion 拖著移動時,會叫 motion()
{
    angle = x;///老師用上周較差的方法,直接把 mouse 座標,變轉動角度
    glutPostRedisplay();///請畫面重畫
}
void display()///畫面要 display 時呼叫這個函式
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///先清畫面
    glPushMatrix();///備份矩陣(乾淨的矩陣)
            glRotatef(angle, 0,0,1);///rotate/translate/scale都會把矩陣改變
            glTranslatef(0.45, -0.08, 0);///移動,讓茶壺的柄,放到畫面的中心
            glutSolidTeapot(0.3);///TODO: 請試著把茶壺的柄,放到畫面的中心
    glPopMatrix();///還原矩陣(乾淨的矩陣)
    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week05 TRT");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}

















#include <GL/glut.h>
float angle=0;///旋轉的角度
void motion (int x, int y)///mouse motion 拖著移動時,會叫 motion()
{
    angle = x;///老師用上周較差的方法,直接把 mouse 座標,變轉動角度
    glutPostRedisplay();///請畫面重畫
}
void display()///畫面要 display 時呼叫這個函式
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///先清畫面
    glPushMatrix();///備份矩陣(乾淨的矩陣)
        glutSolidTeapot(0.3);///放在中間

            glTranslatef(0.5, 0.15, 0);///把會旋轉的茶壺柄,放到右上角
            glRotatef(angle, 0,0,1);///把整個對畫面中心做旋轉
            glTranslatef(0.45, -0.08, 0);///移動,讓茶壺的柄,放到畫面的中心
            glutSolidTeapot(0.3);///TODO: 請試著把茶壺的柄,放到畫面的中心
    glPopMatrix();///還原矩陣(乾淨的矩陣)
    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week05 TRT");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}
















#include <GL/glut.h>
float angle=0;///旋轉的角度
void motion (int x, int y)///mouse motion 拖著移動時,會叫 motion()
{
    angle = x;///老師用上周較差的方法,直接把 mouse 座標,變轉動角度
    glutPostRedisplay();///請畫面重畫
}
void display()///畫面要 display 時呼叫這個函式
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///先清畫面
    glPushMatrix();///備份矩陣(乾淨的矩陣)
        glutSolidTeapot(0.3);///放在中間
        glPushMatrix();
            glTranslatef(0.5, 0.15, 0);///把會旋轉的茶壺柄,放到右上角
            glRotatef(angle, 0,0,1);///把整個對畫面中心做旋轉
            glTranslatef(0.45, -0.08, 0);///移動,讓茶壺的柄,放到畫面的中心
            glutSolidTeapot(0.3);///TODO: 請試著把茶壺的柄,放到畫面的中心

            glPushMatrix();///備份矩陣(乾淨的矩陣)
                glutSolidTeapot(0.3);///放在中間

                glTranslatef(0.5, 0.15, 0);///把會旋轉的茶壺柄,放到右上角
                glRotatef(angle, 0,0,1);///把整個對畫面中心做旋轉
                glTranslatef(0.45, -0.08, 0);///移動,讓茶壺的柄,放到畫面的中心
                glutSolidTeapot(0.3);///TODO: 請試著把茶壺的柄,放到畫面的中心
            glPopMatrix();
         glPopMatrix();
    glPopMatrix();///還原矩陣(乾淨的矩陣)
    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week05 TRT");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}

2018年3月19日 星期一

WEEK04-移動.旋轉.縮放

1.試 glRoatatef (角度, x軸, y軸, z軸)
       (OpenGL)(float)      ↳     ↳      ↳各種旋轉軸
















2.期中考考題
























3.練習旋轉的程式
























#include <stdio.h>
#include <GL/glut.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///備份矩陣
        glRotatef(angle, 0,0,1);///旋轉angle度
        glutSolidTeapot(0.3);
    glPopMatrix();///還原矩陣
    glutSwapBuffers();
    printf("%.1f\n", angle);
    angle++;///每次角度加1
}
int main(int argc, char*argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week04 transformation");
    glutIdleFunc(display);///很閒/Idle,去重畫
    glutDisplayFunc(display);
    glutMainLoop();

}



4.利用滑鼠拖曳,旋轉
























#include <stdio.h>
#include <GL/glut.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///備份矩陣
        glRotatef(angle, 0,0,1);///旋轉angle度
        glutSolidTeapot(0.3);
    glPopMatrix();///還原矩陣
    glutSwapBuffers();
    ///printf("%.1f\n", angle);
    ///angle++;///每次角度加1
}
void mouse(int button, int state, int x, int y)
{

}
void motion(int x, int y)
{///Now: 當mouse在拖曳motion時,
    angle=x;///Now: 去改變angle值
    glutPostRedisplay();///請重面重畫
}
int main(int argc, char*argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week04 transformation");
    glutMouseFunc(mouse);///Now: mouse
    glutMotionFunc(motion);///Now: motion
    ///Now: glutIdleFunc(display);///很閒/Idle,去重畫
    glutDisplayFunc(display);
    glutMainLoop();
}

2018年3月12日 星期一

week3筆記

1.複習點線面顏色



2.使用滑鼠點擊 teapot 出現座標















3.使用滑鼠移動 teapot
   加入 motion 滑動












float teapotX=0, teapotY=0; // teapot 的位置,一開始在0 , 0
void motion(int x,int y)
{
    teapotX=(x-150)/150.0;  teapotY=-(y-150)/150.0;// 把你的 mouse 位置,設成 teapot 的位置
    printf("%d %d\n", x, y); // 印出移動的數字
    glutPostOverlayRedisplay();
}

2018年3月5日 星期一

Week2 點線面,顏色

1. 進入 http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/ 下載 data,win32,glut32(需與shape.exe同一目錄),開啟shape.exe,右鍵選形狀,左鍵拖拉數字改變



2. 開始動手畫點線面



3. 更改顏色














glColor3f(r,g,b);

gl 是 OpenGL的函式

Color是色彩,3個參數,f float浮點數介於 0.0-1.0,ub unsigned char 0-255

2018年2月26日 星期一