bool InputManager::handleEvent(QEvent* event) { if (event->type() != QEvent::KeyPress && event->type() != QEvent::KeyRelease) return false; QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event); Qt::Key key = static_cast<Qt::Key>(keyEvent->key()); const char* keyCategory = NULL; // NOTE: We can potentially get key presses on the device before // com.palm.keys comes up, and these won't be broadcast to subscribers // However, we assume that we wouldn't want them to receive a collection // of queued up key presses // Each subset of keys must not overlap in the current handling if (isAudioKey(key)) { keyCategory = CATEGORY_AUDIO; } else if (isMediaKey(key)) { keyCategory = CATEGORY_MEDIA; } else if (isSwitch(key)) { keyCategory = CATEGORY_SWITCHES; } else if (isHeadsetKey(key)) { if (!(key == KEYS::Key_Headset || key == KEYS::Key_HeadsetMic)) { // state machine time -- headset button headsetStateMachine(keyEvent); } keyCategory = CATEGORY_HEADSET; } else if (isBluetoothKey(key)) { handleBluetoothKey(keyEvent); return true; } else { // Not a key that we care about, so we indicate we didn't handle it return false; } // first event that comes in sets the sticky state, no matter // whether it is a real action that a user did or a generated // "InitialState" static int switchInitCount = 0; if (setKeyState(key, event->type())) { if (NULL == m_publicService && (++switchInitCount == HostBase::instance()->getNumberOfSwitches() )) { startService(); } } // We don't post the "InitialState" key because it is internally // generated in order to get initial state of a key if (!(keyEvent->nativeModifiers() & SysMgrNativeKeyboardModifier_InitialState)) { const char* keyString = NULL; keyToString(key, &keyString); (void)postKeyToSubscribers(keyEvent, keyCategory, keyString, NULL); } return true; }
void QSFMLCanvas::keyReleaseEvent(QKeyEvent* event) { QWidget::keyReleaseEvent(event); setKeyState(event->key(), 0); }
void QSFMLCanvas::keyPressEvent(QKeyEvent* event) { QWidget::keyPressEvent(event); setKeyState(event->key(), 1); }
void update(float _deltaTime) { if (m_mouseDown) { int32_t deltaX = m_mouseNow.m_mx - m_mouseLast.m_mx; int32_t deltaY = m_mouseNow.m_my - m_mouseLast.m_my; m_horizontalAngle += m_mouseSpeed * float(deltaX); m_verticalAngle -= m_mouseSpeed * float(deltaY); m_mouseLast.m_mx = m_mouseNow.m_mx; m_mouseLast.m_my = m_mouseNow.m_my; } float direction[3] = { cosf(m_verticalAngle) * sinf(m_horizontalAngle), sinf(m_verticalAngle), cosf(m_verticalAngle) * cosf(m_horizontalAngle), }; float right[3] = { sinf(m_horizontalAngle - float(M_PI)/2.0f), 0, cosf(m_horizontalAngle - float(M_PI)/2.0f), }; if (m_keys & CAMERA_KEY_UP) { // m_eye += direction * _deltaTime * m_moveSpeed float tmpRhs[3]; float tmpPos[3]; memcpy(tmpPos, m_eye, sizeof(float)*3); vec3Mul(tmpRhs, direction, _deltaTime * m_moveSpeed); vec3Add(m_eye, tmpPos, tmpRhs); setKeyState(CAMERA_KEY_UP, false); } if (m_keys & CAMERA_KEY_DOWN) { // m_eye -= direction * _deltaTime * m_moveSpeed float tmpRhs[3]; float tmpPos[3]; memcpy(tmpPos, m_eye, sizeof(float)*3); vec3Mul(tmpRhs, direction, _deltaTime * m_moveSpeed); vec3Sub(m_eye, tmpPos, tmpRhs); setKeyState(CAMERA_KEY_DOWN, false); } if (m_keys & CAMERA_KEY_LEFT) { // m_eye += right * _deltaTime * m_moveSpeed float tmpRhs[3]; float tmpPos[3]; memcpy(tmpPos, m_eye, sizeof(float)*3); vec3Mul(tmpRhs, right, _deltaTime * m_moveSpeed); vec3Add(m_eye, tmpPos, tmpRhs); setKeyState(CAMERA_KEY_LEFT, false); } if (m_keys & CAMERA_KEY_RIGHT) { // m_eye -= right * _deltaTime * m_moveSpeed float tmpRhs[3]; float tmpPos[3]; memcpy(tmpPos, m_eye, sizeof(float)*3); vec3Mul(tmpRhs, right, _deltaTime * m_moveSpeed); vec3Sub(m_eye, tmpPos, tmpRhs); setKeyState(CAMERA_KEY_RIGHT, false); } vec3Add(m_at, m_eye, direction); vec3Cross(m_up, right, direction); }
void update(float _deltaTime, const entry::MouseState& _mouseState) { if (!m_mouseDown) { m_mouseLast.m_mx = _mouseState.m_mx; m_mouseLast.m_my = _mouseState.m_my; } m_mouseDown = !!_mouseState.m_buttons[entry::MouseButton::Right]; if (m_mouseDown) { m_mouseNow.m_mx = _mouseState.m_mx; m_mouseNow.m_my = _mouseState.m_my; } if (m_mouseDown) { int32_t deltaX = m_mouseNow.m_mx - m_mouseLast.m_mx; int32_t deltaY = m_mouseNow.m_my - m_mouseLast.m_my; m_horizontalAngle += m_mouseSpeed * float(deltaX); m_verticalAngle -= m_mouseSpeed * float(deltaY); m_mouseLast.m_mx = m_mouseNow.m_mx; m_mouseLast.m_my = m_mouseNow.m_my; } entry::GamepadHandle handle = { 0 }; m_horizontalAngle += m_gamepadSpeed * inputGetGamepadAxis(handle, entry::GamepadAxis::RightX)/32768.0f; m_verticalAngle -= m_gamepadSpeed * inputGetGamepadAxis(handle, entry::GamepadAxis::RightY)/32768.0f; const int32_t gpx = inputGetGamepadAxis(handle, entry::GamepadAxis::LeftX); const int32_t gpy = inputGetGamepadAxis(handle, entry::GamepadAxis::LeftY); m_keys |= gpx < -16834 ? CAMERA_KEY_LEFT : 0; m_keys |= gpx > 16834 ? CAMERA_KEY_RIGHT : 0; m_keys |= gpy < -16834 ? CAMERA_KEY_FORWARD : 0; m_keys |= gpy > 16834 ? CAMERA_KEY_BACKWARD : 0; float direction[3] = { cosf(m_verticalAngle) * sinf(m_horizontalAngle), sinf(m_verticalAngle), cosf(m_verticalAngle) * cosf(m_horizontalAngle), }; float right[3] = { sinf(m_horizontalAngle - bx::piHalf), 0, cosf(m_horizontalAngle - bx::piHalf), }; float up[3]; bx::vec3Cross(up, right, direction); if (m_keys & CAMERA_KEY_FORWARD) { float pos[3]; bx::vec3Move(pos, m_eye); float tmp[3]; bx::vec3Mul(tmp, direction, _deltaTime * m_moveSpeed); bx::vec3Add(m_eye, pos, tmp); setKeyState(CAMERA_KEY_FORWARD, false); } if (m_keys & CAMERA_KEY_BACKWARD) { float pos[3]; bx::vec3Move(pos, m_eye); float tmp[3]; bx::vec3Mul(tmp, direction, _deltaTime * m_moveSpeed); bx::vec3Sub(m_eye, pos, tmp); setKeyState(CAMERA_KEY_BACKWARD, false); } if (m_keys & CAMERA_KEY_LEFT) { float pos[3]; bx::vec3Move(pos, m_eye); float tmp[3]; bx::vec3Mul(tmp, right, _deltaTime * m_moveSpeed); bx::vec3Add(m_eye, pos, tmp); setKeyState(CAMERA_KEY_LEFT, false); } if (m_keys & CAMERA_KEY_RIGHT) { float pos[3]; bx::vec3Move(pos, m_eye); float tmp[3]; bx::vec3Mul(tmp, right, _deltaTime * m_moveSpeed); bx::vec3Sub(m_eye, pos, tmp); setKeyState(CAMERA_KEY_RIGHT, false); } if (m_keys & CAMERA_KEY_UP) { float pos[3]; bx::vec3Move(pos, m_eye); float tmp[3]; bx::vec3Mul(tmp, up, _deltaTime * m_moveSpeed); bx::vec3Add(m_eye, pos, tmp); setKeyState(CAMERA_KEY_UP, false); } if (m_keys & CAMERA_KEY_DOWN) { float pos[3]; bx::vec3Move(pos, m_eye); float tmp[3]; bx::vec3Mul(tmp, up, _deltaTime * m_moveSpeed); bx::vec3Sub(m_eye, pos, tmp); setKeyState(CAMERA_KEY_DOWN, false); } bx::vec3Add(m_at, m_eye, direction); bx::vec3Cross(m_up, right, direction); }