2019年3月21日 星期四

Week05_玄的筆記

Week 05上課筆記

到此網址  http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/

下載檔案  (已連結)  --> 並解壓縮到同一個資料夾 
window.zip    
glut32.dll





測試 是否可以開啟檔案  



測試並觀察旋轉方向 


開始CodeBlock並開啟FreeGlut 專案

下載檔案 FreeGLUT  並壓縮 --> 到lib 資料夾 複製libfreeglut.a 並貼上
將檔名改成  libglut32.a


將Freeglut資料夾位址網址並貼上


將程式碼刪掉, 更改為下列
  glRotatef(angle,0,1,0);  /// 對Y軸轉angle度
///////////
#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();  /// 還原
    glutSwapBuffers();
    angle+=3;   /// 每次+3度
}

int main (int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Shu的視窗");
    glutDisplayFunc(display);
    glutIdleFunc(display);  /// Idle 重畫
    glutMainLoop();
}
////////////
Bulid 後呈現畫面  (茶壺繞著Y軸自動旋轉)


 讓茶壺跟著滑鼠轉動 

將程式碼改為下列
//////////////////
#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();  /// 還原
    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); ///glut要搭配GLUT
    glutCreateWindow("Shu的視窗");
    glutDisplayFunc(display);
    glutIdleFunc(display);  /// Idle 重畫
    glutMotionFunc(motion);
    glutMainLoop();  ///如果沒加上這行,跑一次就會離開
}


//////////////////

將滑鼠座標位子顯示出來

///////////////
#include<GL/glut.h>
#include <stdio.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();  /// 還原
    glutSwapBuffers();
    ///angle++;   /// 每次+3度
}

void motion(int x, int y) /// 當滑鼠拖曳時
{
    angle=x;
    display();
}
void mouse(int button,int state,int x, int y)
{
    printf("%d %d %d %d\n",button,state,x,y);  
/// button 為滑鼠按鍵  左鍵會顯示1 ,中鍵為2,右鍵為3,
/// state 為滑鼠的狀態,按下會顯示1,放開會顯示2
/// x 跟y 為當下滑鼠的座標位子
}

int main (int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH); ///glut要搭配GLUT
    glutCreateWindow("Shu的視窗");
    glutDisplayFunc(display);
    glutIdleFunc(display);  /// Idle 重畫
    glutMotionFunc(motion);
    glutMouseFunc(mouse);
    glutMainLoop();  ///如果沒加上這行,跑一次就會離開
}
////////////////////




沒有留言:

張貼留言