OpenGL滑鼠移動方塊

2021-08-22 03:32:15 字數 827 閱讀 3472

思路:用變數設定方塊的座標,然後根據滑鼠的位移更改方塊的變數座標。

注意:方塊的繪圖座標系和世界座標系是重合的,滑鼠所在的座標是以視窗的左上角為原點(0,0)的座標系,視窗的左下角的世界座標係為gluorho2d(left, right, bottom, top)中的(left, bottom)。所以滑鼠的座標(xmouse, ymouse)轉化為世界座標(x, y)為: x = xmouse;   y = top - ymouse.且滑鼠位移的y增量在世界座標系中式減量。

#include #include "graphics.h"

int x1 = 0, y1 = 0, x2 = 100, y2 = 100; //方塊的左下角座標和右上角座標

int x = 0, y = 0; //滑鼠位置

int dx = 0, dy = 0; //滑鼠位移

int b = 0; //判斷滑鼠是否在方塊內

void init()

void test()

int inrect(int xmouse, int ymouse)

void mymouse(int button, int state, int xmouse, int ymouse)

if (button == glut_left_button && state == glut_up) b = 0; //當移動較快時滑鼠會在重新整理間隔移出方塊,所以用down和up來判斷滑鼠在方塊內

}void movemouse(int xmouse, int ymouse)

}int main(int argc, char** argv)

OpenGL 滑鼠互動

1.檢測滑鼠的click glutmousefunc void func int button,int state,int x,int y button glut left button,glut middle button,blut right button state glut down,glu...

滑鼠事件 跟隨滑鼠移動

案例分析 1.滑鼠不斷移動,使用滑鼠移動事件 mousemove 2.在頁面中不斷移動,給document註冊事件 3.要移動距離,而且不佔位置,我們使用絕對定位 效果 跟隨滑鼠的天使 title 6 style 7img 11style 12head 13 body 14 img src pic....

滑鼠移動事件

當滑鼠指標位於元素上方時時,改變元素的背景色 p mouseover function 當滑鼠指標位於元素上方時,會發生 mouseover 事件。該事件大多數時候會與 mouseout 事件一起使用。mouseover 方法觸發 mouseover 事件,或規定當發生 mouseover 事件時執...