(1)到這個網站http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
(2)下載data win32 glut32.dll(按储存)
(3)解壓縮data.zip跟windows.zip
(4)把解壓縮好的檔案丟進windows
glRotatef(旋轉)

讓滑鼠控制茶壺移動
程式碼:
#include <GL/glut.h>
float x=0, y=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef((x-150)/150.0, -(y-150)/150.0, 0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int nowx,int nowy)
{
x=nowx; y=nowy; ///更新x,y
display(); ///再畫display()
}
int main(int argc, char ** argv)
{
glutInit( &argc, argv); ///啟動GLUT
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("06161180");
glutDisplayFunc(display);
glutMotionFunc(motion); ///滑鼠有動作motion時,要叫motion()
glutMainLoop();
}
茶壺可跟著滑鼠左右移動來旋轉
程式碼:
#include <GL/glut.h>
float x=0, y=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ///清畫面
glPushMatrix();
glRotatef(x, 0, 1, 0);
///glTranslatef((x-150)/150.0, -(y-150)/150.0, 0); ///移動
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int nowx,int nowy)
{
x=nowx; y=nowy; ///更新x,y
display(); ///再畫display()
}
int main(int argc, char ** argv)
{
glutInit( &argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("06161180");
glutDisplayFunc(display);
glutMotionFunc(motion); ///負責motion的函式,要叫motion()
glutMainLoop();
}



沒有留言:
張貼留言