-
Notifications
You must be signed in to change notification settings - Fork 215
/
Controller.cpp
122 lines (109 loc) · 3.6 KB
/
Controller.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
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "Controller.h"
#include "vrb/ConcreteClass.h"
#include "vrb/Matrix.h"
#include "vrb/Transform.h"
using namespace vrb;
namespace crow {
Controller::Controller() {
Reset();
}
Controller::Controller(const Controller& aController) {
*this = aController;
}
Controller::~Controller() {
Reset();
}
Controller&
Controller::operator=(const Controller& aController) {
index = aController.index;
enabled = aController.enabled;
focused = aController.focused;
widget = aController.widget;
pointerX = aController.pointerX;
pointerY = aController.pointerY;
pointerWorldPoint = aController.pointerWorldPoint;
buttonState = aController.buttonState;
lastButtonState = aController.lastButtonState;
touched = aController.touched;
wasTouched = aController.wasTouched;
touchX = aController.touchX;
touchY= aController.touchY;
lastTouchX = aController.lastTouchX;
lastTouchY = aController.lastTouchY;
scrollStart = aController.scrollStart;
scrollDeltaX = aController.scrollDeltaX;
scrollDeltaY = aController.scrollDeltaY;
transform = aController.transform;
beamToggle = aController.beamToggle;
beamParent = aController.beamParent;
pointer = aController.pointer;
transformMatrix = aController.transformMatrix;
beamTransformMatrix = aController.beamTransformMatrix;
immersiveName = aController.immersiveName;
immersivePressedState = aController.immersivePressedState;
immersiveTouchedState = aController.immersiveTouchedState;
memcpy(immersiveTriggerValues, aController.immersiveTriggerValues, sizeof(immersiveTriggerValues));
numButtons = aController.numButtons;
memcpy(immersiveAxes, aController.immersiveAxes, sizeof(immersiveAxes));
numAxes = aController.numAxes;
numHaptics = aController.numHaptics;
inputFrameID = aController.inputFrameID;
pulseDuration = aController.pulseDuration;
pulseIntensity = aController.pulseIntensity;
leftHanded = aController.leftHanded;
inDeadZone = aController.inDeadZone;
lastHoverEvent = aController.lastHoverEvent;
return *this;
}
void
Controller::Reset() {
index = -1;
enabled = false;
focused = false;
widget = 0;
pointerX = pointerY = 0.0f;
pointerWorldPoint = vrb::Vector(0.0f, 0.0f, 0.0f);
buttonState = lastButtonState = 0;
touched = wasTouched = false;
touchX = touchY = 0.0f;
lastTouchX = lastTouchY = 0.0f;
scrollStart = -1.0;
scrollDeltaX = scrollDeltaY = 0.0f;
transform = nullptr;
beamToggle = nullptr;
beamParent = nullptr;
pointer = nullptr;
transformMatrix = Matrix::Identity();
beamTransformMatrix = Matrix::Identity();
immersiveName.clear();
immersivePressedState = 0;
immersiveTouchedState = 0;
memset(immersiveTriggerValues, 0, sizeof(immersiveTriggerValues));
numButtons = 0;
memset(immersiveAxes, 0, sizeof(immersiveAxes));
numAxes = 0;
numHaptics = 0;
inputFrameID = 0;
pulseDuration = 0.0f;
pulseIntensity = 0.0f;
leftHanded = false;
inDeadZone = true;
lastHoverEvent = 0.0;
}
vrb::Vector Controller::StartPoint() const {
return transformMatrix.MultiplyPosition(beamTransformMatrix.MultiplyPosition(vrb::Vector()));
}
vrb::Vector Controller::Direction() const {
return transformMatrix.MultiplyDirection(beamTransformMatrix.MultiplyDirection(vrb::Vector(0.0f, 0.0f, -1.0f)));
}
void
Controller::DetachRoot() {
if (transform) {
transform->RemoveFromParents();
}
}
} // namespace crow