2019年3月21日 星期四

老灰電腦圖學 WEEK05 旋轉rotation

http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
下載 data win32 glut32.dll
解壓縮後 data放入 glut32.dll放入

右手安培定則來知道空間概念

https://www.transmissionzero.co.uk/software/freeglut-devel/
一樣要下載 後解壓所 複製改名字 上週都有做過不要忘記


glRotatef() 程式碼來旋轉
今天教將物體旋轉 點滑鼠移動 可以旋轉物體
#include <GL/glut.h>
float angle=0;
void display()
{
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 glPushMatrix();
 glRotatef(angle, 0,1,0);/// 今天教的  對Y軸 轉angle角度
 glutSolidTeapot(0.3);
 glPopMatrix();  ///pop還原matrix
 glutSwapBuffers();
 angle+=3; ///每次執行到這行 加一點點
}
void motion(int x,int y){
angle=x;
display();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week05 rotate");
    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutIdleFunc(display); ///idle閒閒沒事就重畫
    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);/// 今天教的  對Y軸 轉angle角度
 glutSolidTeapot(0.3);
 glPopMatrix();  ///pop還原matrix
 glutSwapBuffers();
 ///angle+=3; ///每次執行到這行 加一點點
}
void motion(int x,int y)
{
angle=x;
display();
}
#include <stdio.h>
void mouse (int button,int state,int x,int y)
{
    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);
    glutMotionFunc(motion); ///idle閒閒沒事就重畫
    glutMouseFunc(mouse);
    glutMainLoop();
}



































沒有留言:

張貼留言