主題:移動
範例:glTranslatef(x,y,z)
主題:滑鼠
#include <GL/glut.h>
float x=0,y=0; ///滑鼠motion
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glPushMatrix(); //備份矩陣
glTranslatef( (x-150)/150.0, -(y-150)/150.0, 0); ///滑鼠motion,移動
glutSolidTeapot(0.3);
glPopMatrix(); //還原矩陣,才不會有殘值
glutSwapBuffers();
}
void motion(int nowX,int nowY){ ///滑鼠motion
x=nowX; y=nowY; ///滑鼠motion,座標
display(); ///滑鼠motion,馬上更新
}
int main(int argc,char**argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Week04");
glutDisplayFunc(display);
glutMotionFunc(motion); ///滑鼠motion
glutMainLoop();
}
float x=0,y=0; ///滑鼠motion
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glPushMatrix(); //備份矩陣
glTranslatef( (x-150)/150.0, -(y-150)/150.0, 0); ///滑鼠motion,移動
glutSolidTeapot(0.3);
glPopMatrix(); //還原矩陣,才不會有殘值
glutSwapBuffers();
}
void motion(int nowX,int nowY){ ///滑鼠motion
x=nowX; y=nowY; ///滑鼠motion,座標
display(); ///滑鼠motion,馬上更新
}
int main(int argc,char**argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Week04");
glutDisplayFunc(display);
glutMotionFunc(motion); ///滑鼠motion
glutMainLoop();
}
沒有留言:
張貼留言