step 0 :下載模型
0.0 jsyeh.org/3dcg10 下載 data.zip , windows.zip
0.1 data.zip =>下載/windows/data
windows.zip => 下載/windows
source.zip=>下載/windows
執行windows/Transformation.exe
step 1 : 示範轉動方式
1.1 在右邊轉動的藍色車子(自轉)
```
glTranslaterf(0.9 , 0.0 , 0.0);///移動 在右邊
glRotatef( 角度 , 0 , 1 ,0 );///旋轉
畫一台藍色車子
```
1.2 繞著中間轉彎的車子 (公轉)
```
glRotatef( 角度 , 0 , 1 ,0 );///旋轉
glTranslaterf(0.9 , 0.0 , 0.0);///移動 在右邊
畫一台藍色車子
```
step 2 : 用另一個程式理解(TRT)
2.1 120.125.80.50/GL 有程式 (內含其中、練習)
2.2右下角點ToDraw , 左邊可以畫圖
2.3 Ctrl+R Reload可以清空圖
2.4 畫身體 叫myDrawObject(0)
2.5 畫手臂 叫myDrawObject(1)
2.6 拉動程式碼可以改變位置
2.7 按右上角 angle= 在按空白鍵 會自動變成動畫
step 3 : 新增新的功能
3.1 改成身體不動 手臂正常揮手
```
glPushMatrix();
myDrawObject(0);///畫身體
glRotatef( angle , 0 , 0 , 1) ;///轉下面整個東西
glTranslatef( -0.3 , -0.19 , 0 );///往左下方移動(軸心放中心)
myDrawObject(1);///手臂(右上方)
plPopMatrix();
```
3.2 上面 T 擺好 ,手掛到身體右上角
```
myDrawObject(0);///畫身體
glPushMatrix();
glTranslatef(0.29 , 0.31 , 0 ) ///往右上方移動
glRotatef( angle , 0 , 0 , 1) ;///轉下面整個東西
glTranslatef( -0.3 , -0.19 , 0 );///往左下方移動(軸心放中心)
myDrawObject(1);///手臂(右上方)
plPopMatrix();
```
step 4 : 實作
4.1 開新專案 命名為week12_TRT
4.2 貼上程式碼
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0 , 0, 0);
glRotatef( angle , 0 , 0 ,1 );
glTranslatef( 0 , 0 , 0);
glutSolidTeapot(0.2);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char **argv)
{
glutInit (&argc , argv);
glutInitDisplayMode( GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week12 TRT");
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}
5.1 可自己件模型 或是上網查 ( 需有身體、手臂等等)
5.2 開新專案 命名為week12_TRT_TRT
5.3 範例 (身體+右手)
```
引用模型:
#include "glm.h"
GLMmodel * pmodel = NULL;
GLMmodel * pmodel = NULL;///上手臂
GLMmodel * pmodel = NULL;///下手軸
#include <GL/glut.h>
float angle=0 ;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,1);
glutSolidTeapot(0.3);///身體 ///glmDraw( pmodel ,...)
glPushMatrix();
glTranslatef(0.2 , 0, 0);
glRotatef( angle , 0 , 0 ,1 );
glTranslatef( 0.2 , 0 , 0);
glColor3f(1,0,0);
glutSolidTeapot(0.2);///手臂 /// glmDraw(arm , ...)
glPushMatrix();
glTranslatef(0.2 , 0, 0);
glRotatef( angle , 0 , 0 ,1 );
glTranslatef( 0.2 , 0 , 0);
glColor3f(1,0,0);
glutSolidTeapot(0.2);///手肘 /// glmDraw(hand , ...)
glPushMatrix();
glPopMatrix();
glutSwapBuffers();
angle+=0.1;
}
int main(int argc, char **argv)
{
glutInit (&argc , argv);
glutInitDisplayMode( GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week12 TRT");
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}
5.3 範例 (身體+右手+左手)
位置、角度改成負的(因為左右手對稱)
```
引用模型:
#include "glm.h"
GLMmodel * pmodel = NULL;
GLMmodel * pmodel = NULL;///上手臂
GLMmodel * pmodel = NULL;///下手軸
#include <GL/glut.h>
float angle=0 ;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,1);
glutSolidTeapot(0.3);///身體 ///glmDraw( pmodel ,...)
glPushMatrix();///右邊的手臂手肘
glTranslatef(0.2 , 0, 0);
glRotatef( angle , 0 , 0 ,1 );
glTranslatef( 0.2 , 0 , 0);
glColor3f(1,0,0);
glutSolidTeapot(0.2);///手臂 /// glmDraw(arm , ...)
glPushMatrix();
glTranslatef(0.2 , 0, 0);
glRotatef( angle , 0 , 0 ,1 );
glTranslatef( 0.2 , 0 , 0);
glColor3f(1,0,0);
glutSolidTeapot(0.2);///手肘 /// glmDraw(hand , ...)
glPushMatrix();
glPopMatrix();
glPushMatrix();///左邊的手臂手肘
glTranslatef(-0.2 , 0, 0);
glRotatef( -angle , 0 , 0 ,1 );
glTranslatef( -0.2 , 0 , 0);
glColor3f(1,0,0);
glutSolidTeapot(0.2);///手臂 /// glmDraw(arm , ...)
glPushMatrix();
glTranslatef(-0.2 , 0, 0);
glRotatef( -angle , 0 , 0 ,1 );
glTranslatef( -0.2 , 0 , 0);
glColor3f(1,0,0);
glutSolidTeapot(0.2);///手肘 /// glmDraw(hand , ...)
glPushMatrix();
glPopMatrix();
glutSwapBuffers();
angle+=0.1;
}
int main(int argc, char **argv)
{
glutInit (&argc , argv);
glutInitDisplayMode( GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week12_TRT_TRT");
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}
}
沒有留言:
張貼留言