電腦圖學小考:T-R-T
轉動主題:階層轉動、骨架
主題:鍵盤按鍵
下載freeglut 以及老師給的程式碼在120.125.89.81
#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();
}
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 );
glRotatef(angle, 0,0,1);
glTranslatef(0.28, 0,0);
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 06160565");
glutIdleFunc(display);///Now!!!!
glutDisplayFunc(display);
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.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();
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++;
}
void motion(int x,int y)
{
angle=x;
display();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week11 06160565");
glutIdleFunc(display);///Now!!!!
glutDisplayFunc(display);
glutMotionFunc(motion);
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 );
glRotatef(angle, 0,0,1);
glTranslatef(0.28, 0,0);
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++;
}
void motion(int x,int y)
{
angle=x;
display();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week11 06160565");
glutIdleFunc(display);///Now!!!!
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
沒有留言:
張貼留言