-T-R-T 特定軸轉,階層性旋轉,矩陣-
1.到http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
下data win32 glut32.dll win32 放到同一資料夾解壓縮

3.自己寫
(1.)

#include <GL/glut.h>
float angle=0;///旋轉的角度
void motion(int x, int y)///mouse motion拖著移動時,會叫motion()
{
angle=x;///老師用上週較差的方法,直接把mouse座標,變轉動角度
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///備份矩陣(乾淨的)
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(0.5, 0.14, 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)///mouse motion拖著移動時,會叫motion()
{
angle=x;///老師用上週較差的方法,直接把mouse座標,變轉動角度
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///備份矩陣(乾淨的)
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(0.5, 0.14, 0);
glRotatef(angle, 0,0,1);
glTranslatef(0.45, -0.08, 0);
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(0.5, 0.14, 0);
glRotatef(angle, 0,0,1);
glTranslatef(0.45, -0.08, 0);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.5, 0.04, 0);
glRotatef(-angle, 0,0,1);
glTranslatef(-0.45, -0.08, 0);
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(-0.5, 0.14, 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();
}
自轉
2.用別人的程式改

3.自己寫
(1.)

#include <GL/glut.h>
float angle=0;///旋轉的角度
void motion(int x, int y)///mouse motion拖著移動時,會叫motion()
{
angle=x;///老師用上週較差的方法,直接把mouse座標,變轉動角度
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///備份矩陣(乾淨的)
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(0.5, 0.14, 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();
}
(2.)

#include <GL/glut.h>
float angle=0;///旋轉的角度
void motion(int x, int y)///mouse motion拖著移動時,會叫motion()
{
angle=x;///老師用上週較差的方法,直接把mouse座標,變轉動角度
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///備份矩陣(乾淨的)
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(0.5, 0.14, 0);
glRotatef(angle, 0,0,1);
glTranslatef(0.45, -0.08, 0);
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(0.5, 0.14, 0);
glRotatef(angle, 0,0,1);
glTranslatef(0.45, -0.08, 0);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.5, 0.04, 0);
glRotatef(-angle, 0,0,1);
glTranslatef(-0.45, -0.08, 0);
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(-0.5, 0.14, 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();
}


沒有留言:
張貼留言