複習 T R S (mouse motion)
1. 將data.zip, windows.zip, glut32.dll下載至桌面2. 解壓縮,並將data, glut32.dll放進windows
3. 打開transformation.exe
4. 測試x,y,z軸如何旋轉
5. 了解公轉、自轉的差別
按滑鼠右鍵,點選(Swap translate/rotate),交換順序
自轉、公轉差別如下
自轉:原地打轉 公轉:想像車子擺在大盤子的邊緣上轉動
CodeBlocks(TRT)
glPushMatrix();
glRotated(a,0,0,1);
glTranslated(-2.4,1.2,-6);
glutSolidSphere(1,slices,stacks);
glPopMatrix();
將圖形變白色
畫轉動茶壺
#include <GL/glut.h>
float angle=0;///Now: 讓茶壼自動轉動的角度
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///Now:備份矩陣
glRotatef(angle, 0,0,1);///Now:轉動
glutSolidTeapot(0.3);
glPopMatrix();///Now:還原矩陣
glutSwapBuffers();
}
void motion(int x, int y)
{
angle=x;///Now: 改變角度
glutPostRedisplay();///Now: 請 重畫畫面
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Week05 TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);///Now:
glutMainLoop();
}
把茶壺的中心點移到茶壺把手上
#include <GL/glut.h>
float angle=0;///Now: 讓茶壼自動轉動的角度
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///Now:備份矩陣
glRotatef(angle, 0,0,1);///Now:轉動
glTranslatef(0.45,0.10,0);
glutSolidTeapot(0.3);
glPopMatrix();///Now:還原矩陣
glutSwapBuffers();
}
void motion(int x, int y)
{
angle=x;///Now: 改變角度
glutPostRedisplay();///Now: 請 重畫畫面
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Week05 TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);///Now:
glutMainLoop();
}
將紅茶壺當身體,綠茶壺當手臂
#include <GL/glut.h>float angle=0;///Now: 讓茶壼自動轉動的角度
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///Now:備份矩陣
glColor3f(1,0,0);glutSolidTeapot(0.3);///中間的紅色茶壺
glPushMatrix();
glTranslatef(0.4,0.13,0);///(3)掛上紅色茶壺,變成手臂
glRotatef(angle, 0,0,1);///(2)轉動樓下全部
glTranslatef(0.45,-0.10,0);///(1)把茶壺炳,放到世界正中間
glColor3f(0,1,0);glutSolidTeapot(0.3);///綠茶壺
glPushMatrix();
glTranslatef(0.4,0.13,0);///(3)掛上紅色茶壺,變成手臂
glRotatef(angle, 0,0,1);///(2)轉動樓下全部
glTranslatef(0.45,-0.10,0);///(1)把茶壺炳,放到世界正中間
glColor3f(0,1,0);glutSolidTeapot(0.3);///綠茶壺
glPopMatrix();
glPopMatrix();
glPopMatrix();///Now:還原矩陣
glutSwapBuffers();
}
void motion(int x, int y)
{
angle=x;///Now: 改變角度
glutPostRedisplay();///Now: 請 重畫畫面
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Week05 TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);///Now:
glutMainLoop();
}
將兩個連接在一起的綠色茶壺複製到左側
#include <GL/glut.h>
float angle=0;///Now: 讓茶壼自動轉動的角度
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///Now:備份矩陣
glColor3f(1,0,0);glutSolidTeapot(0.3);///中間的紅色茶壺
glPushMatrix();///右手臂
glTranslatef(0.4,0.13,0);///(3)掛上紅色茶壺,變成手臂
glRotatef(angle, 0,0,1);///(2)轉動樓下全部
glTranslatef(0.45,-0.10,0);///(1)把茶壺炳,放到世界正中間
glColor3f(0,1,0);glutSolidTeapot(0.3);///綠茶壺
glPushMatrix();
glTranslatef(0.4,0.13,0);///(3)掛上紅色茶壺,變成手臂
glRotatef(angle, 0,0,1);///(2)轉動樓下全部
glTranslatef(0.45,-0.10,0);///(1)把茶壺炳,放到世界正中間
glColor3f(0,1,0);glutSolidTeapot(0.3);///綠茶壺
glPopMatrix();
glPopMatrix();
glPushMatrix();///右手臂
glTranslatef(-0.4,0.13,0);///(3)掛上紅色茶壺,變成手臂
glRotatef(angle, 0,0,1);///(2)轉動樓下全部
glTranslatef(-0.45,-0.10,0);///(1)把茶壺炳,放到世界正中間
glColor3f(0,1,0);glutSolidTeapot(0.3);///綠茶壺
glPushMatrix();
glTranslatef(-0.4,0.13,0);///(3)掛上紅色茶壺,變成手臂
glRotatef(angle, 0,0,1);///(2)轉動樓下全部
glTranslatef(-0.45,-0.10,0);///(1)把茶壺炳,放到世界正中間
glColor3f(0,1,0);glutSolidTeapot(0.3);///綠茶壺
glPopMatrix();
glPopMatrix();
glPopMatrix();///Now:還原矩陣
glutSwapBuffers();
}
void motion(int x, int y)
{
angle=x;///Now: 改變角度
glutPostRedisplay();///Now: 請 重畫畫面
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Week05 TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);///Now:
glutMainLoop();
}
float angle=0;///Now: 讓茶壼自動轉動的角度
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///Now:備份矩陣
glColor3f(1,0,0);glutSolidTeapot(0.3);///中間的紅色茶壺
glPushMatrix();///右手臂
glTranslatef(0.4,0.13,0);///(3)掛上紅色茶壺,變成手臂
glRotatef(angle, 0,0,1);///(2)轉動樓下全部
glTranslatef(0.45,-0.10,0);///(1)把茶壺炳,放到世界正中間
glColor3f(0,1,0);glutSolidTeapot(0.3);///綠茶壺
glPushMatrix();
glTranslatef(0.4,0.13,0);///(3)掛上紅色茶壺,變成手臂
glRotatef(angle, 0,0,1);///(2)轉動樓下全部
glTranslatef(0.45,-0.10,0);///(1)把茶壺炳,放到世界正中間
glColor3f(0,1,0);glutSolidTeapot(0.3);///綠茶壺
glPopMatrix();
glPopMatrix();
glPushMatrix();///右手臂
glTranslatef(-0.4,0.13,0);///(3)掛上紅色茶壺,變成手臂
glRotatef(angle, 0,0,1);///(2)轉動樓下全部
glTranslatef(-0.45,-0.10,0);///(1)把茶壺炳,放到世界正中間
glColor3f(0,1,0);glutSolidTeapot(0.3);///綠茶壺
glPushMatrix();
glTranslatef(-0.4,0.13,0);///(3)掛上紅色茶壺,變成手臂
glRotatef(angle, 0,0,1);///(2)轉動樓下全部
glTranslatef(-0.45,-0.10,0);///(1)把茶壺炳,放到世界正中間
glColor3f(0,1,0);glutSolidTeapot(0.3);///綠茶壺
glPopMatrix();
glPopMatrix();
glPopMatrix();///Now:還原矩陣
glutSwapBuffers();
}
void motion(int x, int y)
{
angle=x;///Now: 改變角度
glutPostRedisplay();///Now: 請 重畫畫面
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Week05 TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);///Now:
glutMainLoop();
}
將左手臂的angle改為負的
#include <GL/glut.h>
float angle=0;///Now: 讓茶壼自動轉動的角度
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///Now:備份矩陣
glColor3f(1,0,0);glutSolidTeapot(0.3);///中間的紅色茶壺
glPushMatrix();///右手臂
glTranslatef(0.4,0.13,0);///(3)掛上紅色茶壺,變成手臂
glRotatef(angle, 0,0,1);///(2)轉動樓下全部
glTranslatef(0.45,-0.10,0);///(1)把茶壺炳,放到世界正中間
glColor3f(0,1,0);glutSolidTeapot(0.3);///綠茶壺
glPushMatrix();
glTranslatef(0.4,0.13,0);///(3)掛上紅色茶壺,變成手臂
glRotatef(angle, 0,0,1);///(2)轉動樓下全部
glTranslatef(0.45,-0.10,0);///(1)把茶壺炳,放到世界正中間
glColor3f(0,1,0);glutSolidTeapot(0.3);///綠茶壺
glPopMatrix();
glPopMatrix();
glPushMatrix();///右手臂
glTranslatef(-0.4,0.13,0);///(3)掛上紅色茶壺,變成手臂
glRotatef(-angle, 0,0,1);///(2)轉動樓下全部
glTranslatef(-0.45,-0.10,0);///(1)把茶壺炳,放到世界正中間
glColor3f(0,1,0);glutSolidTeapot(0.3);///綠茶壺
glPushMatrix();
glTranslatef(-0.4,0.13,0);///(3)掛上紅色茶壺,變成手臂
glRotatef(-angle, 0,0,1);///(2)轉動樓下全部
glTranslatef(-0.45,-0.10,0);///(1)把茶壺炳,放到世界正中間
glColor3f(0,1,0);glutSolidTeapot(0.3);///綠茶壺
glPopMatrix();
glPopMatrix();
glPopMatrix();///Now:還原矩陣
glutSwapBuffers();
}
void motion(int x, int y)
{
angle=x;///Now: 改變角度
glutPostRedisplay();///Now: 請 重畫畫面
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Week05 TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);///Now:
glutMainLoop();
}









沒有留言:
張貼留言