2014-12-03 169 views
0

只要按住鼠標右鍵,我想放大對象。現在的問題是每次我想放大時都必須點擊它。有沒有辦法修改我的代碼,以便在按住按鈕的同時縮放它,而不是點擊它?GLUT鼠標按鈕向下

void mouse(int button, int state, int x, int y) 
{ 
    // Save the left button state 
    if (button == GLUT_LEFT_BUTTON) 
    { 
     leftMouseButtonDown = (state == GLUT_DOWN); 
     zMovement += 0.1f; 
    } 

    else if (button == GLUT_RIGHT_BUTTON) 
    { 
     leftMouseButtonDown = (state == GLUT_DOWN); 
     zMovement -= 0.1f; 
    } 

    // Save the mouse position 
    mouseXPos = x; 
    mouseYPos = y; 
} 

回答

1

你的函數的狀態變量告訴你什麼類型的鼠標按鈕的事件發生了:它可以是GLUT_DOWN或GLUT_UP。

瞭解了這一點,只要狀態設置爲true(這必須在每個幀的某個位置完成),就可以將此狀態存儲在鼠標功能外的額外變量中並進行縮放。該代碼可能看起來像下面這樣:

void mouse(int button, int state, int x, int y) 
{ 
    // Save the left button state 
    if (button == GLUT_LEFT_BUTTON) 
    { 
     leftMouseButtonDown = (state == GLUT_DOWN); 
    } 

    else if (button == GLUT_RIGHT_BUTTON) 
    { 
     // \/ right MouseButton 
     rightMouseButtonDown = (state == GLUT_DOWN); 
    } 

    // Save the mouse position 
    mouseXPos = x; 
    mouseYPos = y; 
} 

void callThisInEveryFrame() 
{ 
    if (leftMouseButtonDown) 
     zMovement += 0.1f; 
    if (rightMouseButtonDown) 
     zMovement -= 0.1f; 
} 
+0

阿其如此明顯,當你拼出來一樣,(感謝變量提醒過:P)這工作太好了,謝謝 – user2757842 2014-12-03 16:08:00