2022年3月14日 星期一

RH的學習筆記٩(ˊᗜˋ*)و week04

 主題1.1:移動Translate

1.到jsyeh.org/3dcg10 下載win32、data/將兩者解壓縮/並將data丟到windows資料夾裡




2.接著就可以打開Transformation.exe,會出現以下的畫面


glTransltaef 可調整(左右、上下、前後)

glTotatef 可調整角度

glScalef 可調整縮放

3..打開一個新的專案,並輸入基本設定的程式

#include <GL/glut.h>

void display()

{

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);



    glutSwapBuffers();

}

int main(int argc,char**argv)

{

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("自行設定");


    glutDisplayFunc(display);

    glutMainLoop();

}


4.接著輸入紅色茶壺的程式碼

程式碼如下:
#include <GL/glut.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        glColor3f(1,0,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Residual_hope");
    glutDisplayFunc(display);
    glutMainLoop();
}


主題1.2:座標換算

1.自訂一個函式,使其只要輸入該函式、座標位置便可創造一個紅色茶壺

void myTeapot(float x,float y)
{
    glPushMatrix();///push備份矩陣
        glTranslatef(x,y,0);
        glutSolidTeapot(0.3);
    glPopMatrix();///pop還原矩陣
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glColor3f(1,0,0);///red
    myTeapot(+0.5,+0.5);
    myTeapot(-0.5,+0.5);
    myTeapot(+0.5,-0.5);
    myTeapot(-0.5,-0.5);
    glutSwapBuffers();
}


主題2.2:滑鼠事件

1.寫一個滑鼠的外掛程式

void mouse(int button,int state,int x,int y)
{
    printf("%d %d %d %d\n",button,state,x,y);
}
並在下方增加glutMouseFunc() 這個基本設定


左鍵=0  中鍵=1  右鍵=2

2.用滑鼠事件配合創造出來的茶壺做出一個能用滑鼠控制茶壺位置的程式

口訣:減一半、除一半,y倒過來
建立一個mousex=0,mousey=0/扣除中心點,除以中心點/將滑鼠事件函式改成物件隨滑鼠移動


3.創建一個透過點擊小黑框算出該點座標的函式

3.1先設置出一個n,用來計算有幾個點
3.2寫一個迴圈用來搭配陣列 mx[i],my[i]
3.3滑鼠用printf()印出程式碼



沒有留言:

張貼留言