(1)小考:T-R-T轉
(2)主題:階層轉動,骨架
(3):鍵盤按鍵
首先先到http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/ 這個網站
下載:windows.zip解壓縮並下載\windows\Light&material.exe
data.zip 解壓縮並下載\windows\data\模型
glut32.dll 下載\windows\glut32.dll
在Google Chrome下載freeglut(window的mingw版)
https://www.transmissionzero.co.uk/software/freeglut-devel/ 並把他解壓縮到桌面
之後再把解壓縮的freeglut資料夾打開來,並找到lib資料夾
再把lib裡面的libfreeglut.a複製成libglut32.a)
老師的網址http://120.125.89.81/
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidTeapot( 0.3 );
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week11 TRT");
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();
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 );///手臂
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 );///上手臂
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++;
}
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("week11 TRT");
glutIdleFunc(display);///Now!!!!
glutDisplayFunc(display);
glutMotionFunc(motion);///Now2!!!
glutMainLoop();
}
#include <GL/glut.h>
float angle1=0, angle2, angle3, angle4;///Now3!!!
int jointID=1;///1,2,3,4///Now3!!!
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(angle1, 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(angle2, 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(-angle3, 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(-angle4, 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!!!
{
if(jointID==1) angle1 = x;///Now2!!!///Now3!!!
if(jointID==2) angle2 = x;///Now2!!!///Now3!!!
if(jointID==3) angle3 = x;///Now2!!!///Now3!!!
if(jointID==4) angle4 = x;///Now2!!!///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();
}
#include <GL/glut.h>
float angle[20];///用陣列,來取代很多個變數///Now4!!
///float angle1=0, angle2, angle3, angle4;///Now3!!!
int jointID=1;///1,2,3,4///Now3!!!
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.28, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidTeapot( 0.2 );///上手臂
glPushMatrix();///右下手臂
glTranslatef(0.2, 0,0 );///(3)往右移動, 掛在身體的右肘
glRotatef(angle[2], 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[3], 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[4], 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[jointID] = x;///Now4!!!!
///if(jointID==1) angle1 = x;///Now2!!!///Now3!!!
///if(jointID==2) angle2 = x;///Now2!!!///Now3!!!
///if(jointID==3) angle3 = x;///Now2!!!///Now3!!!
///if(jointID==4) angle4 = x;///Now2!!!///Now3!!!
display();///Now2!!!
}
void keyboard(unsigned char key, int x, int y)
{///Now3!!!
/// jointID = key - '0';///雖然可以這樣簡化,但下面易看
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();
}
#include <GL/glut.h>
float angle[20];///用陣列,來取代很多個變數///Now4!!
///float angle1=0, angle2, angle3, angle4;///Now3!!!
int jointID=1;///1,2,3,4///Now3!!!
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.28, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidTeapot( 0.2 );///上手臂
glPushMatrix();///右下手臂
glTranslatef(0.2, 0,0 );///(3)往右移動, 掛在身體的右肘
glRotatef(angle[2], 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[3], 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[4], 0,0,1);///(2)旋轉
glTranslatef(-0.28, 0,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidTeapot( 0.2 );///下手臂
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
///angle++;///Now2!!!
}
int oldX, oldY;
void mouse(int button, int state, int x, int y)///Now5!!!!
{///當mouse按下去時,要記下!! 要記得要讓它有作用!!
oldX = x; oldY = y;///Now5!!!!
}
void motion(int x, int y)///Now2!!!
{
angle[jointID] += x -oldX;///Now4!!!!///Now5!!!!
oldX = x;///Now5!!!!
///if(jointID==1) angle1 = x;///Now2!!!///Now3!!!
///if(jointID==2) angle2 = x;///Now2!!!///Now3!!!
///if(jointID==3) angle3 = x;///Now2!!!///Now3!!!
///if(jointID==4) angle4 = x;///Now2!!!///Now3!!!
display();///Now2!!!
}
void keyboard(unsigned char key, int x, int y)
{///Now3!!!
/// jointID = key - '0';///雖然可以這樣簡化,但下面易看
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!!!
glutMouseFunc(mouse);///Now5!!!!
glutKeyboardFunc(keyboard);///Now3!!!
glutMainLoop();
}
#include <GL/glut.h>
float angle[20];///用陣列,來取代很多個變數///Now4!!
///float angle1=0, angle2, angle3, angle4;///Now3!!!
int jointID=1;///1,2,3,4///Now3!!!
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.28, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidTeapot( 0.2 );///上手臂
glPushMatrix();///右下手臂
glTranslatef(0.2, 0,0 );///(3)往右移動, 掛在身體的右肘
glRotatef(angle[2], 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[3], 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[4], 0,0,1);///(2)旋轉
glTranslatef(-0.28, 0,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidTeapot( 0.2 );///下手臂
glPopMatrix();
glPopMatrix();
glPushMatrix();///左邊的大腿
glTranslatef(-0.18, -0.1,0 );///(3)往左移動, 掛在身體的左肩
glRotatef(-angle[3], 0,0,1);///(2)旋轉
glTranslatef(0, -0.2,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidTeapot( 0.2 );///上手臂
glPushMatrix();///左下小腿
glTranslatef(0, -0.1,0 );///(3)往左移動, 掛在身體的左肘
glRotatef(-angle[4], 0,0,1);///(2)旋轉
glTranslatef(0, -0.2,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidTeapot( 0.2 );///下小腿
glPopMatrix();
glPopMatrix();
glPushMatrix();///右邊的大腿
glTranslatef(+0.18, -0.1,0 );///(3)往左移動, 掛在身體的左肩
glRotatef(-angle[3], 0,0,1);///(2)旋轉
glTranslatef(0, -0.2,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidTeapot( 0.2 );///上手臂
glPushMatrix();///左下小腿
glTranslatef(0, -0.1,0 );///(3)往左移動, 掛在身體的左肘
glRotatef(-angle[4], 0,0,1);///(2)旋轉
glTranslatef(0, -0.2,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidTeapot( 0.2 );///下小腿
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
///angle++;///Now2!!!
}
int oldX, oldY;
void mouse(int button, int state, int x, int y)///Now5!!!!
{///當mouse按下去時,要記下!! 要記得要讓它有作用!!
oldX = x; oldY = y;///Now5!!!!
}
void motion(int x, int y)///Now2!!!
{
angle[jointID] += x -oldX;///Now4!!!!///Now5!!!!
oldX = x;///Now5!!!!
///if(jointID==1) angle1 = x;///Now2!!!///Now3!!!
///if(jointID==2) angle2 = x;///Now2!!!///Now3!!!
///if(jointID==3) angle3 = x;///Now2!!!///Now3!!!
///if(jointID==4) angle4 = x;///Now2!!!///Now3!!!
display();///Now2!!!
}
void keyboard(unsigned char key, int x, int y)
{///Now3!!!
/// jointID = key - '0';///雖然可以這樣簡化,但下面易看
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!!!
glutMouseFunc(mouse);///Now5!!!!
glutKeyboardFunc(keyboard);///Now3!!!
glutMainLoop();
}
float angle[20];///用陣列,來取代很多個變數///Now4!!
///float angle1=0, angle2, angle3, angle4;///Now3!!!
int jointID=1;///1,2,3,4///Now3!!!
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.28, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidTeapot( 0.2 );///上手臂
glPushMatrix();///右下手臂
glTranslatef(0.2, 0,0 );///(3)往右移動, 掛在身體的右肘
glRotatef(angle[2], 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[3], 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[4], 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[jointID] = x;///Now4!!!!
///if(jointID==1) angle1 = x;///Now2!!!///Now3!!!
///if(jointID==2) angle2 = x;///Now2!!!///Now3!!!
///if(jointID==3) angle3 = x;///Now2!!!///Now3!!!
///if(jointID==4) angle4 = x;///Now2!!!///Now3!!!
display();///Now2!!!
}
void keyboard(unsigned char key, int x, int y)
{///Now3!!!
/// jointID = key - '0';///雖然可以這樣簡化,但下面易看
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];///用陣列,來取代很多個變數///Now4!!
///float angle1=0, angle2, angle3, angle4;///Now3!!!
int jointID=1;///1,2,3,4///Now3!!!
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.28, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidTeapot( 0.2 );///上手臂
glPushMatrix();///右下手臂
glTranslatef(0.2, 0,0 );///(3)往右移動, 掛在身體的右肘
glRotatef(angle[2], 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[3], 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[4], 0,0,1);///(2)旋轉
glTranslatef(-0.28, 0,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidTeapot( 0.2 );///下手臂
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
///angle++;///Now2!!!
}
int oldX, oldY;
void mouse(int button, int state, int x, int y)///Now5!!!!
{///當mouse按下去時,要記下!! 要記得要讓它有作用!!
oldX = x; oldY = y;///Now5!!!!
}
void motion(int x, int y)///Now2!!!
{
angle[jointID] += x -oldX;///Now4!!!!///Now5!!!!
oldX = x;///Now5!!!!
///if(jointID==1) angle1 = x;///Now2!!!///Now3!!!
///if(jointID==2) angle2 = x;///Now2!!!///Now3!!!
///if(jointID==3) angle3 = x;///Now2!!!///Now3!!!
///if(jointID==4) angle4 = x;///Now2!!!///Now3!!!
display();///Now2!!!
}
void keyboard(unsigned char key, int x, int y)
{///Now3!!!
/// jointID = key - '0';///雖然可以這樣簡化,但下面易看
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!!!
glutMouseFunc(mouse);///Now5!!!!
glutKeyboardFunc(keyboard);///Now3!!!
glutMainLoop();
}
float angle[20];///用陣列,來取代很多個變數///Now4!!
///float angle1=0, angle2, angle3, angle4;///Now3!!!
int jointID=1;///1,2,3,4///Now3!!!
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.28, 0,0);///(1)往右推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidTeapot( 0.2 );///上手臂
glPushMatrix();///右下手臂
glTranslatef(0.2, 0,0 );///(3)往右移動, 掛在身體的右肘
glRotatef(angle[2], 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[3], 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[4], 0,0,1);///(2)旋轉
glTranslatef(-0.28, 0,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidTeapot( 0.2 );///下手臂
glPopMatrix();
glPopMatrix();
glPushMatrix();///左邊的大腿
glTranslatef(-0.18, -0.1,0 );///(3)往左移動, 掛在身體的左肩
glRotatef(-angle[3], 0,0,1);///(2)旋轉
glTranslatef(0, -0.2,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidTeapot( 0.2 );///上手臂
glPushMatrix();///左下小腿
glTranslatef(0, -0.1,0 );///(3)往左移動, 掛在身體的左肘
glRotatef(-angle[4], 0,0,1);///(2)旋轉
glTranslatef(0, -0.2,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidTeapot( 0.2 );///下小腿
glPopMatrix();
glPopMatrix();
glPushMatrix();///右邊的大腿
glTranslatef(+0.18, -0.1,0 );///(3)往左移動, 掛在身體的左肩
glRotatef(-angle[3], 0,0,1);///(2)旋轉
glTranslatef(0, -0.2,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidTeapot( 0.2 );///上手臂
glPushMatrix();///左下小腿
glTranslatef(0, -0.1,0 );///(3)往左移動, 掛在身體的左肘
glRotatef(-angle[4], 0,0,1);///(2)旋轉
glTranslatef(0, -0.2,0);///(1)往左推,把茶壼的柄,放到中心,變 轉動軸
glColor3f(255,0,0);///紅色
glutSolidTeapot( 0.2 );///下小腿
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
///angle++;///Now2!!!
}
int oldX, oldY;
void mouse(int button, int state, int x, int y)///Now5!!!!
{///當mouse按下去時,要記下!! 要記得要讓它有作用!!
oldX = x; oldY = y;///Now5!!!!
}
void motion(int x, int y)///Now2!!!
{
angle[jointID] += x -oldX;///Now4!!!!///Now5!!!!
oldX = x;///Now5!!!!
///if(jointID==1) angle1 = x;///Now2!!!///Now3!!!
///if(jointID==2) angle2 = x;///Now2!!!///Now3!!!
///if(jointID==3) angle3 = x;///Now2!!!///Now3!!!
///if(jointID==4) angle4 = x;///Now2!!!///Now3!!!
display();///Now2!!!
}
void keyboard(unsigned char key, int x, int y)
{///Now3!!!
/// jointID = key - '0';///雖然可以這樣簡化,但下面易看
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!!!
glutMouseFunc(mouse);///Now5!!!!
glutKeyboardFunc(keyboard);///Now3!!!
glutMainLoop();
}
沒有留言:
張貼留言