延續上禮拜的步驟
>>開啟transfrom的檔案
練習 glRotatef (角度, X,Y,Z)
開啟glut專案
#include <GL/glut.h>
float angle=0; //初始值設0
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix(); ///備份矩陣
glRotatef(angle, 0,1,0); ///y軸做變化
glutSolidTeapot(0.3);
glPopMatrix(); ///還原矩陣
glutSwapBuffers();
angle+=3; ///角度每一次都轉一點
}
int main(int argc, char**argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("我是郁峰");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
}
#include <GL/glut.h>
float angle=0;
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix(); ///備份矩陣
glRotatef(angle, 0,1,0);
glutSolidTeapot(0.3);
glPopMatrix(); ///還原矩陣
glutSwapBuffers();
///angle+=3;/// 註解掉
}
void motion(int x, int y){
///當你的mosue 去drag做motion動作時
angle=x; display();}
int main(int argc, char**argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("我是郁峰");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
glutMouseFunc(mouse);///Mouse函式
|
|
|
v
#include <stdio.h>
void mouse(int button, int state, int x, int y){
printf("%d %d %d %d\n", button, state, x, y);
int button --> 左鍵0, 中鍵1,右鍵2
int state --> 是否有按下(1,0)
int x --> x軸
int y --> y軸
沒有留言:
張貼留言