data 和win32解壓縮後,把data檔案和glut32.dll拉進win32資料夾裡面
點開檔案中的Transformation,調整rotatef了解每個軸,右鍵能改變物件
開啟之前flut檔案,更改這六行程式碼便能用滑鼠讓圖形旋轉
用滑鼠讓茶壺旋轉
#include <GL/glut.h>
float myAngle=0;///todo宣告我的變數
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清畫面
glPushMatrix();
glRotated(myAngle,0,0,1);///todo:對z軸做旋轉
glutSolidTeapot();
glPopMartix();
glutSwaoBuffers();
}
void motion(int x,int y)
{
myAngle = x;///todo 角度等下要拿來用
display();///todo每次做動作,就重畫畫面
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week 04");
glutMotionFunc(motion);///加motion函式
glutDisplayFunc(display);
glutMainLoop();
}
#include <GL/glut.h>
float myAngle=0;///todo宣告我的變數
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清畫面
glPushMatrix();
glRotated(myAngle,0,0,1);///todo:對z軸做旋轉
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int oldX=0;///宣告變數
void mouse(int button,int state,int x,int y)
{
if(state==GLUT_DOWN)oldX = x;///按下去要記在哪裡
}
void motion(int x,int y)
{
myAngle += (x-oldX);///加了多少度
oldX = x;
display();///todo每次做動作,就重畫畫面
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week 04");
glutMotionFunc(motion);///加motion函式
glutMouseFunc(mouse);
glutDisplayFunc(display);
glutMainLoop();
}






沒有留言:
張貼留言