1.先下載別人的程式(用與上週一樣別的程式去模擬!!)
與上週(Week 03)一樣到 http://jsyeh.org/3dcg10下載data.zip、windows.zip、glut32.dll這三個檔案!!
忘記上週怎麼用的話,給你上週連結(OWO)// ~ Week04,記得要好好再次複習!!
快速簡單步驟回想:
1.先到http://jsyeh.org/3dcg10下載data.zip、windows.zip、glut32.dll 這三個檔案
2.將data.zip、windows.zip 解壓縮
3.壓縮好後,將glut32.dll 和 data 複製到windows裡
4.執行 Transformation.exe,就可以完成
以上,想要更想詳細就點上方的Week04,就會點開上週筆記!!
開啟畫面↓
左上與右上的視窗點滑鼠右鍵可以轉換功能與模型
點選下方數 長按 字數上下移動可以改變數字大小
2.這週來介紹圖形公轉與自轉
公轉:在旋轉時,圖形的旋轉中心點並非在圖形中心點,看起來像是圖形繞著一點轉
自轉:就是圖形以自己中心旋轉
用程式來看看公轉與自轉:
自轉:
公轉:
達!達達達!!!!!!!
是的!!glRotate跟glTranslate的順序是不一樣的!!
自轉:
程式碼:
glTranslationf( , , );
glRotatef( , , , );
glScalef( , , );
glBegin(...);
...
EX:
而程式執行順序:
1.繪畫出車子
2.將車子縮放大小(自己所覺得適合的)
3.轉動車子
4.移動車子本身與車子的旋轉中心點
公轉:
程式碼:
glRotatef( , , , );
glTranslationf( , , );
glScalef( , , );
glBegin(...);
...
EX:
而程式執行順序:
1.繪畫出車子
2.將車子縮放大小(自己所覺得適合的)
3.移動車子(旋轉中心不會移動)
4.(繞著剛剛不變的旋轉中心)車子旋轉
比較特別程式執行的順序是要從下往上看。
1.先照之前用CodeBlocks開啟GLUT!
忘記怎麼用的話,給你連結(OWO)// ~在Week01,複習!!複習!
2.開始改成公轉與自轉的程式
自轉:
程式碼(更改地方):
glPushMatrix();
glTranslated(0,0,-6);
glRotated(a,0,0,1);
glTranslated(0,0,-6);
glRotated(a,0,0,1);
//轉動Z軸
glutSolidSphere(1,slices,stacks);
glPopMatrix();
glutSolidSphere(1,slices,stacks);
glPopMatrix();
公轉:
程式碼(更改地方):
glRotated(a,0,0,1);
//轉動Z軸
glTranslated(1.2,0,-6);
glutSolidSphere(1,slices,stacks);
glPopMatrix();
glTranslated(1.2,0,-6);
glutSolidSphere(1,slices,stacks);
glPopMatrix();
(3)用茶壺做 T-R-T轉動
程式碼:
#include <GL/glut.h>
float angle=0; ///Now: 讓茶壼自動轉動的角度
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix(); ///Now:備份矩陣
glRotatef(angle, 0,0,1); ///Now:轉動樓下全部
glTranslatef(0.45,-0.1,0); ///把茶壺柄移到中間
glutSolidTeapot(0.3);
glPopMatrix(); ///Now:還原矩陣
glutSwapBuffers();
}
void motion(int x, int y)
{
angle=x; ///Now: 改變角度
glutPostRedisplay(); ///Now: 請 重畫畫面
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("QWQ");
float angle=0; ///Now: 讓茶壼自動轉動的角度
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix(); ///Now:備份矩陣
glRotatef(angle, 0,0,1); ///Now:轉動樓下全部
glTranslatef(0.45,-0.1,0); ///把茶壺柄移到中間
glutSolidTeapot(0.3);
glPopMatrix(); ///Now:還原矩陣
glutSwapBuffers();
}
void motion(int x, int y)
{
angle=x; ///Now: 改變角度
glutPostRedisplay(); ///Now: 請 重畫畫面
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("QWQ");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
glutMotionFunc(motion);
glutMainLoop();
}
(4)運用T-R-T做出手臂範例(手臂以茶壺代替)
程式碼:
#include <GL/glut.h>
float angle=0;///Now: 讓茶壼自動轉動的角度
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///Now:備份矩陣
glColor3f(1,0,0);
glutSolidTeapot(0.3); ///中間的紅色茶壺
float angle=0;///Now: 讓茶壼自動轉動的角度
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///Now:備份矩陣
glColor3f(1,0,0);
glutSolidTeapot(0.3); ///中間的紅色茶壺
glPushMatrix();///右手臂
glTranslatef(0.4,0.13,0); ///最後掛上去
glRotatef(angle, 0,0,1);///Now:轉動樓下全部
glTranslatef(0.45,-0.1,0);///把茶壺柄移到中間
glColor3f(0,1,0);
glutSolidTeapot(0.3);
glPushMatrix();///右手肘
glTranslatef(0.4,0.13,0); ///最後掛上去
glRotatef(angle, 0,0,1);///Now:轉動樓下全部
glTranslatef(0.45,-0.1,0);///把茶壺柄移到中間
glColor3f(0,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glTranslatef(0.4,0.13,0); ///最後掛上去
glRotatef(angle, 0,0,1);///Now:轉動樓下全部
glTranslatef(0.45,-0.1,0);///把茶壺柄移到中間
glColor3f(0,1,0);
glutSolidTeapot(0.3);
glPushMatrix();///右手肘
glTranslatef(0.4,0.13,0); ///最後掛上去
glRotatef(angle, 0,0,1);///Now:轉動樓下全部
glTranslatef(0.45,-0.1,0);///把茶壺柄移到中間
glColor3f(0,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glPushMatrix();///左手臂
glTranslatef(-0.4,0.13,0); ///最後掛上去
glRotatef(angle, 0,0,1);///Now:轉動樓下全部
glTranslatef(-0.45,-0.1,0);///把茶壺柄移到中間
glColor3f(0,1,0);
glutSolidTeapot(0.3);
glPushMatrix();///左手肘
glTranslatef(-0.4,0.13,0); ///最後掛上去
glRotatef(angle, 0,0,1);///Now:轉動樓下全部
glTranslatef(-0.45,-0.1,0);///把茶壺柄移到中間
glColor3f(0,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glPopMatrix();///Now:還原矩陣
glutSwapBuffers();
}
void motion(int x, int y)
{
angle=x;///Now: 改變角度
glutPostRedisplay();///Now: 請 重畫畫面
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("QWQ");
glutSwapBuffers();
}
void motion(int x, int y)
{
angle=x;///Now: 改變角度
glutPostRedisplay();///Now: 請 重畫畫面
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("QWQ");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
glutMotionFunc(motion);
glutMainLoop();
}










沒有留言:
張貼留言