Week12
step01-1
step01-1Transformation.exe 看它的變化
1. jsyeh.org/3dcg10 下載 windows.zip data.zip
2. windows.zip => 下載\windows\Transformation.exe
3. data.zip => 下載\windows\data\模型
4. 重點在: 有T移動、有R轉動, 按右鍵 Swap交換 T R
5. glTranslatef( 0.9 , 0.0 , 0.0 ); 移動
6. glRotatef( 角度, 0, 1, 0); 旋轉
step02-1
1. 把 glTranslatef()那一行,點它,變紅色,便可以移動左邊的東西
2. 把一個 glTranslatef()放在 Rotatef()的下面、手臂的上面
3. 另一個 glTranslatef()放在 Rotatef()的上面
經過下面的程式碼, 請想像成把手臂砍下來, 把軸心放在世界轉盤的中心。這時候, 再把整個世界轉動, 便可以看到很變態的、長在肚臍的手臂在轉動。
glPushMatrix();
myDrawObject(0);
glRotatef(angle, 0, 0, 1);
glTranslatef(-0.3, -0.19, 0);
myDrawObject(1);
glPopMatrix();
step02-2
glPushMatrix();
glTranslatef(-0.5, -0.9, 0); //(3)最上面的T,把整個東西掛在對的位置
glRotatef(-45, 0,0,1); //(2)轉動某個角度
glTranslatef(-0.8, 0.9, 0); //(1)用最下面的T, 把旋轉中心放到正中心
drawHand();
glPopMatrix();
step02-3
File-New-Project, GLUT專案, week12_TRT
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
///glTranslatef(0, 0, 0);
glRotatef( angle, 0, 0, 1);
///glTransaltef(0, 0, 0);
glutSolidTeapot( 0.2 );
glPopMatrix();
glutSwapBuffers();
angle++;
}
int main( int argc, char** argv )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_DOUBLE|GLUT_DEPTH );
glutCreateWindow("week12 TRT");
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}
```
step03-1
#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 );
glPushMatrix();
glTranslatef(0.2, 0, 0);
glRotatef( angle, 0, 0, 1);
glTranslatef(0.2, 0, 0);
glColor3f(1,0,0);
glutSolidTeapot( 0.2 );
glPopMatrix();
glutSwapBuffers();
angle++;
}
int main( int argc, char** argv )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_DOUBLE|GLUT_DEPTH );
glutCreateWindow("week12 TRT");
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}
```
step03-2
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,1);
glutSolidTeapot( 0.3 );
glPushMatrix();
glTranslatef(0.2, 0, 0);
glRotatef( angle, 0, 0, 1);
glTranslatef(0.2, 0, 0);
glColor3f(1,0,0);
glutSolidTeapot( 0.2 );
glPushMatrix();
glTranslatef(0.2, 0, 0);
glRotatef( angle, 0, 0, 1);
glTranslatef(0.2, 0, 0);
glColor3f(1,0,0);
glutSolidTeapot( 0.2 );
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
angle++;
}
step03-3
step03-3改一下正負號, 可以做出左手邊的手臂、手肘哦
glPushMatrix();
glTranslatef(0.2, 0, 0);
glRotatef( angle, 0, 0, 1);
glTranslatef(0.2, 0, 0);
glColor3f(1,0,0);
glutSolidTeapot( 0.2 );
glPushMatrix();
glTranslatef(0.2, 0, 0);
glRotatef( angle, 0, 0, 1);
glTranslatef(0.2, 0, 0);
glColor3f(1,0,0);
glutSolidTeapot( 0.2 );
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.2, 0, 0);
glRotatef( -angle, 0, 0, 1);
glTranslatef(-0.2, 0, 0);
glColor3f(1,0,0);
glutSolidTeapot( 0.2 );
glPushMatrix();
glTranslatef(-0.2, 0, 0);
glRotatef( -angle, 0, 0, 1);
glTranslatef(-0.2, 0, 0);
glColor3f(1,0,0);
glutSolidTeapot( 0.2 );
glPopMatrix();
glPopMatrix();
沒有留言:
張貼留言