// start or end interaction void myMouseCB(int button, int state, int x, int y) { Button = button ; if( Button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) { HVect arcball_coords; arcball_coords.x = 2.0*(float)x/(float)Width-1.0; arcball_coords.y = -2.0*(float)y/(float)Height+1.0; Ball_Mouse(Arcball, arcball_coords) ; Ball_Update(Arcball); Ball_BeginDrag(Arcball); } if( Button == GLUT_LEFT_BUTTON && state == GLUT_UP ) { Ball_EndDrag(Arcball); Button = -1 ; } if( Button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN ) { PrevY = y ; } // Tell the system to redraw the window glutPostRedisplay() ; }
// interaction (mouse motion) void MotionCB(int x, int y) { GLMouseButtonInfo mouseButtonInfo; mouseButtonInfo = GlobalResourceManager::use()->getMouseButtonInfo(); if( mouseButtonInfo.button == GLUT_RIGHT_BUTTON ) { HVect arcball_coords; arcball_coords.x = 2.0*(float)x/(float)g_width - 1.0 ; arcball_coords.y = -2.0*(float)y/(float)g_height + 1.0 ; Ball_Mouse(g_arcball,arcball_coords); Ball_Update(g_arcball); glutPostRedisplay() ; } else if( mouseButtonInfo.button == GLUT_MIDDLE_BUTTON ) { if( y - g_prevY > 0 ) g_zoom = g_zoom * 1.03 ; else g_zoom = g_zoom * 0.97 ; g_prevY = y ; glutPostRedisplay() ; } myMotion(x,y) ; }
// interaction (mouse motion) void myMotionCB(int x, int y) { if( Button == GLUT_LEFT_BUTTON ) { HVect arcball_coords; arcball_coords.x = 2.0*(float)x/(float)Width - 1.0 ; arcball_coords.y = -2.0*(float)y/(float)Height + 1.0 ; Ball_Mouse(Arcball,arcball_coords); Ball_Update(Arcball); glutPostRedisplay() ; } else if( Button == GLUT_RIGHT_BUTTON ) { if( y - PrevY > 0 ) Zoom = Zoom * 1.03 ; else Zoom = Zoom * 0.97 ; PrevY = y ; glutPostRedisplay() ; } }
/******************************************************************************* Event handler for mouse motion. *******************************************************************************/ void myMotionCB(int x, int y) { if( g_button == GLUT_LEFT_BUTTON ) { HVect arcball_coords; arcball_coords.x = 2.0*(float)x/(float)g_width - 1.0 ; arcball_coords.y = -2.0*(float)y/(float)g_height + 1.0; Ball_Mouse(g_arcBall,arcball_coords); Ball_Update(g_arcBall); glutPostRedisplay(); } else if( g_button == GLUT_RIGHT_BUTTON ) { if( y - g_previousY > 0 ) g_zoom = g_zoom * 1.03f; else g_zoom = g_zoom * 0.97f; g_previousY = y; glutPostRedisplay(); } }
// start or end interaction void MouseCB(int button, int state, int x, int y) { GlobalResourceManager::use()->setMouseButtonInfo( button, state ); if( button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN ) { HVect arcball_coords; arcball_coords.x = 2.0*(float)x/(float)g_width-1.0; arcball_coords.y = -2.0*(float)y/(float)g_height+1.0; Ball_Mouse(g_arcball, arcball_coords) ; Ball_Update(g_arcball); Ball_BeginDrag(g_arcball); } if( button == GLUT_RIGHT_BUTTON && state == GLUT_UP ) { Ball_EndDrag(g_arcball); // Button = -1 ; GlobalResourceManager::use()->setMouseButtonInfo( -1, state ); } if( button == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN ) { g_prevY = y ; } myMouse(button, state, x,y) ; // Tell the system to redraw the window glutPostRedisplay() ; }
void CMassView::MouseDown(BPoint where) // reacts to mouse clicks { long whichButtons = 1; // used for tracking which buttons are down Window()->CurrentMessage()->FindInt32("buttons", &whichButtons); // find out which buttons are down if (inGLMode && (whichButtons & B_SECONDARY_MOUSE_BUTTON)) // if we are in GL mode, and button 2 is down { float frameWidth = Frame().Width(), frameHeight = Frame().Height(); // find the width & height dragMode = dragBall; // drag the arcball to rotate HVect vNow; // vector type for passing to ball functions vNow.x = (2.0 * where.x - frameWidth)/frameWidth; // set the vector vNow.y = -(2.0 * where.y - frameHeight)/frameHeight; // in both dimensions Ball_Mouse(&ball, vNow); // and pass it to the Ball functions Ball_BeginDrag(&ball); // start dragging while (whichButtons) // loop until drop the mouse { snooze(20 * 1000); // snooze for 20 µs GetMouse(&where, (ulong *)&whichButtons, true); // get the mouse location, &c. vNow.x = (2.0 * where.x - frameWidth)/frameWidth; // set the vector vNow.y = -(2.0 * where.y - frameHeight)/frameHeight; // in both dimensions Ball_Mouse(&ball, vNow); // and pass it to the Ball functions Draw(Frame()); // redraw the entire frame } // end of while (whichButtons) Ball_EndDrag(&ball); // stop dragging } // end of case where dragging else if (acceptClicks) // if we have "accept" switched on { long row, col; // the board coordinates of the click if (!inGLMode) // if it's the regular board { row = where.y / CELL_SIZE; // calculate which row to look in col = where.x / CELL_SIZE; // and which column } // end of normal mode else { GLubyte theColour[4]; // array for retrieving "colour" LockGL(); // lock in preparation for drawing GLfloat mNow[16]; // local matrix for ball routines Ball_Update(&ball); // update the data for the ball Ball_Value(&ball, mNow); // retrieve the ball's position as a matrix glDisable(GL_LIGHTING); // disable lighting glShadeModel(GL_FLAT); // switch to flat shading glMatrixMode(GL_MODELVIEW); // make sure that we are set to the model matrix glClearColor(0.0, 0.0, 0.0, 1.0); // and set the "clear" colour to black glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the window to black glPushMatrix(); // push the GL stack to get a new matrix glLoadIdentity(); // load the identity matrix glTranslatef(0, 0, -600.0); // translate the model matrix glMultMatrixf(mNow); // multiply by this matrix glCallList(torusPickListID); // and call the display list glReadPixels(where.x, Frame().Height() - where.y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, theColour); // read a single pixel at the mouse location glPopMatrix(); // pop the matrix back off the stack glEnable(GL_LIGHTING); // re-enable lighting glShadeModel(GL_SMOOTH); // and smoothness UnlockGL(); // unlock GL Draw(Frame()); // redraw the entire picture row = theColour[1] - 128; col = theColour[0] - 128; // retrieve the row & column // (background is black & returns -128) // printf("%d %d\n", row, col); return; } // end of GL mode code if (row < 0) return; // make sure it is a legal cell else if (row >= theBoard.getHeight()) return; // i.e. not off top or bottom if (col < 0) return; // same with left & right else if (col >= theBoard.getWidth()) return; BMessage *theMessage = new BMessage(CM_MSG_MOVE_CHOSEN); // create a message for it acceptClicks = false; // turn off "accept clicks" theMessage->AddInt32("row", row); theMessage->AddInt32("column", col); // add the coordinates to the message be_app->PostMessage(theMessage); // send the message off delete theMessage; // get rid of the message when done } // end of case where we accept clicks } // end of MouseDown()