Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Allow atom selection via VR controllers #399

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contrib/vr/OpenVRControllerModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ SOFTWARE.
// system headers
#include <chrono>
#include <vector>
#include <thread>
#include "os_std.h"
#include "os_gl.h"

Expand Down
37 changes: 29 additions & 8 deletions contrib/vr/OpenVRMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ SOFTWARE.
#include "Feedback.h"
#include "Matrix.h"
#include "Ortho.h"
#include "Scene.h"
#include "SceneMouse.h"
#include "ButMode.h"

// local headers
#include "OpenVRUtils.h"
Expand Down Expand Up @@ -727,11 +730,12 @@ void OpenVRGetPickingProjection(PyMOLGlobals * G, float near_plane, float far_p

// take avarage projection params from eyes
float left, right, top, bottom;
float vertical_offset = 0.45;
CEye &LEye = I->Left, &REye = I->Right;
left = (LEye.Left + REye.Left) * 0.5f;
right = (LEye.Right + REye.Right) * 0.5f;
top = (LEye.Top + REye.Top) * 0.5f;
bottom = (LEye.Bottom + REye.Bottom) * 0.5f;
top = (LEye.Top + REye.Top + vertical_offset) * 0.5f;
bottom = (LEye.Bottom + REye.Bottom + vertical_offset) * 0.5f;
OpenVRGetProjection(left, right, top, bottom, near_plane, far_plane, matrix);
return;
}
Expand Down Expand Up @@ -1031,7 +1035,6 @@ void HandleLaser(PyMOLGlobals * G, int centerX, int centerY, CMouseEvent const&
}

bool menuHit = false;

if (laserSource) {
I->Picker.Activate(laserSource->GetLaserDeviceIndex(), centerX, centerY);

Expand All @@ -1054,14 +1057,32 @@ void HandleLaser(PyMOLGlobals * G, int centerX, int centerY, CMouseEvent const&
}
}

// laser missed
float missedColor[4] = {1.0f, 1.0f, 0.0f, 0.5f};
if (!laserTarget) {
laserTarget = &I->Picker;
if (!SettingGetGlobal_b(G, cSetting_openvr_cut_laser)) {
laserSource->SetLaserLength(0.0f);

CScene *Scene = G->Scene;
if (SettingGetGlobal_b(G, cSetting_openvr_cut_laser) && OpenVRIsScenePickerActive(G)) {
float atomWorldPos[3];
ScenePickAtomInWorld(G, centerX, centerY, atomWorldPos);
OpenVRUpdateScenePickerLength(G, atomWorldPos);
}

// check if we hit an atom
if (Scene->LastPicked.context.object != NULL) {
float atomHitColor[4] = {1.0f, 0.0f, 1.0f, 0.5f};
laserSource->SetLaserColor(atomHitColor);
// select the atom
if(Actions->Action1->WasPressed()) {
SceneClickObject(G, Scene->LastPicked.context.object, Scene->LastPicked, cButModeSeleToggle, "");
}
} else {
// laser missed
float missedColor[4] = {1.0f, 1.0f, 0.0f, 0.5f};
if (!SettingGetGlobal_b(G, cSetting_openvr_cut_laser)) {
laserSource->SetLaserLength(0.0f);
}
laserSource->SetLaserColor(missedColor);
}
laserSource->SetLaserColor(missedColor);
}

if (mouseEvent.deviceIndex == laserSource->GetLaserDeviceIndex()) {
Expand Down