2022電腦圖學 Computer Graphics 授課教師: 葉正聖 銘傳大學資訊傳播工程系 每週主題: 程式環境、點線面顏色、移動/旋轉/縮放與矩陣(Matrix)、階層性關節轉動(T-R-T)、做出機器人、打光、貼圖、glu/glut函式、鍵盤、滑鼠、計時器(timer)、讀入3D模型、粒子系統、聲音、特效、投影矩陣、攝影機與運鏡、機器人2.0、期末作品
2022年3月29日 星期二
啵咕咕的圖學筆記
2022年3月22日 星期二
啵咕咕的圖學筆記week05
****電腦圖學之父 Ivan Sutherland*****
如同上週jsyeh.org/3dcg10.....
標準10行
#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)
{
glutInit( &argc, argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow("week05");
glutDisplayFunc(display);
glutMainLoop();
}
本週新程式
#include <GL/glut.h>
#include<stdio.h>
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glColor3f(1,1,0);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void keyboard( unsigned char key,int x,int y)
{
printf("%c %d,%d\n",key,x,y);
}
int main(int argc, char** argv)
{
glutInit( &argc, argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow("week05");
glutDisplayFunc(display);
glutKeyboardFunc(keybord);
glutMainLoop();
}
接續剛剛的
void keyboard( unsigned char key,int x,int y)
{
}
void mouse(int button,int state,int x,int y)
{
}
void motion(int x,int y)
{
}
int main(int argc, char** argv)
{
glutInit( &argc, argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow("week05");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
繼續
#include <GL/glut.h>
#include<stdio.h>
float x=150, y=150, z=0;
int oldX=0, oldY=0;
void display()
{
glClearColor(0.5,0.5,0.5,1);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
glTranslatef((x-150)/150.0, -(y-150)/150.0,z);
glColor3f(1,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void keyboard( unsigned char key,int x,int y)
{
}
void mouse(int button,int state,int mouseX,int mouseY)
{
oldX=mouseX; oldY=mouseY;
}
void motion(int mouseX,int mouseY)
{
x += (mouseX-oldX); y +=(mouseY-oldY);
oldX=mouseX; oldY=mouseY;
display();
}
int main(int argc, char** argv)
{
glutInit( &argc, argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow("week05");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
縮放
#include <GL/glut.h>
#include<stdio.h>
float x=150, y=150, z=0, scale=1.0;
int oldX=0, oldY=0;
void display()
{
glClearColor(0.5,0.5,0.5,1);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
glTranslatef((x-150)/150.0, -(y-150)/150.0,z);
glScalef(scale, scale, scale);
glColor3f(1,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void keyboard( unsigned char key,int x,int y)
{
}
void mouse(int button,int state,int mouseX,int mouseY)
{
oldX=mouseX; oldY=mouseY;
}
void motion(int mouseX,int mouseY)
{
if(mouseX-oldX>0) scale*=1.01;
if(mouseY-oldY<0) scale*=0.99;
oldX=mouseX; oldY=mouseY;
display();
}
int main(int argc, char** argv)
{
glutInit( &argc, argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow("week05");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
2022年3月15日 星期二
啵咕咕的圖學筆記week04
week04
跟上周一樣,這次調rotate
旋轉程式
#include<GL/glut.h>
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
glRotatef(90, 0,0,1);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
用滑鼠旋轉#include<GL/glut.h>
float angle=0;
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
glRotatef(angle, 0,0,1);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x, int y)
{
angle=x;
display();
}
int main(int argc, char** argv)
{
glutInit( &argc, argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow("week04_rotate");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
修治精準度
2022年3月8日 星期二
啵咕咕的圖學筆記 week03
Week03 1-1進到https://jsyeh.org/3dcg10,下載data、win32
再將windows.zip、data.zip解壓縮 1-2將data放到windows裡面,執行Transformation.exe,試試看換模型及調整下方
上週程式新增
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix(); 備份矩陣 移動會累積,因為會修改矩陣
glTranslated(0.5,0.5,0); 右上角
glColor3f(1,1,0);
glutSolidTeapot(0.3);
glPopMatrix();還原矩陣(舊的位置)
glutSwapBuffers();
}
進階:
#include <GL/glut.h>
void myteapot(float x, float y)
{
glPushMatrix();
glTranslatef(x, y,0);
glColor3f(1,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
}
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
myteapot(0.5,0.5);
myteapot(0.5,-0.5);
myteapot(-0.5,0.5);
myteapot(-0.5,-0.5);
glutSwapBuffers();
}
int main(int argc, char** argv)
{
glutInit( &argc, argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow("week03 移動");
glutDisplayFunc(display);
glutMainLoop() ;
}
用滑鼠寫程式:
#include<GL/glut.h>
#include<stdio.h>
float mouseX=0, mouseY=0;
void myteapot(float x, float y)
{
glPushMatrix();
glTranslatef(x, y, 0);
glColor3f(1,1,0);
glutSolidTeapot(0.1);
glPopMatrix();
}
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
myteapot( (mouseX-150)/150.0,-(mouseY-150)/150.0); 座標換算
glutSwapBuffers();
}
void mouse(int button, int state, int x, int y)
{
printf("%d %d %d %d\n", button ,state,x,y);
mouseX=x; mouseY=y;
}
int main(int argc, char** argv)
{
glutInit( &argc, argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow("week03 ²¾°Ê");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop() ;
}
2022年3月1日 星期二
啵咕咕的圖學筆記 week02
1. 下載範例 https://jsyeh.org/3dcg10
data.zip windows.zip glut32.dll
2. data.zip=解壓=>下載\windows\data\模型
windows.zip=解壓=>windows\Shapes.exe
glut32.dll=複製=> 下載\windows\glut32.dll
3. 跑 Shape.exe 看範例試試看
左按右鍵選單:大頂點 多色
右按右鍵選單:point...polygon
2022年2月22日 星期二
啵咕咕的圖學筆記 week01
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...





