1.小考:TRT轉動
2.主題:階層轉動,骨架
3.主題:鍵盤按鍵
1隻手臂
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(255,255,255);
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(0.5,0,0);
glRotatef(angle,0,0,1);
glTranslatef(0.28, 0,0);
glColor3f(255,0,0);
glutSolidTeapot(0.2); 手臂
glPopMatrix();
glutSwapBuffers();
angle++;
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week11 TRT 06161215");
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}
2隻手臂
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(255,255,255);///白色
glutSolidTeapot( 0.3 );///身體
glPushMatrix();///右邊的手臂
glTranslatef(0.2, 0,0 );///(3)往右移動, 掛在身體的右肩
glRotatef(angle, 0,0,1);///(2)旋轉
glTranslatef(0.28, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidTeapot( 0.2 );///上手臂
glPushMatrix();///右下手臂
glTranslatef(0.2, 0,0 );///(3)往右移動, 掛在身體的右肘
glRotatef(angle, 0,0,1);///(2)旋轉
glTranslatef(0.28, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidTeapot( 0.2 );///上手臂
glPopMatrix();
glPopMatrix();
glPushMatrix();///左邊的手臂
glTranslatef(-0.2, 0,0 );///(3)往左移動, 掛在身體的左肩
glRotatef(angle, 0,0,1);///(2)旋轉
glTranslatef(-0.28, 0,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidTeapot( 0.2 );///上手臂
glPushMatrix();///左下手臂
glTranslatef(-0.2, 0,0 );///(3)往左移動, 掛在身體的左肘
glRotatef(angle, 0,0,1);///(2)旋轉
glTranslatef(-0.28, 0,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidTeapot( 0.2 );///上手臂
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
angle++;
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week11 TRT");
glutIdleFunc(display);///Now!!!!
glutDisplayFunc(display);
glutMainLoop();
}
滑鼠控制手臂移動
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(255,255,255); ///白色
glutSolidTeapot( 0.3 ); ///身體
///右邊的手臂
glPushMatrix();
glTranslatef(0.2,0,0); ///(3)往右移動,掛在身邊的右肩
glRotatef(angle,0,0,1);///(2)旋轉
glTranslatef(0.28,0,0);///(1)往右推,把茶壺的柄, 放到中心, 變轉動軸
glColor3f(255,0,0); ///紅色
glutSolidTeapot( 0.2 ); ///上手臂
glPushMatrix(); ///下手臂
glTranslatef(0.2,0,0); ///(3)往右移動,掛在身邊的右肩
glRotatef(angle,0,0,1);///(2)旋轉
glTranslatef(0.28,0,0);///(1)往右推,把茶壺的柄, 放到中心, 變轉動軸
glColor3f(255,0,0); ///紅色
glutSolidTeapot( 0.2 ); ///下手臂
glPopMatrix();
glPopMatrix();
///左邊的手臂
glPushMatrix();
glTranslatef(-0.2,0,0); ///(3)往左移動,掛在身邊的右肩
glRotatef(-angle,0,0,1);///(2)旋轉
glTranslatef(-0.28,0,0);///(1)往左推,把茶壺的柄, 放到中心, 變轉動軸
glColor3f(255,0,0); ///紅色
glutSolidTeapot( 0.2 ); ///上手臂
glPushMatrix(); ///左下手臂
glTranslatef(-0.2,0,0); ///(3)往左移動,掛在身邊的右肩
glRotatef(-angle,0,0,1);///(2)旋轉
glTranslatef(-0.28,0,0);///(1)往左推,把茶壺的柄, 放到中心, 變轉動軸
glColor3f(255,0,0); ///紅色
glutSolidTeapot( 0.2 ); ///下手臂
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
///angle++; ///NOW2
}
void motion(int x, int y) ///NOW2
{
angle=x; ///NOW2
display(); ///NOW2
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("06160912");
glutIdleFunc(display);
glutDisplayFunc(display);
glutMotionFunc(motion); ///NOW2
glutMainLoop();
}
鍵盤按鍵
沒有留言:
張貼留言