2022年3月24日 星期四

week05電腦圖學

 week05

1.做出按下鍵盤按鍵印出滑鼠所在的座標









#include <GL/glut.h>

#include <stdio.h>

void display()

{

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glColor3f(1,1,0);

    glutSolidTeapot(0.3);

    glutSwapBuffers();

}

void keyboard(unsigned char key, int x, int y)

{

    printf("你按下了 %c 在 %d %d 座標\n", key, x, y);

}

int main(int argc, char**argv)

{

    glutInit( &argc, argv);

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("Week05 keyboard");


    glutDisplayFunc(display);

    glutKeyboardFunc(keyboard);

    glutMainLoop();

}

2.點擊移動















                    將滑鼠當前位置設為oldX、Y
多加
void Mouse(int bitton,int state,int mouseX,int mouseY)
{

    oldX= mouseX; oldY= mouseY;

}

3.茶壺放大縮小


















多加

void motion(int mouseX,int mouseY)

{

    if( mouseX-oldX >0) scale*= 1.01;

    if( mouseX-oldX <0) scale*= 0.99;

    ///x+=(mouseX-oldX); y+=(mouseY-oldY);

    oldX =mouseX;     oldY= mouseY;

    display();

}

沒有留言:

張貼留言

VERY BEAUTIFUL, VERY POWERFUL

一.     一樣先安裝且設定好freeglut,OpecCV, 開啟CodeBlocks建立新專案 week11_gundam,                 把 MyGundam.zip下載解壓縮後的data資料夾放到freeglut/bin裡面 把week09_openc...