Week05
(1)複習移動、旋轉(Translate、Rotate)
(2)本週主題:T-R-T 特定軸轉
(3)本週主題:階層性旋轉
(4)本週主題:矩陣(整合)
(5)回家作業
----------------------------------------
TODO:開啟Transformation.exe
把順序改成
glTranslatef()//移動一台旋轉、有縮放的車子
glRotatef()//旋轉一台有縮放的車子
glScalef()//有一台有縮放的車子
glBegin()//有一台車子
口訣:左耳貼左肩,從下往上讀

--------------------------------------------------------------------------------------------------------------------------
TRT
畫茶壺
#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("week05 TRT");
glutDisplayFunc(display);
glutMainLoop();
}
--------------------------------------------------------------------------------------------------------------------------
用茶壺畫手臂關節的樣子
#include <GL/glut.h>
float angle=0;
void motion(int x, int y)
{
angle=x;
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glutSolidTeapot(0.3);
glTranslatef(0.5,0.15,0);
glRotatef(angle,0,0,1);
glTranslatef(0.45,-0.08,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05 TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}

--------------------------------------------------------------------------------------------------------------------------
用茶壺畫一隻有關節的手臂
#include <GL/glut.h>
float angle=0;
void motion(int x, int y)
{
angle=x;
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(0.5,0.15,0);
glRotatef(angle,0,0,1);
glTranslatef(0.45,-0.08,0);
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(0.5,0.15,0);
glRotatef(angle,0,0,1);
glTranslatef(0.45,-0.08,0);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05 TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}

--------------------------------------------------------------------------------------------------------------------------
用茶壺畫兩隻有關節的手臂
#include <GL/glut.h>
float angle=0;
void motion(int x, int y)
{
angle=x;
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glutSolidTeapot(0.3);///放在中間的茶壺
glPushMatrix();///上手臂
glTranslatef(0.5,0.15,0);
glRotatef(angle,0,0,1);
glTranslatef(0.45,-0.08,0);
glutSolidTeapot(0.3);
glPushMatrix();///下手肘
glTranslatef(0.5,0.15,0);
glRotatef(angle,0,0,1);
glTranslatef(0.45,-0.08,0);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glPushMatrix();///上手臂
glTranslatef(-0.5,0.15,0);
glRotatef(angle,0,0,1);
glTranslatef(-0.45,-0.08,0);
glutSolidTeapot(0.3);
glPushMatrix();///下手肘
glTranslatef(-0.5,0.15,0);
glRotatef(angle,0,0,1);
glTranslatef(-0.45,-0.08,0);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05 TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
--------------------------------------------------------------------------------------------------------------------------
用茶壺畫兩隻有關節的手臂
#include <GL/glut.h>
float angle=0;
void motion(int x, int y)
{
angle=x;
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glutSolidTeapot(0.3);///放在中間的茶壺
glPushMatrix();///上手臂
glTranslatef(0.5,0.15,0);
glRotatef(angle,0,0,1);
glTranslatef(0.45,-0.08,0);
glutSolidTeapot(0.3);
glPushMatrix();///下手肘
glTranslatef(0.5,0.15,0);
glRotatef(angle,0,0,1);
glTranslatef(0.45,-0.08,0);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glPushMatrix();///上手臂
glTranslatef(-0.5,0.15,0);
glRotatef(-angle,0,0,1);
glTranslatef(-0.45,-0.08,0);
glutSolidTeapot(0.3);
glPushMatrix();///下手肘
glTranslatef(-0.5,0.15,0);
glRotatef(-angle,0,0,1);
glTranslatef(-0.45,-0.08,0);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05 TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
--------------------------------------------------------------------------------------------------------------------------



沒有留言:
張貼留言