- 桌面安裝freeglut把lib的libfreeglut.a複製改名成libglut32.a
- File-NewProject,GLUT專案week04_mouse__glScalef
- 貼上10行程式碼
- #include <GL/glut.h>
- void display()
- {
- glutSolidTeapot(0.3);
- glutSwapBuffers();
- }
- int main(int argc,char*argv[])
- {
- glutInit(&argc,argv);
- glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
- glutCreateWindow("week04 mouse glScalef");
- glutDisplayFunc(display);
- glutMainLoop();
- }
- 補上glClearColor(1.0,1.0,0.9,1.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
背景顏色變 - 旋轉 再貼上上周的程式碼motion的
- #include <GL/glut.h>
- float angle=0;
- void display()
- {
- glClearColor(1.0,0.0,0.9,1.0);
- 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 mouse glScalef");
- glutDisplayFunc(display);
- glutMotionFunc(motion);
- glutMainLoop();
- }
- 縮放
- #include <GL/glut.h>
- ///float angle=0;
- float s=1;
- void display()
- {
- glClearColor(1.0,0.0,0.9,1.0);
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
- glPushMatrix();
- ///glRotatef(angle,0,0,1);
- glScalef(s,s,s);
- glutSolidTeapot(0.3);
- glPopMatrix();
- glutSwapBuffers();
- }
- void motion(int x,int y){
- ///angle=x;
- s=1+(x-150)/150.0;
- display();
- }
- int main(int argc,char*argv[])
- {
- glutInit(&argc,argv);
- glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
- glutCreateWindow("week04 mouse glScalef");
- glutDisplayFunc(display);
- glutMotionFunc(motion);
- glutMainLoop();
- }
- week04_keyboard_mouse_motion
- #include <GL/glut.h>
- #include <stdio.h.>
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
- glutSolidTeapot(0.3);
- glutSwapBuffers();
- }
- void keyboard(unsigned char key,int x,int y){
- printf("key: %c x: %d y: %d\n",key,x,y);
- }
- int main(int argc,char*argv[])
- {
- glutInit(&argc,argv);
- glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
- glutCreateWindow("week04 keyboard mouse motion");
- glutDisplayFunc(display);
- glutKeyboardFunc(keyboard);
- glutMainLoop();
- }
- 改一下
- #include <GL/glut.h>
- #include <stdio.h.>
- float angle=0,oldX=0;
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
- glPushMatrix();
- glRotatef(angle,0,0,1);
- glutSolidTeapot(0.3);
- glPushMatrix();
- glutSwapBuffers();
- }
- void mouse(int button,int state,int x,int y)
- {
- oldX=x;
- }
- void motion(int x,int y)
- {
- angle+=(x-oldX);
- oldX=x;
- display();
- }
- void keyboard(unsigned char key,int x,int y)
- {
- printf("key: %c x: %d y: %d\n",key,x,y);
- }
- int main(int argc,char*argv[])
- {
- glutInit(&argc,argv);
- glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
- glutCreateWindow("week04 keyboard mouse motion");
- glutDisplayFunc(display);
- glutKeyboardFunc(keyboard);
- glutMouseFunc(mouse);
- glutMotionFunc(motion);
- glutMainLoop();
- }
- https://jsyeh.org/3dcg10/點開下載window.zip和data,zip
- week04 translate rotate scale貼上前一個程式碼
稍微改一下茶壺會自己旋轉- #include <GL/glut.h>
- #include <stdio.h.>
- float angle=0,oldX=0;
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
- glPushMatrix();
- glRotatef(angle++,0,0,1);
- glutSolidTeapot(0.3);
- glPopMatrix();
- glutSwapBuffers();
- }
- int main(int argc,char*argv[])
- {
- glutInit(&argc,argv);
- glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
- glutCreateWindow("week04 keyboard mouse motion");
- glutDisplayFunc(display);
- glutIdleFunc(display);
- glutMainLoop();
- }
- 旋轉縮小變色茶壺
- #include <GL/glut.h>
- #include <stdio.h.>
- float angle=0,oldX=0;
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
- glPushMatrix();
- glTranslatef(0.8,0,0);
- glRotatef(angle++,0,0,1);
- glScalef(0.3,0.3,0.3);
- glColor3f(0.5,1,1);
- glutSolidTeapot(0.3);
- glPopMatrix();
- glutSwapBuffers();
- }
- int main(int argc,char*argv[])
- {
- glutInit(&argc,argv);
- glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
- glutCreateWindow("week04 translate rotate scale");
- glutDisplayFunc(display);
- glutIdleFunc(display);
- glutMainLoop();
- }
- week04_rotate_translate_scale再創一個貼上前一個的程式碼
然後這兩個交換glRotatef(angle++,0,0,1); glTranslatef(0.8,0,0);#include <GL/glut.h>#include <stdio.h.>float angle=0,oldX=0;void display(){glClearColor(1.0,1.0,0.9,1.0);glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glPushMatrix();glRotatef(angle++,0,0,1);glTranslatef(0.8,0,0);glScalef(0.3,0.3,0.3);glColor3f(0.5,1,1);glutSolidTeapot(0.3);glPopMatrix();glutSwapBuffers();}int main(int argc,char*argv[]){glutInit(&argc,argv);glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);glutCreateWindow("week04 translate rotate scale");glutDisplayFunc(display);glutIdleFunc(display);glutMainLoop();}
2024電腦圖學 Computer Graphics
人智二甲
授課教師: 葉正聖 銘傳大學人工智慧應用學系
每週主題: 程式環境、點線面顏色、移動/旋轉/縮放與矩陣(Matrix)、階層性關節轉動(T-R-T)、做出機器人、打光、貼圖、glu/glut函式、鍵盤、滑鼠、計時器(timer)、讀入3D模型、粒子系統、聲音、特效、投影矩陣、攝影機與運鏡、機器人2.0、期末作品
2024年3月14日 星期四
電腦圖學 Week04
訂閱:
張貼留言 (Atom)
-
1.今天加入一個Blogger 2.創立一個自己的品牌 3.每周一篇,標籤(學號姓名,WeekXX) 4.第二節學到如何放圖片 5.老師教我們許多截圖法 6.實際在WebGL Water操作3D的球 (https://madebyevan.com/webgl-wate...
-
week16-1_sample_gluLookAt 在resize()函式 加入gluLookAt() 2想再按按鍵時看不同位置 if(key=='?') week16-2_glut_glutReshapeFunc_gluPerspective_gluLookAt...
-
1. week16-0_sample (1)安裝freeglut (2)安裝opencv,重開CodeBlocks --> 詳細去看 魚鱗電腦圖學Week05-1 (3) 打開新專案,命名為: week1 6-0_sample 2. 下載課本範例☆゚.*・。 (1)進...
沒有留言:
張貼留言