主題 : 旋轉Rotation
1.開啟檔案
實作
自動旋轉茶壺
#include <GL/glut.h>float angle=0;
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPopMatrix();
glRotatef(angle,0,1,0); 今天新教的
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
angle+=3;
}
int main(int argc,char**argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05 rotate");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
}
用滑鼠控制茶壺
#include <GL/glut.h>
float angle=0;
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///沒使用會有殘影
glPopMatrix();
glRotatef(angle,0,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
///angle+=3;
}
void motion(int x,int y){
angle=x;
display();
}
int main(int argc,char**argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05 rotate");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
float angle=0;
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///沒使用會有殘影
glPopMatrix();
glRotatef(angle,0,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
///angle+=3;
}
void motion(int x,int y){
angle=x;
display();
}
int main(int argc,char**argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05 rotate");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
滑鼠按下去 彈起來
#include <GL/glut.h>
float angle=0;
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///沒使用會有殘影
glPopMatrix();
glRotatef(angle,0,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
///angle+=3;
}
void motion(int x,int y){
angle=x;
display();
}
#include<stdio.h>
void mouse(int button,int state,int x,int y){
printf("%d %d %d %d\n",button,state,x,y);
}
int main(int argc,char**argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05 rotate");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMotionFunc(motion);
glutMouseFunc(mouse);
glutMainLoop();
}
沒有留言:
張貼留言