2024年3月7日 星期四

mouse滑鼠Week03

 1.Glut開啟專案week03_mouse放上10行程式碼,加上新的程式碼

#include <stdio.h>

void mouse(int button, int state,int x, int y){

    printf("Hello Mouse!\n");

}

glutMouseFunc(mouse);

2.把printf("Hello Mouse!\n");去掉,加上printf("%d %d %d %d\n",button,state,x,y)
button 左鍵=0、中鍵=1、右鍵=2,state按下=0、鬆開=1,(x,y)=座標
3.把
printf("%d %d %d %d\n",button,state,x,y)去掉,加上if(state==GLUT_DOWN)
        printf("glVertex2f((%d-150)/150.0,-(%d-150)/150.0);\n",x,y);
4.到https://jsyeh.org/3dcg10
下載data,win32,windows.zip解壓縮把data丟進windows開啟Transformation.exe


5.
glTranslatef(x,y,z)按住要調整的上下移動
6.新增專案
week03_mouse_glTranslatef,要讓茶壺跟著mouse走,新增程式碼
7.glRotatef(角度,x,y,z)可以用右手比讚來判斷,轉動軸為大拇指,轉動方向為其他手指,y軸轉就比個讚y為轉動軸,-y是倒讚,以此類推
8.
新增專案week03_mouse_glRotatef,拿week03_mouse_glTranslatef的程式碼改
9.
新增專案week03_mouse_translatef_rotatef,拿week03_mouse_glRotatef的程式碼改







沒有留言:

張貼留言