forked from chebee7i/DTS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrackerTool.cpp
99 lines (74 loc) · 2.74 KB
/
TrackerTool.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
#include "FieldViewer.h"
#include "PositionDialog.h"
Viewer::TrackerToolFactory::TrackerToolFactory(Vrui::ToolManager& toolManager, Viewer* sApplication)
: Vrui::ToolFactory("TrackerTool",toolManager),
application(sApplication),
numButtons(1),
buttonToggleFlags(0),
numValuators(0)
{
/* Initialize the input device layout of the custom tool class: */
layout.setNumDevices(1);
layout.setNumButtons(0,numButtons); // device 0 has 1 button
layout.setNumValuators(0,numValuators);
/* Set the custom tool class' factory pointer: */
TrackerTool::factory=this;
}
Viewer::TrackerToolFactory::~TrackerToolFactory(void)
{
TrackerTool::factory = 0;
// TODO
// need to delete all *remaining* tools created by this factory
// otherwise, alt-f4 causes segmentation fault
// so we need a list to keep track of created tools
}
Vrui::Tool* Viewer::TrackerToolFactory::createTool(const Vrui::ToolInputAssignment& inputAssignment) const
{
/* Create a new object of the custom tool class: */
TrackerTool* newTool=new TrackerTool(this,inputAssignment);
return newTool;
}
void Viewer::TrackerToolFactory::destroyTool(Vrui::Tool* tool) const
{
/* Cast the tool pointer to the custom tool class (not really necessary): */
TrackerTool* trackerTool=dynamic_cast<TrackerTool*>(tool);
/* Destroy the tool: */
delete trackerTool;
}
/***************************************************
Static elements of class Viewer::TrackerTool:
***************************************************/
Viewer::TrackerToolFactory* Viewer::TrackerTool::factory=0;
/*******************************************
Methods of class Viewer::TrackerTool:
*******************************************/
Viewer::TrackerTool::TrackerTool(const TrackerToolFactory* factory,const Vrui::ToolInputAssignment& inputAssignment)
:Vrui::TransformTool(factory,inputAssignment)
{
}
const Viewer::TrackerToolFactory* Viewer::TrackerTool::getFactory(void) const
{
return factory;
}
void Viewer::TrackerTool::initialize(void)
{
TransformTool::initialize();
positionDialog = new PositionDialog();
positionDialog->show();
}
void Viewer::TrackerTool::deinitialize(void)
{
TransformTool::deinitialize();
delete positionDialog;
}
void Viewer::TrackerTool::frame(void)
{
Vrui::Point pos = Vrui::getDeviceTransformation(input.getDevice(0)).getOrigin();
/// what IS this? no matter what, we are always in the xz plane.
/// on desktop...this is true whether we use a MouseTool or not.
//transformedDevice->setTransformation(input.getDevice(0)->getTransformation());
//Vrui::Point pos = transformedDevice->getPosition();
positionDialog->setX(pos[0]);
positionDialog->setY(pos[1]);
positionDialog->setZ(pos[2]);
}