#include <GL/glut.h>
float angle=0;///旋轉角度
void motion(int x,int y)///mouse motion拖著移動時,會叫motion()
{
angle=x;///上週比較差的方法,直接把mouse座標,變轉動角度
glutPostRedisplay();///請畫面重畫
}
void display()///畫面要display時呼叫這個涵式
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);///先清畫面
glPushMatrix();///備份矩陣(乾淨的矩陣)
glRotatef(angle,0,0,1);///rotate/trnslate/acale都會把矩陣改變
glTranslatef(0.45,-0.08,0);///移動,讓茶壺的柄放到畫面中心
glutSolidTeapot(0.3);///TODO:試著把茶壺的柄放到畫面中心
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()///畫面要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);///TODO:試著把茶壺的柄放到畫面中心
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()///畫面要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);///TODO:試著把茶壺的柄放到畫面中心
glPushMatrix();
glTranslatef(0.5,0.15,0);///把會旋轉的茶壺柄放到右上角
glRotatef(angle,0,0,1);///把整個畫面中心做旋轉
glTranslatef(0.45,-0.08,0);///移動,讓茶壺的柄放到畫面中心
glutSolidTeapot(0.3);///TODO:試著把茶壺的柄放到畫面中心
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)///mouse motion拖著移動時,會叫motion()
{
angle=x;///上週比較差的方法,直接把mouse座標,變轉動角度
glutPostRedisplay();///請畫面重畫
}
void display()///畫面要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);///TODO:試著把茶壺的柄放到畫面中心
glPushMatrix();///上手
glTranslatef(0.5,0.15,0);///把會旋轉的茶壺柄放到右上角
glRotatef(angle,0,0,1);///把整個畫面中心做旋轉
glTranslatef(0.45,-0.08,0);///移動,讓茶壺的柄放到畫面中心
glutSolidTeapot(0.3);///TODO:試著把茶壺的柄放到畫面中心
glPopMatrix();
glPopMatrix();
glPushMatrix();///上手臂
glTranslatef(-0.5,0.15,0);///把會旋轉的茶壺柄放到右上角
glRotatef(-angle,0,0,1);///把整個畫面中心做旋轉
glTranslatef(-0.45,-0.08,0);///移動,讓茶壺的柄放到畫面中心
glutSolidTeapot(0.3);///TODO:試著把茶壺的柄放到畫面中心
glPushMatrix();///下手
glTranslatef(-0.5,0.15,0);///把會旋轉的茶壺柄放到右上角
glRotatef(-angle,0,0,1);///把整個畫面中心做旋轉
glTranslatef(-0.45,-0.08,0);///移動,讓茶壺的柄放到畫面中心
glutSolidTeapot(0.3);///TODO:試著把茶壺的柄放到畫面中心
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();
}



沒有留言:
張貼留言