1 /*
2 OpenVR for PyMOL Copyright Notice
3 =====================================
4 
5 The OpenVR for PyMOL source code is copyrighted, but you can freely use and
6 copy it as long as you don't change or remove any of the Copyright notices.
7 OpenVR for PyMOL is made available under the following open-source license
8 terms:
9 
10 ------------------------------------------------------------------------------
11 Copyright (c) 2018 EPAM Systems, Inc.
12 
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19 
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22 
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30 ------------------------------------------------------------------------------
31 
32 */
33 
34 #ifndef _H_OpenVRStereo
35 #define _H_OpenVRStereo
36 
37 // pymol headers
38 #include "PyMOLGlobals.h"
39 
40 bool OpenVRAvailable(PyMOLGlobals * G);
41 bool OpenVRReady(PyMOLGlobals * G);
42 
43 int OpenVRInit(PyMOLGlobals * G);
44 void OpenVRFree(PyMOLGlobals * G);
45 
46 // PyMOL-style enum
47 enum {
48   cAction_scene_next,
49   cAction_scene_prev,
50 
51   cAction_movie_toggle,
52   cAction_movie_next,
53   cAction_movie_prev,
54 };
55 
56 class OpenVRInputHandlers {
57 public:
KeyboardFunc(unsigned char k,int x,int y,int mod)58   virtual void KeyboardFunc(unsigned char k, int x, int y, int mod) {}
SpecialFunc(int k,int x,int y,int mod)59   virtual void SpecialFunc(int k, int x, int y, int mod) {}
MouseFunc(int button,int state,int x,int y,int mod)60   virtual int MouseFunc(int button, int state, int x, int y, int mod) { return 0; }
MotionFunc(int x,int y,int mod)61   virtual int MotionFunc(int x, int y, int mod) { return 0; }
ActionFunc(int a)62   virtual void ActionFunc(int a) {}
63 };
64 
65 void OpenVRSetInputHandlers(PyMOLGlobals * G, OpenVRInputHandlers* handlers);
66 
67 void OpenVRFeedback(PyMOLGlobals * G);
68 
69 void OpenVRFrameStart(PyMOLGlobals * G);
70 void OpenVREyeStart(PyMOLGlobals * G, int eye);
71 void OpenVREyeFinish(PyMOLGlobals * G);
72 void OpenVRSceneFinish(PyMOLGlobals * G, unsigned sceneX, unsigned sceneY, unsigned sceneWidth, unsigned sceneHeight);
73 void OpenVRFrameFinish(PyMOLGlobals * G);
74 
75 void OpenVRGetWidthHeight(PyMOLGlobals * G, int* width, int* height);
76 
77 void OpenVRMenuBufferStart(PyMOLGlobals * G, unsigned width, unsigned height, bool clear = true);
78 void OpenVRMenuBufferFinish(PyMOLGlobals * G);
79 void OpenVRMenuToggle(PyMOLGlobals * G, unsigned deviceIndex = ~0U);
80 void OpenVRMenuCrop(PyMOLGlobals * G, unsigned x, unsigned y, unsigned width, unsigned height);
81 void OpenVRMenuSettingsChanged(PyMOLGlobals * G);
82 
83 float* OpenVRGetWorldToHead(PyMOLGlobals * G);
84 float* OpenVRGetHeadToEye(PyMOLGlobals * G);
85 float* OpenVRGetControllerPose(PyMOLGlobals * G);
86 float* OpenVRGetEyeProjection(PyMOLGlobals * G, float near_plane, float far_plane);
87 float const* OpenVRGetPickingMatrix(PyMOLGlobals * G);
88 void OpenVRGetPickingProjection(PyMOLGlobals * G, float near_plane, float far_plane, float *matrix);
89 float const *OpenVRGetMolecule2WorldMatrix(PyMOLGlobals * G, float *scaler);
90 
91 void OpenVRLoadProjectionMatrix(PyMOLGlobals * G, float near_plane, float far_plane);
92 void OpenVRLoadPickingProjectionMatrix(PyMOLGlobals * G, float near_plane, float far_plane);
93 void OpenVRLoadWorld2EyeMatrix(PyMOLGlobals * G);
94 
95 bool OpenVRIsMoleculeCaptured(PyMOLGlobals * G);
96 
97 void OpenVRHandleInput(PyMOLGlobals * G, int SceneX, int SceneY, int SceneWidth, int SceneHeight, float *model2World);
98 
99 void OpenVRDraw(PyMOLGlobals * G);
100 
101 void OpenVRClippingChanged(PyMOLGlobals * G);
102 void OpenVRLaserWidthChanged(PyMOLGlobals * G);
103 
104 void OpenVRUpdateScenePickerLength(PyMOLGlobals * G, float *PickWorldPoint);
105 bool OpenVRIsScenePickerActive(PyMOLGlobals * G);
106 
107 #endif /* _H_OpenVRStereo */
108