(1)主題:旋轉Rotation
(2)實作:glRotatef()
(3)滑鼠 轉,自動轉
1.進入http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/下載data,win32,glut32.dll

2.把已經解壓縮的data與glut32.dll放到解壓縮的windows裡面

3.打開transformation.exe,更改glRotatef的值選轉

4.打開https://www.transmissionzero.co.uk/software/freeglut-devel/下載
freeglut 3.0.0 MinGW Package
5.將freeglut解壓縮,把裡面的libfreeglut.a複製,更改檔名為libglut32.a
6.打開codeblocks,複製freeglut的位址貼上就可以打開

7.打上程式碼,就可以看到選轉的茶壺

程式碼:
#include <GL/glut.h>
float angel=0;
void display()
{///沒有使用 glCleat()去清畫面,會有殘影...
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///Push備份保護Matrix
glRotatef(angel, 0,1,0);///對Y軸,轉angel度
glutSolidTeapot(0.3);
glPopMatrix();///Pop還原Matrix
glutSwapBuffers();
angel+=3;///每次執行到這行,才加一點點
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05 rotate");
glutDisplayFunc(display);
glutIdleFunc(display);///今天新教的!!!!Idle閒閒沒事,就重畫
glutMainLoop();
}
8.改程式碼,讓茶壺用滑鼠選轉

程式碼:
#include <GL/glut.h>
float angel=0;
void display()
{///沒有使用 glCleat()去清畫面,會有殘影...
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///Push備份保護Matrix
glRotatef(angel, 0,1,0);///今天教的!!! 對Y軸,轉angel度
glutSolidTeapot(0.3);
glPopMatrix();///Pop還原Matrix
glutSwapBuffers();
///angel+=3;///今天教的!!! 每次執行到這行,才加一點點
}
void motion(int x, int y)///現在才在要加新的!!!
{///當你的mouse去drag做motion動作時,
angel=x;///現在要新加的!!!
display();///現在要加新的!!!
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05 rotate");
glutDisplayFunc(display);
glutIdleFunc(display);///今天新教的!!!!Idle閒閒沒事,就重畫
glutMotionFunc(motion);///現在要新加的!!!
glutMainLoop();///如果忘了寫glutMainLoop()或是忘了寫圓括號()就會離開
}
9.點滑鼠可以看到點擊的紀錄

視窗中的第一個數字0是滑鼠的左鍵,1是滑鼠的中鍵,2是滑鼠的右鍵
程式碼:
#include <GL/glut.h>
float angel=0;
void display()
{///沒有使用 glCleat()去清畫面,會有殘影...
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///Push備份保護Matrix
glRotatef(angel, 0,1,0);///今天教的!!! 對Y軸,轉angel度
glutSolidTeapot(0.3);
glPopMatrix();///Pop還原Matrix
glutSwapBuffers();
///angel+=3;///今天教的!!! 每次執行到這行,才加一點點
}
void motion(int x, int y)///現在才在要加新的!!!
{///當你的mouse去drag做motion動作時,
angel=x;///現在要新加的!!!
display();///現在要加新的!!!
}
#include<stdio.h>///現在要新加的!!!
void mouse(int button, int state, int x, int y)///現在要新加的!!!
{///要把大象放到冰箱:(1)mouse按下去(3)mouse放開來
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);///今天新教的!!!!Idle閒閒沒事,就重畫
glutMotionFunc(motion);///現在要新加的!!!
glutMouseFunc(mouse);///現在要新加的!!!
glutMainLoop();///如果忘了寫glutMainLoop()或是忘了寫圓括號()就會離開
}
專研不是說好一組嗎
回覆刪除