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 // this header
35 #include "OpenVRController.h"
36
37 // system headers
38 #include "os_gl.h"
39
OpenVRController()40 OpenVRController::OpenVRController()
41 : m_init(false)
42 , m_deviceIndex(~0U)
43 , m_bShowController(true)
44 , m_gripIsPressed(false)
45 , m_pRenderModel(NULL)
46 {
47 }
48
Init()49 void OpenVRController::Init()
50 {
51 m_hintsQuad = new OpenVRQuad();
52 m_hintsQuad->SetSize(0.04f, 0.04f);
53 m_hintsQuad->SetAlpha(0.25f);
54 m_laser.Init();
55 m_init = true;
56 }
57
Free()58 void OpenVRController::Free()
59 {
60 m_laser.Free();
61 delete m_hintsQuad;
62 m_hintsQuad = 0;
63 m_init = false;
64 }
65
IsInitialized()66 bool OpenVRController::IsInitialized()
67 {
68 return m_init;
69 }
70
SetHintsTexture(GLuint hintsTexture,unsigned spriteCount)71 void OpenVRController::SetHintsTexture(GLuint hintsTexture, unsigned spriteCount)
72 {
73 m_hintsQuad->SetTexture(hintsTexture, spriteCount);
74 m_hintsQuad->SetMirror(true);
75 }
76
SetHintsIndex(unsigned index)77 void OpenVRController::SetHintsIndex(unsigned index)
78 {
79 m_hintsQuad->SetSprite(index);
80 }
81
Show(bool isVisible)82 void OpenVRController::Show(bool isVisible)
83 {
84 m_bShowController = isVisible;
85 }
86
IsVisible() const87 bool OpenVRController::IsVisible() const
88 {
89 return m_bShowController;
90 }
91
LaserShow(bool isVisible)92 void OpenVRController::LaserShow(bool isVisible)
93 {
94 if (isVisible)
95 m_laser.Show();
96 else
97 m_laser.Hide();
98 }
99
IsLaserVisible() const100 bool OpenVRController::IsLaserVisible() const
101 {
102 return m_laser.IsVisible();
103 }
104
Draw()105 void OpenVRController::Draw()
106 {
107 GL_DEBUG_FUN();
108
109 glPushMatrix();
110 glMultMatrixf(m_pose);
111
112 if (m_pRenderModel) {
113 m_pRenderModel->Draw();
114
115 glPushMatrix();
116 glTranslatef(0.0f, 0.005f, 0.049f);
117 glRotatef(96.8f, 1.0f, 0.0f, 0.0f);
118 m_hintsQuad->Draw();
119 glPopMatrix();
120 }
121
122 m_laser.Draw();
123
124 glPopMatrix();
125 }
126
GetLaserRay(float * origin,float * dir) const127 bool OpenVRController::GetLaserRay(float* origin, float* dir) const
128 {
129 if (IsLaserVisible()) {
130 if (origin) {
131 origin[0] = m_pose[12];
132 origin[1] = m_pose[13];
133 origin[2] = m_pose[14];
134 }
135 if (dir) {
136 dir[0] = -m_pose[8];
137 dir[1] = -m_pose[9];
138 dir[2] = -m_pose[10];
139 }
140 return true;
141 }
142 return false;
143 }
144
GetLaserDeviceIndex() const145 unsigned OpenVRController::GetLaserDeviceIndex() const
146 {
147 return m_deviceIndex;
148 }
149
SetLaserLength(float length)150 void OpenVRController::SetLaserLength(float length)
151 {
152 m_laser.SetLength(length);
153 }
154
SetLaserWidth(float width)155 void OpenVRController::SetLaserWidth(float width)
156 {
157 m_laser.SetWidth(width);
158 }
159
SetLaserColor(float r,float g,float b,float a)160 void OpenVRController::SetLaserColor(float r, float g, float b, float a)
161 {
162 m_laser.SetColor(r, g, b, a);
163 }
164
SetLaserColor(float const color[])165 void OpenVRController::SetLaserColor(float const color[])
166 {
167 m_laser.SetColor(color[0], color[1], color[2], color[3]);
168 }
169