-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrackerPlugin.cpp
150 lines (124 loc) · 2.63 KB
/
TrackerPlugin.cpp
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <TrackerPlugin.h>
#include <cvrConfig/ConfigManager.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <osg/Vec3>
using namespace cvr;
using namespace osg;
using namespace std;
TrackerPlugin::TrackerPlugin()
{
_numBodies = 0;
_numButtons = 0;
_numVal = 0;
_buttonMask = 0;
}
TrackerPlugin::~TrackerPlugin()
{
}
bool TrackerPlugin::init(std::string tag)
{
_numBodies = 1;
for (int i = 0; i < _numBodies; i++)
{
TrackedBody* tb = new TrackedBody;
tb->x = tb->y = tb->z = 0.0;
osg::Quat q;
tb->qx = q.x();
tb->qy = q.y();
tb->qz = q.z();
tb->qw = q.w();
_bodyList.push_back(tb);
_bodyListMem.push_back(tb);
}
_numButtons = 2;
_numVal = 0;
for (int i = 0; i < _numVal; i++)
{
_valList.push_back(0.0);
_valListMem.push_back(0.0);
}
_buttonMask = 0;
_buttonMaskMem = 0;
return true;
}
TrackerBase::TrackedBody* TrackerPlugin::getBody(int index)
{
if (index < 0 || index >= _numBodies)
{
return NULL;
}
return _bodyList[index];
}
void TrackerPlugin::setBody(int index, TrackedBody* tb)
{
if (index < 0 || index >= _numBodies)
{
}
else
{
_bodyListMem[index] = tb;
}
}
unsigned int TrackerPlugin::getButtonMask()
{
return _buttonMask;
}
void TrackerPlugin::setButtonMask(int buttonMask)
{
_buttonMaskMem = buttonMask;
}
float TrackerPlugin::getValuator(int index)
{
if (index < 0 || index >= _numVal)
{
return 0.0;
}
return _valList[index];
}
void TrackerPlugin::setValuator(int index, float val)
{
_valListMem[index] = val;
}
int TrackerPlugin::getNumBodies()
{
return _numBodies;
}
int TrackerPlugin::getNumValuators()
{
return _numVal;
}
int TrackerPlugin::getNumButtons()
{
return _numButtons;
}
void TrackerPlugin::update(
std::map<int, std::list<InteractionEvent*> >& eventMap)
{
if (_numButtons)
{
_buttonMask = 0;
for (int i = 0; i < _numButtons; i++)
{
_buttonMask = _buttonMask | _buttonMaskMem;
}
}
if (_numVal)
{
for (int i = 0; i < _numVal; i++)
{
_valList[i] = _valListMem[i];
}
}
for (int i = 0; i < _numBodies; i++)
{
_bodyList[i]->x = _bodyListMem[i]->x;
_bodyList[i]->y = _bodyListMem[i]->y;
_bodyList[i]->z = _bodyListMem[i]->z;
_bodyList[i]->qx = _bodyListMem[i]->qx;
_bodyList[i]->qy = _bodyListMem[i]->qy;
_bodyList[i]->qz = _bodyListMem[i]->qz;
_bodyList[i]->qw = _bodyListMem[i]->qw;
}
}