mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 09:24:00 +02:00
Correct mouse position in occulus
This commit is contained in:
parent
abe9704dbc
commit
84da070901
4 changed files with 78 additions and 27 deletions
|
@ -1305,18 +1305,20 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
|
|||
if (event->button() == Qt::LeftButton) {
|
||||
_mouseX = event->x();
|
||||
_mouseY = event->y();
|
||||
_mouseDragStartedX = _mouseX;
|
||||
_mouseDragStartedY = _mouseY;
|
||||
_mouseDragStartedX = getTrueMouseX();
|
||||
_mouseDragStartedY = getTrueMouseY();
|
||||
_mousePressed = true;
|
||||
|
||||
if (_audio.mousePressEvent(_mouseX, _mouseY)) {
|
||||
// stop propagation
|
||||
return;
|
||||
}
|
||||
|
||||
if (_rearMirrorTools->mousePressEvent(_mouseX, _mouseY)) {
|
||||
// stop propagation
|
||||
return;
|
||||
|
||||
if (mouseOnScreen()) {
|
||||
if (_audio.mousePressEvent(getMouseX(), getMouseY())) {
|
||||
// stop propagation
|
||||
return;
|
||||
}
|
||||
|
||||
if (_rearMirrorTools->mousePressEvent(getMouseX(), getMouseY())) {
|
||||
// stop propagation
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// nobody handled this - make it an action event on the _window object
|
||||
|
@ -1349,11 +1351,12 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) {
|
|||
_mouseY = event->y();
|
||||
_mousePressed = false;
|
||||
|
||||
checkBandwidthMeterClick();
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::Stats)) {
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::Stats) && mouseOnScreen()) {
|
||||
// let's set horizontal offset to give stats some margin to mirror
|
||||
int horizontalOffset = MIRROR_VIEW_WIDTH;
|
||||
Stats::getInstance()->checkClick(_mouseX, _mouseY, _mouseDragStartedX, _mouseDragStartedY, horizontalOffset);
|
||||
Stats::getInstance()->checkClick(getMouseX(), getMouseY(),
|
||||
getMouseDragStartedX(), getMouseDragStartedY(), horizontalOffset);
|
||||
checkBandwidthMeterClick();
|
||||
}
|
||||
|
||||
// fire an action end event
|
||||
|
@ -1546,13 +1549,13 @@ void Application::idle() {
|
|||
|
||||
void Application::checkBandwidthMeterClick() {
|
||||
// ... to be called upon button release
|
||||
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::Bandwidth) &&
|
||||
Menu::getInstance()->isOptionChecked(MenuOption::Stats) &&
|
||||
Menu::getInstance()->isOptionChecked(MenuOption::UserInterface) &&
|
||||
glm::compMax(glm::abs(glm::ivec2(_mouseX - _mouseDragStartedX, _mouseY - _mouseDragStartedY)))
|
||||
<= BANDWIDTH_METER_CLICK_MAX_DRAG_LENGTH
|
||||
&& _bandwidthMeter.isWithinArea(_mouseX, _mouseY, _glWidget->width(), _glWidget->height())) {
|
||||
glm::compMax(glm::abs(glm::ivec2(getMouseX() - getMouseDragStartedX(),
|
||||
getMouseY() - getMouseDragStartedY())))
|
||||
<= BANDWIDTH_METER_CLICK_MAX_DRAG_LENGTH
|
||||
&& _bandwidthMeter.isWithinArea(getMouseX(), getMouseY(), _glWidget->width(), _glWidget->height())) {
|
||||
|
||||
// The bandwidth meter is visible, the click didn't get dragged too far and
|
||||
// we actually hit the bandwidth meter
|
||||
|
@ -1666,6 +1669,48 @@ glm::vec3 Application::getMouseVoxelWorldCoordinates(const VoxelDetail& mouseVox
|
|||
(mouseVoxel.z + mouseVoxel.s / 2.0f) * TREE_SCALE);
|
||||
}
|
||||
|
||||
bool Application::mouseOnScreen() const {
|
||||
if (OculusManager::isConnected()) {
|
||||
return getMouseX() >= 0 && getMouseX() <= _glWidget->getDeviceWidth() &&
|
||||
getMouseY() >= 0 && getMouseY() <= _glWidget->getDeviceHeight();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int Application::getMouseX() const {
|
||||
if (OculusManager::isConnected()) {
|
||||
glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseX(), getTrueMouseY()));
|
||||
return pos.x;
|
||||
}
|
||||
return getTrueMouseX();
|
||||
}
|
||||
|
||||
int Application::getMouseY() const {
|
||||
if (OculusManager::isConnected()) {
|
||||
glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseX(), getTrueMouseY()));
|
||||
return pos.y;
|
||||
}
|
||||
return getTrueMouseY();
|
||||
}
|
||||
|
||||
int Application::getMouseDragStartedX() const {
|
||||
if (OculusManager::isConnected()) {
|
||||
glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseDragStartedX(),
|
||||
getTrueMouseDragStartedY()));
|
||||
return pos.x;
|
||||
}
|
||||
return getTrueMouseDragStartedX();
|
||||
}
|
||||
|
||||
int Application::getMouseDragStartedY() const {
|
||||
if (OculusManager::isConnected()) {
|
||||
glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseDragStartedX(),
|
||||
getTrueMouseDragStartedY()));
|
||||
return pos.y;
|
||||
}
|
||||
return getTrueMouseDragStartedY();
|
||||
}
|
||||
|
||||
FaceTracker* Application::getActiveFaceTracker() {
|
||||
return (_dde.isActive() ? static_cast<FaceTracker*>(&_dde) :
|
||||
(_faceshift.isActive() ? static_cast<FaceTracker*>(&_faceshift) :
|
||||
|
@ -1898,7 +1943,6 @@ void Application::init() {
|
|||
|
||||
_mouseX = _glWidget->width() / 2;
|
||||
_mouseY = _glWidget->height() / 2;
|
||||
QCursor::setPos(_mouseX, _mouseY);
|
||||
|
||||
// TODO: move _myAvatar out of Application. Move relevant code to MyAvataar or AvatarManager
|
||||
_avatarManager.init();
|
||||
|
@ -2076,8 +2120,8 @@ void Application::updateMouseRay() {
|
|||
// if the mouse pointer isn't visible, act like it's at the center of the screen
|
||||
float x = 0.5f, y = 0.5f;
|
||||
if (!_mouseHidden) {
|
||||
x = _mouseX / (float)_glWidget->width();
|
||||
y = _mouseY / (float)_glWidget->height();
|
||||
x = getTrueMouseX() / (float)_glWidget->width();
|
||||
y = getTrueMouseY() / (float)_glWidget->height();
|
||||
}
|
||||
PickRay pickRay = _myCamera.computeViewPickRay(x, y);
|
||||
_mouseRayOrigin = pickRay.origin;
|
||||
|
|
|
@ -213,8 +213,15 @@ public:
|
|||
bool isMouseHidden() const { return _mouseHidden; }
|
||||
const glm::vec3& getMouseRayOrigin() const { return _mouseRayOrigin; }
|
||||
const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; }
|
||||
int getMouseX() const { return _mouseX; }
|
||||
int getMouseY() const { return _mouseY; }
|
||||
bool mouseOnScreen() const;
|
||||
int getMouseX() const;
|
||||
int getMouseY() const;
|
||||
int getTrueMouseX() const { return _mouseX; }
|
||||
int getTrueMouseY() const { return _mouseY; }
|
||||
int getMouseDragStartedX() const;
|
||||
int getMouseDragStartedY() const;
|
||||
int getTrueMouseDragStartedX() const { return _mouseDragStartedX; }
|
||||
int getTrueMouseDragStartedY() const { return _mouseDragStartedY; }
|
||||
bool getLastMouseMoveWasSimulated() const { return _lastMouseMoveWasSimulated;; }
|
||||
Faceshift* getFaceshift() { return &_faceshift; }
|
||||
Visage* getVisage() { return &_visage; }
|
||||
|
|
|
@ -523,7 +523,7 @@ void ApplicationOverlay::renderPointers() {
|
|||
//If we are in oculus, render reticle later
|
||||
_reticleActive[MOUSE] = true;
|
||||
_magActive[MOUSE] = true;
|
||||
_reticulePosition[MOUSE] = glm::vec2(application->getMouseX(), application->getMouseY());
|
||||
_reticulePosition[MOUSE] = glm::vec2(application->getTrueMouseX(), application->getTrueMouseY());
|
||||
_reticleActive[LEFT_CONTROLLER] = false;
|
||||
_reticleActive[RIGHT_CONTROLLER] = false;
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ void NodeBounds::draw() {
|
|||
// Compute ray to find selected nodes later on. We can't use the pre-computed ray in Application because it centers
|
||||
// itself after the cursor disappears.
|
||||
Application* application = Application::getInstance();
|
||||
PickRay pickRay = application->getCamera()->computeViewPickRay(application->getMouseX(), application->getMouseY());
|
||||
PickRay pickRay = application->getCamera()->computeViewPickRay(application->getTrueMouseX(), application->getTrueMouseY());
|
||||
|
||||
// Variables to keep track of the selected node and properties to draw the cube later if needed
|
||||
Node* selectedNode = NULL;
|
||||
|
@ -220,8 +220,8 @@ void NodeBounds::drawOverlay() {
|
|||
const int MOUSE_OFFSET = 10;
|
||||
const int BACKGROUND_BEVEL = 3;
|
||||
|
||||
int mouseX = application->getMouseX(),
|
||||
mouseY = application->getMouseY(),
|
||||
int mouseX = application->getTrueMouseX(),
|
||||
mouseY = application->getTrueMouseY(),
|
||||
textWidth = widthText(TEXT_SCALE, 0, _overlayText);
|
||||
glColor4f(0.4f, 0.4f, 0.4f, 0.6f);
|
||||
renderBevelCornersRect(mouseX + MOUSE_OFFSET, mouseY - TEXT_HEIGHT - PADDING,
|
||||
|
|
Loading…
Reference in a new issue