2019年3月21日 星期四

朱書樑的上課筆記w5

主題:旋轉Rotation
實作:glRotatef()
1.先到http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/將[data] [window] [glut32.dll]下載並解壓縮
2.將 [window] 解壓縮後將[data]中的data檔案以及 [glut32.dll]載入
3.將Transformation.exe打開並使用滑鼠進行操作即可
(若將glRoataef數值改成(X,1,1,0),即可將對稱軸變斜的)









4.打開codeblocks並新增project GULT












代入滑鼠程式碼

5.將原始程式碼刪除並打入新的程式碼

(紅框圈起來的是讓茶壺旋轉的程式碼)









(glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);  這一行是要清除殘影)


6.再加入跟著滑鼠旋轉的程式碼(注意:需把angle+=3刪除掉)
(紅框圈起來的是能讓茶壺跟著滑鼠旋轉的程式碼)









7.


完成程式碼:
#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();
}
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("06160540");
    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutMotionFunc(motion);
    glutMouseFunc(mouse);     
    glutMainLoop();
}



沒有留言:

張貼留言