2019年3月14日 星期四

比利安娜工作室-夜狗雞排,W4

電圖Week04 2019/03/14

1.主題:移動

跟上禮拜一樣到 小葉的秘密網站 下載win32,data,glut32.dll
win32→windows.zip 解壓縮成windows資料夾
將glut32.dll拉進windows資料夾
data.zip解壓縮後將裡面的data資料夾拉進windows資料夾
執行Transformation.exe
修改 glTranslatef 的值看保時捷的移動變化

2.示範:glTranslatef(x,y,z)

https://www.transmissionzero.co.uk/software/freeglut-devel/下載MinGw版本的freeglut
依照上次開啟GLUT的步驟開啟新project,然後將程式碼刪除
打出茶壺程式碼
並加入 glTranslatef 

3.主題:滑鼠

創意無限的小葉交了我們怎麼讓茶壺跟著滑鼠走

#include <GL/glut.h>
float x=0, y=0;///滑鼠motion
void display()

{
    glColor3f(0,1,1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清空
    glPushMatrix();///備份矩陣
        glTranslatef((x-150)/150.0,-(y-150)/150.0,0);///滑鼠motion
        glutSolidTeapot(0.3);
    glPopMatrix();///還原矩陣,才不會在下次有舊的殘值
    glutSwapBuffers();
}
void motion(int nowX,int nowY)///滑鼠motion
{
    ///滑鼠motion
    x=nowX; y=nowY;///滑鼠motion
    display();///滑鼠motion 馬上更新
}///滑鼠motion
int main(int argc,char **argv)

{

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);

    glutCreateWindow("Week04");

    glutDisplayFunc(display);
    glutMotionFunc(motion);///滑鼠motion

    glutMainLoop();
}

沒有留言:

張貼留言