-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoculusreader.cpp
More file actions
84 lines (69 loc) · 2.18 KB
/
oculusreader.cpp
File metadata and controls
84 lines (69 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "oculusreader.h"
#include <QDebug>
OculusReader::OculusReader():
m_camera(NULL),
m_enabled(true)
{
m_upVectorStart = QVector3D(0,1,0);
m_viewVectorStart = QVector3D(-4,0,0);
pManager = *DeviceManager::Create();
DeviceEnumerator<SensorDevice> isensor = pManager->EnumerateDevices<SensorDevice>();
DeviceEnumerator<SensorDevice> oculusSensor;
DeviceEnumerator<SensorDevice> oculusSensor2;
while(isensor)
{
DeviceInfo di;
if (isensor.GetDeviceInfo(&di))
{
if (strstr(di.ProductName, "Tracker"))
{
if (!oculusSensor)
oculusSensor = isensor;
else if (!oculusSensor2)
oculusSensor2 = isensor;
}
}
isensor.Next();
}
if (oculusSensor)
{
pSensor = *oculusSensor.CreateDevice();
if (pSensor)
pSensor->SetRange(SensorRange(4 * 9.81f, 8 * Math<float>::Pi, 1.0f), true);
if (oculusSensor2)
{
// Second Oculus sensor, useful for comparing firmware behavior & settings.
pSensor2 = *oculusSensor2.CreateDevice();
if (pSensor2)
pSensor2->SetRange(SensorRange(4 * 9.81f, 8 * Math<float>::Pi, 1.0f), true);
}
}
oculusSensor.Clear();
oculusSensor2.Clear();
if (pSensor)
SFusion.AttachToSensor(pSensor);
if (pSensor2)
SFusion2.AttachToSensor(pSensor2);
m_isFirst = true;
m_timer.setInterval(16);
connect(&m_timer, SIGNAL(timeout()),this,SLOT(readSensors()));
m_timer.start();
}
void OculusReader::readSensors() {
if(!m_enabled) {
return;
}
if(m_camera == NULL) {
if(m_isFirst) {
qDebug() << "Camera pointer not set";
}
return;
}
Quatf orient = SFusion.GetOrientation();
QQuaternion qorient(orient.w, orient.z, orient.y, -orient.x); // høyre venstre riktig
QVector3D upVector = qorient.rotatedVector(m_upVectorStart);
QVector3D viewVector = qorient.rotatedVector(m_viewVectorStart);
m_camera->setUpVector(upVector);
m_camera->setCenter(m_camera->eye() + viewVector);
m_isFirst = false;
}