void gameDialog::handleMouse(int button, int action) { int x, y; glfwGetMousePos(&x, &y); if (fShowInventory) { // Override the usual mouse handling bool close = gInventory.HandleMouseClick(button, action, x, y); if (close) { fShowInventory = false; gMsgWindow.SetAlternatePosition(0,0,false); } return; } else if (fShowMainDialog && !fHideDialog) { if (action == GLFW_RELEASE) { fShowMainDialog = dialog::DispatchClick(); } return; } // printf("Mouse function: button %d, state %d, at (%d,%d)\n", button, action, x, y); if (button == GLFW_MOUSE_BUTTON_RIGHT) { if (action == GLFW_PRESS) { xStartTurn = x; yStartTurn = y; angleHorStartTurn = _angleHor; angleVertStartTurn = _angleVert; sTurning = true; } else { sTurning = false; } } else if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS && gMode.Get() == GameMode::GAME) { ClickOnObject(x, y); } else if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS && gMode.Get() == GameMode::TELEPORT) { int x, y; glfwGetMousePos(&x, &y); const ChunkCoord *cc = TeleportClick(fHealthBar, _angleHor, renderViewAngle, x, y, true); if (cc != 0) { // printf("TP to chunk %d,%d,%d\n", cc->x, cc->y, cc->z); unsigned char b[6]; b[0] = 6; b[1] = 0; b[2] = CMD_TELEPORT; b[3] = cc->x & 0xFF; b[4] = cc->y & 0xFF; b[5] = cc->z & 0xFF; SendMsg(b, sizeof b); // this->RequestEffect(EFFECT_ZOOM1); // TODO: Doesn't look good. } } }
void mouseButtonEventHandle(int iMouseID,int iMouseState) { if (iMouseID == GLFW_MOUSE_BUTTON_LEFT) { CCEGLView* pEGLView = CCEGLView::sharedOpenGLView(); //get current mouse pos int x,y; glfwGetMousePos(&x, &y); DPoint oPoint((float)x,(float)y); /* if (!CCRect::CCRectContainsPoint(s_pMainWindow->m_rcViewPort,oPoint)) { CCLOG("not in the viewport"); return; } */ oPoint.x /= pEGLView->m_fFrameZoomFactor; oPoint.y /= pEGLView->m_fFrameZoomFactor; int id = 0; if (iMouseState == GLFW_PRESS) { pEGLView->handleTouchesBegin(1, &id, &oPoint.x, &oPoint.y); } else if (iMouseState == GLFW_RELEASE) { pEGLView->handleTouchesEnd(1, &id, &oPoint.x, &oPoint.y); } } }
void mouseButtonEventHandle(int iMouseID,int iMouseState) { if (iMouseID == GLFW_MOUSE_BUTTON_LEFT) { //get current mouse pos int x,y; glfwGetMousePos(&x, &y); CCPoint oPoint((float)x,(float)y); if (!CCRect::CCRectContainsPoint(s_pMainWindow->m_rcViewPort,oPoint)) { CCLOG("not in the viewport"); return; } s_pMainWindow->m_pTouch->SetTouchInfo((float)(oPoint.x - s_pMainWindow->m_rcViewPort.origin.x) / s_pMainWindow->m_fScreenScaleFactor, (float)(oPoint.y - s_pMainWindow->m_rcViewPort.origin.y) / s_pMainWindow->m_fScreenScaleFactor); s_pMainWindow->m_pSet->addObject(s_pMainWindow->m_pTouch); s_pMainWindow->m_mousePoint = oPoint; if (iMouseState == GLFW_PRESS) { s_pMainWindow->m_pDelegate->touchesBegan(s_pMainWindow->m_pSet,NULL); } else if (iMouseState == GLFW_RELEASE) { s_pMainWindow->m_pDelegate->touchesEnded(s_pMainWindow->m_pSet,NULL); } } }
void modifyCamera(float dt) { int x,y; glfwGetMousePos(&x, &y); vec3 camrot = cam->getOrientation(); camrot.x -= (float)(y-HEIGHT/2) * MOUSE_SPEED * dt; camrot.y -= (float)(x-WIDTH/2) * MOUSE_SPEED * dt; if(camrot.x > 90.0f) camrot.x = 90.0f; if(camrot.x < -90.0f) camrot.x = -90.0f; if(camrot.y > 360.0f) camrot.y -= 360.0f; if(camrot.y < -360.0f) camrot.y += 360.0f; cam->setOrientation(camrot); glfwSetMousePos(WIDTH/2, HEIGHT/2); vec3 movevec; if(glfwGetKey('W')) movevec.z -= MOVE_SPEED; if(glfwGetKey('A')) movevec.x -= MOVE_SPEED; if(glfwGetKey('S')) movevec.z += MOVE_SPEED; if(glfwGetKey('D')) movevec.x += MOVE_SPEED; cam->move(movevec * dt); }
void D2() { int X,Y; glfwGetMousePos(&X,&Y); float x=(2.0f*X/window_width)-1; float y=(-2.0f*Y/window_height)+1; square.x+=((-square.x +x)/600); square.y+=((-square.y +y)/600); glBegin(GL_QUADS); { glColor4f(1,0,0,0.1); glVertex2f(x, y); glColor4f(0,0,1,0.5); float f=1.0f; glVertex2f(f+x, y); glVertex2f(f+x, y+f); glVertex2f(x, y+f); } glEnd(); plate.Render(); square.Render(); }
void PlayerEntity::Update(float interpolationParam, NewtonWorld* world) { glm::vec4 position(prevPosition + (curPosition - prevPosition)*interpolationParam ); Camera* cam=PlayerEntity::camera; cam->setPosition(position.x,position.y,position.z+eyeHeight); static int mousex, mousey, lastmousex, lastmousey; bool followMouse=PlayerEntity::followMouse; lastmousex = mousex; lastmousey = mousey; glfwGetMousePos( &mousex, &mousey ); if(followMouse) { cam->dir.z += (lastmousex - mousex) * 0.2f; cam->dir.x += (lastmousey - mousey) * 0.2f; if ( cam->dir.x > 180.0f ) cam->dir.x = 180.0f; if ( cam->dir.x < 0.0f ) cam->dir.x = 0.0f; if ( cam->dir.z > 360.0f ) cam->dir.z -= 360.0f; if ( cam->dir.z < -360.0f ) cam->dir.z += 360.0f; } }
void processMouseClick(int button, int action) { int x = 0; int y = 0; // only process on mouse click down. if (action == GLFW_RELEASE) { return; } // we need to scale down the (x, y) coordinats to match the size of // the internal board data structure. (void)glfwGetMousePos(&x, &y); x = x / (int)scaleFactor; y = y / (int)scaleFactor; boolean currentState = getCell(board, x, y); boolean newState = currentState ? false : true; (void)setCell(board, x, y, newState); //#ifdef _DEBUG_ printf("Button %d, with action %d on ", button, action); printf("(%d, %d)\n", x, y); printf("currentState: %d, setting newState: %d\n", currentState, newState); (void)fflush(NULL); //#endif return; }
void Slider::update() { int newMouseX, newMouseY; glfwGetMousePos( &newMouseX, &newMouseY ); float relativeMouseX = convertXToRelative( newMouseX ); float relativeMouseY = convertYToRelative( newMouseY ); // Check if mouse press is on button if( !glfwGetMouseButton(0) ) { buttonPressed = false; } else if( ( relativeMouseX - buttonPosition.X ) * ( relativeMouseX - buttonPosition.X ) + (relativeMouseY - buttonPosition.Y ) * ( relativeMouseY - buttonPosition.Y ) < slider_consts::buttonSize * slider_consts::buttonSize || buttonPressed ){ buttonPressed = true; buttonPosition.X = relativeMouseX; float minPos = sliderPosition.X - slider_consts::sliderLength / 2; float maxPos = sliderPosition.X + slider_consts::sliderLength / 2; if( buttonPosition.X < minPos ) buttonPosition.X = minPos; if( buttonPosition.X > maxPos ) buttonPosition.X = maxPos; currentPercentage = ( buttonPosition.X - minPos ) / ( maxPos - minPos ); setUniform( shaderProperty, min + currentPercentage * (max - min) ); } }
void InputManager::SetMouseCursorVisibility(bool Visible) { static int MouseCursorDesktopPositionX, MouseCursorDesktopPositionY; // Hide Mouse Cursor if (!Visible && m_MouseCursorVisible) { glfwPollEvents(); m_MouseIgnorePositionAlways = true; glfwGetMousePos(&MouseCursorDesktopPositionX, &MouseCursorDesktopPositionY); glfwDisable(GLFW_MOUSE_CURSOR); m_MouseIgnorePositionOnce = true; m_MouseIgnorePositionAlways = false; m_MouseCursorVisible = false; } // Show Mouse Cursor else if (Visible && !m_MouseCursorVisible) { m_MouseIgnorePositionAlways = true; glfwEnable(GLFW_MOUSE_CURSOR); glfwSetMousePos(MouseCursorDesktopPositionX, MouseCursorDesktopPositionY); m_MouseIgnorePositionOnce = true; m_MouseIgnorePositionAlways = false; m_MouseCursorVisible = true; // Create a mouse position event //ProcessMousePos(m_MousePositionX, m_MousePositionY); } }
void inpUpdate() { int x, y; memcpy(OldKeys, Keys, KeyCount); if(MouseEnabled) { glfwGetMousePos(&x, &y); MouseDX = x - MouseX; MouseDY = y - MouseY; MouseX = x; MouseY = y; } else { MouseDX = 0; MouseDY = 0; } //glfwSetMousePos(200, 200); OldMousebutton[0] = Mousebutton[0]; OldMousebutton[1] = Mousebutton[1]; OldMousebutton[2] = Mousebutton[2]; Mousebutton[0] = glfwGetMouseButton(GLFW_MOUSE_BUTTON_LEFT); Mousebutton[1] = glfwGetMouseButton(GLFW_MOUSE_BUTTON_RIGHT); Mousebutton[2] = glfwGetMouseButton(GLFW_MOUSE_BUTTON_MIDDLE); }
void ClassicMode::ProcessMouseButton(int MouseButton, int Action) {//printf(" mb\n"); static int nPrevMouseButtonsDown = 0; if (GLFW_PRESS == Action) { nMouseButtonsDown |= (1 << MouseButton); if (!nPrevMouseButtonsDown && nMouseButtonsDown) { glfwGetMousePos(&nDesktopCursorX, &nDesktopCursorY); bCursorArmed = true; } } else { nMouseButtonsDown &= ~(1 << MouseButton); if (nPrevMouseButtonsDown && !nMouseButtonsDown) { if (bCursorArmed) { bCursorArmed = false; bSelectPerformed = true; } else { glfwEnable(GLFW_MOUSE_CURSOR);// printf("mouse visible\n"); glfwSetMousePos(nDesktopCursorX, nDesktopCursorY); } } } nPrevMouseButtonsDown = nMouseButtonsDown; }
void TheMaze2::handleMouseInput(double time_delta) { int xPos, yPos; glfwGetMousePos(&xPos, &yPos); player_.xFacing_ -= player_.look_speed_ * time_delta * float(window_width_/2 - xPos); player_.yFacing_ += player_.look_speed_ * time_delta * float(window_height_/2 - yPos); glfwSetMousePos(window_width_/2, window_height_/2); }
void obp_trackball_rot () { int xpos, ypos; glfwGetMousePos(&xpos, &ypos); glfwSetMousePos(obp_window_width /2, obp_window_height /2); verticalAngle += mouseRotateSpeed * float(obp_window_width /2 - xpos); horizontalAngle += mouseRotateSpeed * float(obp_window_height /2 - ypos); if (horizontalAngle >= 89.99) horizontalAngle = 89.99; if (horizontalAngle <= -89.99) horizontalAngle = -89.99; float initial_distance = 10; float distance = initial_distance - 1.0f * glfwGetMouseWheel(); float camX = distance * -sinf(verticalAngle * (PI / 180)) * cosf((horizontalAngle) * (PI / 180)); float camY = distance * -sinf((horizontalAngle) * (PI / 180)); float camZ = -distance * cosf((verticalAngle) * (PI / 180)) * cosf((horizontalAngle) * (PI / 180)); ProjectionMatrix = glm::perspective(initial_fov, float(obp_window_width) / float(obp_window_height), 0.1f, 100.0f); ViewMatrix = glm::lookAt( glm::vec3(camX, camY, camZ), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f)); }
void update_mouse(Point **mp, int *mouse_held) { // mp is a pointer to a Point pointer so that I can change // the pointer to save the Point grabbed by the mouse // between function calls...pointer! Point *mouse_point = *mp; if(!glfwGetMouseButton(GLFW_MOUSE_BUTTON_LEFT)) { *mouse_held = 0; *mp = malloc(sizeof(Point)); } else { int x, y; glfwGetMousePos(&x, &y); GLint viewport[4]; GLdouble modelview[16]; GLdouble projection[16]; GLfloat winX, winY; GLdouble posX, posY, posZ; glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); glGetDoublev( GL_PROJECTION_MATRIX, projection ); glGetIntegerv( GL_VIEWPORT, viewport ); winX = (float)x; winY = (float)(viewport[3] - y); gluUnProject( winX, winY, 0.99, modelview, projection, viewport, &posX, &posY, &posZ); //find nearest point to mouse click if(!(*mouse_held)) { free(*mp); *mouse_held = 1; Point *nearest; float d = 100000; for(int i = 0; i < NUM_POINTS; i++) { if(!point_array[i]->anchor) { float diff_x = point_array[i]->x - posX; float diff_y = point_array[i]->y - posY; float diff_z = point_array[i]->z - posZ; float dist = sqrt(diff_x*diff_x + diff_y*diff_y + diff_z*diff_z); if(dist < d) { d = dist; nearest = point_array[i]; } } } *mp = nearest; mouse_point = nearest; } //drag point around if(*mouse_held) { mouse_point->x = posX; mouse_point->y = posY; mouse_point->z = posZ; } } }
Point sys_mousePos() { Point out; glfwGetMousePos(&out.x, &out.y); out = pointAddPoint(out, pointInverse(_drawRect.a)); out.x /= _pixel_scale; out.y /= _pixel_scale; return out; }
SGenum SG_EXPORT sgmCoreMouseGetPosition(void* mouse, SGint* x, SGint* y) { if(mouse == NULL) return SG_OK; // SG_INVALID_VALUE glfwGetMousePos(x, y); return SG_OK; }
//----------------------------------------------------------------------------- ivec2 SYS_MousePos() { int x, y; ivec2 pos; glfwGetMousePos(&x, &y); pos.x = x; pos.y = SYS_HEIGHT - y; return pos; }
void Input::Update() { int x, y; glfwGetMousePos(&x, &y); y = screenHeight - y; mouse.SetPos(x, y); for (int i = 0; i < 512; i++) keyboard.Set(i, glfwGetKey(i) == GLFW_PRESS); mouse.Set(GLFW_MOUSE_BUTTON_1, glfwGetMouseButton(GLFW_MOUSE_BUTTON_1) == GLFW_PRESS); mouse.Set(GLFW_MOUSE_BUTTON_2, glfwGetMouseButton(GLFW_MOUSE_BUTTON_2) == GLFW_PRESS); mouse.Set(GLFW_MOUSE_BUTTON_3, glfwGetMouseButton(GLFW_MOUSE_BUTTON_3) == GLFW_PRESS); }
void GLFWCALL mouse_pos_event(int x, int y) { VSX_UNUSED(x); VSX_UNUSED(y); set_modifiers(); glfwGetMousePos(&last_x, &last_y); if (mouse_state) mouse_pos_type = 1; else mouse_pos_type = 2; }
void processMouseEvents(float factor) { int x; int y; int cx = scene->context->w / 2; int cy = scene->context->h / 2; float sensitivity = 0.05f; float dx, dy; glfwGetMousePos(&x, &y); dx = sensitivity * ((float) cx - (float) x); dy = sensitivity * ((float) cy - (float) y); if (dx == 0.0f && dy == 0.0f) { return; } if (glfwGetKey(GLFW_KEY_LSHIFT) == GLFW_PRESS || glfwGetKey(GLFW_KEY_RSHIFT) == GLFW_PRESS) { float slide = SLIDE_STEP * factor; dx *= slide; dy *= slide; slideCamera(scene->camera, -dx, dy, 0.0f); } else { float rotate = ROTATE_STEP * factor; dx *= rotate; dy *= rotate; rotateCamera(scene->camera, dx, 0.0f, 0.0f); rotateCamera(scene->camera, 0.0f, -dy, 0.0f); } if (scene->world != NULL) { setupCamera(scene->world->sp, scene->camera); } if (scene->water != NULL) { setupCameraAlter(scene->water->modifySP, scene->camera); setupCamera(scene->water->drawSP, scene->camera); } glfwSetMousePos(cx, cy); }
void MouseButtonCallback( int button, int action ) { int x, y; glfwGetMousePos( &x, &y ); if( action == GLFW_PRESS ) GUIManager::instance().injectInput( MessagePointerButtonDown( button, (float)x, (float)y ) ); else if( action == GLFW_RELEASE ) GUIManager::instance().injectInput( MessagePointerButtonUp( button, (float)x, (float)y ) ); }
void GLFWApp::HandleInput() { isRunning = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED); int x = 0; int y = 0; glfwGetMousePos(&x, &y); deltaX = x - midWidth; deltaY = y - midHeight; glfwSetMousePos(midWidth, midHeight); }
void computeMatricesFromInputs() { // glfwGetTime is called only once (first time this function is called) static double lastTime = glfwGetTime(); // compute time difference between current and last frame double curTime = glfwGetTime(); float deltaTime = float(curTime - lastTime); // get and reset mouse pos int xpos, ypos; glfwGetMousePos(&xpos, &ypos); glfwSetMousePos(1024/2, 768/2); float mouseDeltaX = float(1024/2 - xpos); float mouseDeltaY = float( 768/2 - ypos); if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_MIDDLE) == GLFW_PRESS) { // pan position cam.move_up(mouseSpeed * mouseDeltaY); cam.move_right(-mouseSpeed * mouseDeltaX); } else { cam.rotate_up(mouseSpeed * mouseDeltaY); cam.rotate_right(mouseSpeed * mouseDeltaX); } // move forward if ((glfwGetKey(GLFW_KEY_UP) == GLFW_PRESS) || (glfwGetKey('W') == GLFW_PRESS)) { cam.move_forward(deltaTime * speed); } // move backward if ((glfwGetKey(GLFW_KEY_DOWN) == GLFW_PRESS) || (glfwGetKey('S') == GLFW_PRESS)) { cam.move_forward(-1 * deltaTime * speed); } // strafe right if ((glfwGetKey(GLFW_KEY_RIGHT) == GLFW_PRESS) || (glfwGetKey('D') == GLFW_PRESS)) { cam.move_right(deltaTime * speed); } // strafe left if ((glfwGetKey(GLFW_KEY_LEFT) == GLFW_PRESS) || (glfwGetKey('A') == GLFW_PRESS)) { cam.move_right(-1 * deltaTime * speed); } // strafe up if (glfwGetKey('I') == GLFW_PRESS) { cam.move_up(deltaTime * speed); } // strafe down if (glfwGetKey('K') == GLFW_PRESS) { cam.move_up(-1 * deltaTime * speed); } lastTime = curTime; }
int sgInit(int argc, char *argv[], sgEvents *event, int res_x, int res_y, bool fullscreen) { sgMain::eventhandler = event; bool running = true; glfwInit(); glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 8); if(!glfwOpenWindow( res_x, res_y, 0, 0, 0, 0, 24, 8, fullscreen?GLFW_FULLSCREEN:GLFW_WINDOW)) { glfwTerminate(); return 0; } printf("Multisampling samples: %i\n", glfwGetWindowParam(GLFW_FSAA_SAMPLES)); glEnable(GL_MULTISAMPLE_ARB); sgRenderer::backingWidth = res_x; sgRenderer::backingHeight = res_y; glfwSetWindowTitle("iSDGE"); glfwSetMousePos(res_x*0.5, res_y*0.5); GLenum err = glewInit(); if (GLEW_OK != err) { /* Problem: glewInit failed, something is seriously wrong. */ printf("Error: %s\n", glewGetErrorString(err)); return -1; } printf("Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); //Initialize the renderer sgMain *sgmain = new sgMain(2); int mouse_x, mouse_y; while(running) { glfwGetMousePos(&mouse_x, &mouse_y); glfwSetMousePos(res_x*0.5, res_y*0.5); sgMouse::currdir = sgVector2(mouse_x-res_x*0.5, mouse_y-res_y*0.5); sgMouse::currpos = sgVector2(mouse_x, mouse_y); sgmain->drawView(); glfwSwapBuffers(); // exit if ESC was pressed or window was closed running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED); } delete sgmain; glfwTerminate(); return 0; }
void run_loop( std::unique_ptr<Example>& example, GLuint width, GLuint height ) { GLuint mouse_x = width / 2; GLuint mouse_y = height / 2; os::steady_clock os_clock; ExampleClock clock; while(true) { clock.Update(os_clock.seconds()); if(!example->Continue(clock)) break; example->Render(clock); glfwSwapBuffers(); int new_x, new_y; glfwGetWindowSize(&new_x, &new_y); if((int(width) != new_x) || (int(height) != new_y)) { if(new_x <= 0) new_x = 1; if(new_y <= 0) new_y = 1; width = GLuint(new_x); height = GLuint(new_y); example->Reshape(width, height); } glfwGetMousePos(&new_x, &new_y); if((int(mouse_x) != new_x) || (int(mouse_y) != new_y)) { if(new_x <= 0) new_x = 1; if(new_y <= 0) new_y = 1; mouse_x = GLuint(new_x); mouse_y = GLuint(new_y); example->MouseMove( mouse_x, height- mouse_y, width, height ); } if(glfwGetKey(GLFW_KEY_ESC)) { glfwCloseWindow(); break; } if(!glfwGetWindowParam(GLFW_OPENED)) break; } }
//----------------------------------------------------------------------------// void GLFWCALL CEGuiGLFWSharedBase::glfwMousePosCallback(int x, int y) { if (!d_mouseDisableCalled) { // if cursor didn't leave the window nothing changes d_sampleApp->injectMousePosition(static_cast<float>(x), static_cast<float>(y)); } else { // if the cursor left the window, we need to use the saved position // because glfw beams the cursor to the middle of the window if // the cursor is disabled d_sampleApp->injectMousePosition(static_cast<float>(d_oldMousePosX), static_cast<float>(d_oldMousePosY)); glfwSetMousePos(d_oldMousePosX, d_oldMousePosY); d_mouseDisableCalled = false; } #ifndef DEBUG if (x < 0 || y < 0 || x > d_newWindowWidth || y > d_newWindowHeight) { // show cursor glfwEnable(GLFW_MOUSE_CURSOR); // move the cursor to the position where it left the window glfwSetMousePos(x, y); // "note down" that the cursor left the window d_mouseLeftWindow = true; } else { if (d_mouseLeftWindow) { // get cursor position to restore afterwards glfwGetMousePos(&d_oldMousePosX, &d_oldMousePosY); // we need to inject the previous cursor position because // glfw moves the cursor to the centre of the render // window if it gets disabled. therefore notify the // next MousePosCallback invocation of the "mouse disabled" event. d_mouseDisableCalled = true; // disable cursor glfwDisable(GLFW_MOUSE_CURSOR); // "note down" that the cursor is back in the render window d_mouseLeftWindow = false; } } #endif }
// update the scene based on the time elapsed since last update static void Update(float secondsElapsed) { //rotate the first instance in `gInstances` const GLfloat degreesPerSecond = 180.0f; gDegreesRotated += secondsElapsed * degreesPerSecond; while(gDegreesRotated > 360.0f) gDegreesRotated -= 360.0f; gInstances.front().transform = glm::rotate(glm::mat4(), gDegreesRotated, glm::vec3(0,1,0)); //move position of camera based on WASD keys, and XZ keys for up and down const float moveSpeed = 4.0; //units per second if(glfwGetKey('S')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.forward()); } else if(glfwGetKey('W')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.forward()); } if(glfwGetKey('A')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.right()); } else if(glfwGetKey('D')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.right()); } if(glfwGetKey('Z')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * -glm::vec3(0,1,0)); } else if(glfwGetKey('X')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * glm::vec3(0,1,0)); } //move light if(glfwGetKey('1')) gLight.position = gCamera.position(); // change light color if(glfwGetKey('2')) gLight.intensities = glm::vec3(1,0,0); //red else if(glfwGetKey('3')) gLight.intensities = glm::vec3(0,1,0); //green else if(glfwGetKey('4')) gLight.intensities = glm::vec3(1,1,1); //white //rotate camera based on mouse movement const float mouseSensitivity = 0.1f; int mouseX, mouseY; glfwGetMousePos(&mouseX, &mouseY); gCamera.offsetOrientation(mouseSensitivity * mouseY, mouseSensitivity * mouseX); glfwSetMousePos(0, 0); //reset the mouse, so it doesn't go out of the window //increase or decrease field of view based on mouse wheel const float zoomSensitivity = -0.2f; float fieldOfView = gCamera.fieldOfView() + zoomSensitivity * (float)glfwGetMouseWheel(); if(fieldOfView < 5.0f) fieldOfView = 5.0f; if(fieldOfView > 130.0f) fieldOfView = 130.0f; gCamera.setFieldOfView(fieldOfView); glfwSetMouseWheel(0); }
void ClassicMode::ProcessMouseWheel(int MouseWheel) { static int nPrevMouseWheel = MouseWheel; int nMouseWheelMoved = MouseWheel - nPrevMouseWheel; nPrevMouseWheel = MouseWheel; if (0 != MyScene.GetSelectedObjectId()) { bool bShiftPressed = (glfwGetKey(GLFW_KEY_LSHIFT) == GLFW_PRESS || glfwGetKey(GLFW_KEY_RSHIFT) == GLFW_PRESS); // Find the new mouse ray Wm5::Vector3d oMouseDirection; { Wm5::Vector3d oNearPoint, oFarPoint; float fDepth; int MousePosX, MousePosY; glfwGetMousePos(&MousePosX, &MousePosY); MousePosY = nViewportHeight - 1 - MousePosY; glReadPixels(MousePosX, MousePosY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &fDepth); //GLfloat winX, winY, winZ; GLdouble posX, posY, posZ; GLdouble modelMatrix[16], projMatrix[16]; GLint viewport[4]; glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); glGetDoublev(GL_PROJECTION_MATRIX, projMatrix); glGetIntegerv(GL_VIEWPORT, viewport); fDepth = 0; gluUnProject(MousePosX, MousePosY, fDepth, modelMatrix, projMatrix, viewport, &posX, &posY, &posZ); oNearPoint.X() = posX; oNearPoint.Y() = posY; oNearPoint.Z() = posZ; fDepth = 1; gluUnProject(MousePosX, MousePosY, fDepth, modelMatrix, projMatrix, viewport, &posX, &posY, &posZ); oFarPoint.X() = posX; oFarPoint.Y() = posY; oFarPoint.Z() = posZ; oMouseDirection = oFarPoint - oNearPoint; oMouseDirection.Normalize(); } //Wm5::Line3d oMouseRay(oCamera, oMouseDirection); Wm5::Vector3d oDisplacement; if (0 == nTESTMode2) oDisplacement = ZoomSelectedModel(nMouseWheelMoved); else oDisplacement = ZoomSelectedModel(nMouseWheelMoved, oMouseDirection); MyScene.m_Objects.at(MyScene.GetSelectedObjectId() - 1)->MoveBy(oDisplacement); if (bShiftPressed) { camera.x += oDisplacement.X(); camera.y += oDisplacement.Y(); camera.z += oDisplacement.Z(); } } }
void glfw_win_t::_mouse_btn_cb(int btn, int action) { //rotation if (btn == GLFW_MOUSE_BUTTON_LEFT){ if(action == GLFW_PRESS) { int x,y; glfwGetMousePos(&x, &y); _trackball->beginTracking(Point2f(x,y)); } else if (action == GLFW_RELEASE) { _old_rot_matrix = _rot_matrix * _old_rot_matrix; _rot_matrix = Matrix4d::identityMatrix(); } } //panning else if (btn == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS) { int x,y; glfwGetMousePos(&x, &y); _trackball->beginPanning(Point2f(x + _cam_x, y + _cam_y)); } }
void mouse() { if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_LEFT)) { int mx, my; glfwGetMousePos(&mx, &my); mouse_func(0, 1, mx, my); } else { mouse_func(0, 0, mx, my); } if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_RIGHT)) { int mx, my; glfwGetMousePos(&mx, &my); mouse_func(2, 1, mx, my); //motion_func(mx, my); } else { mouse_func(2, 0, mx, my); } }