2022電腦圖學 Computer Graphics 授課教師: 葉正聖 銘傳大學資訊傳播工程系 每週主題: 程式環境、點線面顏色、移動/旋轉/縮放與矩陣(Matrix)、階層性關節轉動(T-R-T)、做出機器人、打光、貼圖、glu/glut函式、鍵盤、滑鼠、計時器(timer)、讀入3D模型、粒子系統、聲音、特效、投影矩陣、攝影機與運鏡、機器人2.0、期末作品
2022年6月25日 星期六
電腦圖學week16課堂筆記
電腦圖學week14課堂筆記
課堂內容 : fprintf()、fscanf() 寫檔和讀檔;fprintf()、fscanf() + project
#include <stdio.h>
int main()
{
FILE * fout = fopen("file.txt", "w+");
printf("Hello World\n");
fprintf(fout,"Hello World\n");
fclose(fout);
}
電腦圖學week13課堂筆記
#include <GL/glut.h>
float angle=45;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,1);
glRectf( 0.3, 0.5, -0.3, -0.5);
glPushMatrix();
glTranslatef( 0.3, 0.4, 0);
glRotatef(angle, 0,0,1);
glTranslatef(-0.3, -0.4, 0);
glColor3f(1,0,0);
glRectf( 0.3, 0.5, 0.7, 0.3);
glPopMatrix();
glutSwapBuffers();
}oldX = x;
}
2022年6月23日 星期四
1. alpha 內插公式: 0.0 ~ 1.0
➡ angle=alpha*新角度+(1-alpha)*舊角度
利用excel來練習
2-1.複製上週 week15-angle-TRT-again 程式碼
檔名: week16-interpolation
改善按r之後動作不連續的狀況,利用alpha內插法
程式碼:
4.改視角,aspect ratio:長寬比(寬:長)
#include <GL/glut.h>
void reshape(int w,int h)
{///不能用整數除,長寬比(寬/長)
float ar = (float)w / (float)h;
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);///3D變2D
glLoadIdentity();
gluPerspective(60,ar,0.1,100);
glMatrixMode(GL_MODELVIEW);///3D Model+View
glLoadIdentity();
gluLookAt(0,0,3, ///eye位置
0,0,0, ///center看哪裡
0,1,0);///up向量
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(1);
glutSwapBuffers();
}
void motion(int x,int y)
{
glMatrixMode(GL_MODELVIEW);///3D Model+View
glLoadIdentity();
gluLookAt((x-150)/150.0,(y-150)/150.0,3, ///eye位置
0,0,0, ///center看哪裡
0,1,0);///up向量
glutPostRedisplay();
}///根據滑鼠移動轉換視角
int main(int argc,char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week16 camera");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutReshapeFunc(reshape);///初始視角
glutMainLoop();
}
2022年6月22日 星期三
Ru的電腦圖學筆記>
Step01
1.利用Excel來把alpha內插公式實作出來, 看到新的、舊的資料可以做內插
-alpha 內插公式:alpha: 0.0~1.0
-angle = alpha*新 + (1-alpha)*舊
2.拿 week15_angles_TRT_again 來改
-建立新的 GLUT 檔案,檔名:week16_interpolation
Step02
1.講解上一週作業
2.利用課本的範例,講解gluLookAt(眼睛座標、看哪裡、up向量)
-開啟之前在老師網頁下載的 windows/data/Projection.exe
Step03
1.建立新的 GLUT 檔案,檔名:week16_camera_projection_GlutLookat
2022年6月14日 星期二
電腦圖學筆記week17
筆記
Step
程式環境 : week01 (freeglut,GLUT專案)
week10 (OpenCV的設定)
week16 (改CBP的working_dir)
點線面顏色 : 10行程式碼 display()
main()前3行設定,最後一行glutMainLoop()
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,0);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
int main(int argc, char *argv[])//main()主函式 進階版
{
glutInit(&argc,argv);//把參數送給glutInit初始化
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);//雙緩衝區+3D深度功能
glutCreateWindow("第02週的程式喔!!");//開GLUT視窗
glutDisplayFunc(display);//顯示用的函式
glutMainLoop();
}打光 : 8行 + 10多行
const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };
const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };讀入3D模型 : 模型在工作目錄,glm.h、glm.cpp加進去 #include "glm.h" 再 GLMmodel * body; 再...
貼圖 : OpenCV 及 myTexture範例,還有圖,而且畫glmDraw(pmodel , GLM_TEXTURE GLM_SMOOTH);
int myTexture(char * filename)
{
IplImage * img = cvLoadImage(filename); ///OpenCV讀圖
cvCvtColor(img,img, CV_BGR2RGB); ///OpenCV轉色彩 (需要cv.h)
glEnable(GL_TEXTURE_2D); ///1. 開啟貼圖功能
GLuint id; ///準備一個 unsigned int 整數, 叫 貼圖ID
glGenTextures(1, &id); /// 產生Generate 貼圖ID
glBindTexture(GL_TEXTURE_2D, id); ///綁定bind 貼圖ID
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); /// 貼圖參數, 超過包裝的範圖T, 就重覆貼圖
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); /// 貼圖參數, 超過包裝的範圖S, 就重覆貼圖
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); /// 貼圖參數, 放大時的內插, 用最近點
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); /// 貼圖參數, 縮小時的內插, 用最近點
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img->width, img->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img->imageData);
return id;
}攝影機與運鏡 : 透視投影法 glyPerspective,配上glutReshapeFunc()再上gluLookAt()
VERY BEAUTIFUL, VERY POWERFUL
一. 一樣先安裝且設定好freeglut,OpecCV, 開啟CodeBlocks建立新專案 week11_gundam, 把 MyGundam.zip下載解壓縮後的data資料夾放到freeglut/bin裡面 把week09_openc...
-
第一個OPENGL程式 0.Codeblocks 17.12 mingw裝好 1.File-New-Project ,選OPENGL專案 2.在[...]的目錄中,選[桌面] Projectsje nir 01_OPENGL 3.下一步,完成後Build&Run 4.可...
-
第一個OpenGL程式 1.安裝好 CodeBlocks 17.12 2. File-New-Project, 選OpenGL專案 2.在[點點點]的目錄中, 選「桌面」,Projectsje nir 01_OPENGL 3.下一步下一步,完成後,Build&Run 4...
-
今天一開始我們先學播聲音 因為沒有音檔,所以一開始應該會播錯誤訊息的音效 然而可能程式會錯誤無法播放 就必須在compilier>linker裡設定winmm 然後是MP3檔 要先去moodle下載CMP3_MCI.h 才能播放 #include <stdio.h...











