主題:階層,轉動,骨架
茶壺來當作身體與手臂
#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 );///手臂
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 );
glRotatef(angle, 0,0,1);
glTranslatef(-0.28, 0,0);
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.2, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(0,255,0);///綠色
glutSolidCube( 0.3 );///上手臂
glPushMatrix();///右下手臂
glTranslatef(0.1, 0,0 );///(3)往右移動, 掛在身體的右肘
glRotatef(angle, 0,0,1);///(2)旋轉
glTranslatef(0.2, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidCube( 0.3 );///上手臂
glPopMatrix();
glPopMatrix();
glPushMatrix();///左邊的手臂
glTranslatef(-0.2, 0,0 );///(3)往左移動, 掛在身體的左肩
glRotatef(-angle, 0,0,1);///(2)旋轉
glTranslatef(-0.2, 0,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(0,0,255);///藍色
glutSolidCube( 0.3 );///上手臂
glPushMatrix();///左下手臂
glTranslatef(-0.1, 0,0 );///(3)往左移動, 掛在身體的左肘
glRotatef(-angle, 0,0,1);///(2)旋轉
glTranslatef(-0.2, 0,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidCube( 0.3 );///上手臂
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
///angle++;
}
void motion (int x, int y)
{
angle= x; ///now2!!
display(); /// now2!!
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week11 TRT");
glutIdleFunc(display);///Now!!!!
glutDisplayFunc(display);
glutMotionFunc(motion);///now2!!!
glutMainLoop();
}
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.2, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(0,255,0);///綠色
glutSolidCube( 0.3 );///上手臂
glPushMatrix();///右下手臂
glTranslatef(0.1, 0,0 );///(3)往右移動, 掛在身體的右肘
glRotatef(angle, 0,0,1);///(2)旋轉
glTranslatef(0.2, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidCube( 0.3 );///上手臂
glPopMatrix();
glPopMatrix();
glPushMatrix();///左邊的手臂
glTranslatef(-0.2, 0,0 );///(3)往左移動, 掛在身體的左肩
glRotatef(-angle, 0,0,1);///(2)旋轉
glTranslatef(-0.2, 0,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(0,0,255);///藍色
glutSolidCube( 0.3 );///上手臂
glPushMatrix();///左下手臂
glTranslatef(-0.1, 0,0 );///(3)往左移動, 掛在身體的左肘
glRotatef(-angle, 0,0,1);///(2)旋轉
glTranslatef(-0.2, 0,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidCube( 0.3 );///上手臂
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
///angle++;
}
void motion (int x, int y)
{
angle= x; ///now2!!
display(); /// now2!!
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week11 TRT");
glutIdleFunc(display);///Now!!!!
glutDisplayFunc(display);
glutMotionFunc(motion);///now2!!!
glutMainLoop();
}
利用鍵盤控制
#include <GL/glut.h>
float angle[20]; ///now3
int jointID=1; ///now3!!! ///1,2,3,4
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[1], 0,0,1);///(2)旋轉
glTranslatef(0.2, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(0,255,0);///綠色
glutSolidCube( 0.25 );///上手臂
glPushMatrix();///右下手臂
glTranslatef(0.05, 0,0 );///(3)往右移動, 掛在身體的右肘
glRotatef(angle[2], 0,0,1);///(2)旋轉
glTranslatef(0.1, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glRotatef(90,0,0.5,0);
glutSolidCone(0.1,0.5,30,30);///下手臂
glPopMatrix();
glPopMatrix();
glPushMatrix();///左邊的手臂
glTranslatef(-0.2, 0,0 );///(3)往左移動, 掛在身體的左肩
glRotatef(-angle[3], 0,0,1);///(2)旋轉
glTranslatef(-0.2, 0,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(0,0,255);///藍色
glutSolidCube( 0.25 );///上手臂
glPushMatrix();///左下手臂
glTranslatef(-0.05, 0,0 );///(3)往左移動, 掛在身體的左肘
glRotatef(-angle[4], 0,0,1);///(2)旋轉
glTranslatef(-0.1, 0,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glRotatef(-90,0,0.5,0);
glutSolidCone(0.1,0.5,30,30);///下手臂
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
///angle++;
}
void motion (int x, int y)///now2!!!
{
angle[jointID] = x; ///now3!!!
display(); /// now2!!
}
void keyboard(unsigned char key,int x, int y)///now3!!!
{
if(key=='1') jointID=1; ///NOW3!!!
if(key=='2') jointID=2; ///NOW3!!!
if(key=='3') jointID=3; ///NOW3!!!
if(key=='4') jointID=4; ///NOW3!!!
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week11 TRT");
glutIdleFunc(display);///Now!!!!
glutDisplayFunc(display);
glutMotionFunc(motion);///now2!!!
glutKeyboardFunc(keyboard);///NOW3!!!
glutMainLoop();
}
float angle[20]; ///now3
int jointID=1; ///now3!!! ///1,2,3,4
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[1], 0,0,1);///(2)旋轉
glTranslatef(0.2, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(0,255,0);///綠色
glutSolidCube( 0.25 );///上手臂
glPushMatrix();///右下手臂
glTranslatef(0.05, 0,0 );///(3)往右移動, 掛在身體的右肘
glRotatef(angle[2], 0,0,1);///(2)旋轉
glTranslatef(0.1, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glRotatef(90,0,0.5,0);
glutSolidCone(0.1,0.5,30,30);///下手臂
glPopMatrix();
glPopMatrix();
glPushMatrix();///左邊的手臂
glTranslatef(-0.2, 0,0 );///(3)往左移動, 掛在身體的左肩
glRotatef(-angle[3], 0,0,1);///(2)旋轉
glTranslatef(-0.2, 0,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(0,0,255);///藍色
glutSolidCube( 0.25 );///上手臂
glPushMatrix();///左下手臂
glTranslatef(-0.05, 0,0 );///(3)往左移動, 掛在身體的左肘
glRotatef(-angle[4], 0,0,1);///(2)旋轉
glTranslatef(-0.1, 0,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glRotatef(-90,0,0.5,0);
glutSolidCone(0.1,0.5,30,30);///下手臂
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
///angle++;
}
void motion (int x, int y)///now2!!!
{
angle[jointID] = x; ///now3!!!
display(); /// now2!!
}
void keyboard(unsigned char key,int x, int y)///now3!!!
{
if(key=='1') jointID=1; ///NOW3!!!
if(key=='2') jointID=2; ///NOW3!!!
if(key=='3') jointID=3; ///NOW3!!!
if(key=='4') jointID=4; ///NOW3!!!
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week11 TRT");
glutIdleFunc(display);///Now!!!!
glutDisplayFunc(display);
glutMotionFunc(motion);///now2!!!
glutKeyboardFunc(keyboard);///NOW3!!!
glutMainLoop();
}
沒有留言:
張貼留言