|
@@ -37,8 +37,10 @@ const static float fov = 45.0f;
|
37
|
37
|
const static float nearDist = 0.1f;
|
38
|
38
|
const static float farDist = 75000.0f;
|
39
|
39
|
const static float maxSpeed = 3072.0f;
|
|
40
|
+const static float controllerDeadZone = 0.33f;
|
40
|
41
|
const static float controllerViewFactor = glm::pi<float>();
|
41
|
|
-const static float controllerDeadZone = 0.2f;
|
|
42
|
+const static float rotationAngleClamp = glm::pi<float>() * 2.0f;
|
|
43
|
+const static float rotationAngleVertMax = glm::pi<float>() / 2.0f;
|
42
|
44
|
|
43
|
45
|
const static glm::vec3 rightUnit(1.0f, 0.0f, 0.0f);
|
44
|
46
|
const static glm::vec3 upUnit(0.0f, 1.0f, 0.0f);
|
|
@@ -111,32 +113,24 @@ void Camera::handleMouseMotion(int x, int y) {
|
111
|
113
|
}
|
112
|
114
|
|
113
|
115
|
while (y > 0) {
|
114
|
|
- if (rot.y > -(glm::pi<float>() / 2.0f)) {
|
|
116
|
+ if (rot.y > -rotationAngleVertMax) {
|
115
|
117
|
rot.y -= rotationDeltaY;
|
116
|
118
|
}
|
117
|
119
|
y--;
|
118
|
120
|
}
|
119
|
121
|
|
120
|
122
|
while (y < 0) {
|
121
|
|
- if (rot.y < (glm::pi<float>() / 2.0f)) {
|
|
123
|
+ if (rot.y < rotationAngleVertMax) {
|
122
|
124
|
rot.y += rotationDeltaY;
|
123
|
125
|
}
|
124
|
126
|
y++;
|
125
|
127
|
}
|
126
|
|
-
|
127
|
|
- while (rot.x > (glm::pi<float>() * 2.0f))
|
128
|
|
- rot.x -= glm::pi<float>() * 2.0f;
|
129
|
|
-
|
130
|
|
- while (rot.x < -(glm::pi<float>() * 2.0f))
|
131
|
|
- rot.x += glm::pi<float>() * 2.0f;
|
132
|
128
|
}
|
133
|
129
|
|
134
|
130
|
void Camera::handleControllerAxis(float value, KeyboardButton axis) {
|
135
|
131
|
if (glm::epsilonEqual(value, 0.0f, controllerDeadZone))
|
136
|
132
|
value = 0.0f;
|
137
|
133
|
|
138
|
|
- // TODO clamp Y rotation axis somehow...?
|
139
|
|
-
|
140
|
134
|
if (axis == leftXAxis) {
|
141
|
135
|
posSpeed.x = -maxSpeed * value;
|
142
|
136
|
} else if (axis == leftYAxis) {
|
|
@@ -152,32 +146,26 @@ void Camera::handleControllerAxis(float value, KeyboardButton axis) {
|
152
|
146
|
dirty = true;
|
153
|
147
|
}
|
154
|
148
|
|
155
|
|
-void Camera::handleControllerButton(KeyboardButton button, bool released) {
|
156
|
|
- if (button == aButton) {
|
157
|
|
- handleAction(jumpAction, released);
|
158
|
|
- } else if (button == bButton) {
|
159
|
|
- handleAction(crouchAction, released);
|
160
|
|
- } else if (button == padUp) {
|
161
|
|
- handleAction(forwardAction, released);
|
162
|
|
- } else if (button == padDown) {
|
163
|
|
- handleAction(backwardAction, released);
|
164
|
|
- } else if (button == padLeft) {
|
165
|
|
- handleAction(leftAction, released);
|
166
|
|
- } else if (button == padRight) {
|
167
|
|
- handleAction(rightAction, released);
|
168
|
|
- } else {
|
169
|
|
- return;
|
170
|
|
- }
|
171
|
|
-
|
172
|
|
- dirty = true;
|
173
|
|
-}
|
174
|
|
-
|
175
|
149
|
bool Camera::update() {
|
176
|
150
|
if ((!dirty) && equal(posSpeed, 0.0f) && equal(rotSpeed, 0.0f))
|
177
|
151
|
return false;
|
178
|
152
|
|
|
153
|
+ while (rot.x > rotationAngleClamp)
|
|
154
|
+ rot.x -= rotationAngleClamp;
|
|
155
|
+ while (rot.x < -rotationAngleClamp)
|
|
156
|
+ rot.x += rotationAngleClamp;
|
|
157
|
+ while (rot.y > rotationAngleClamp)
|
|
158
|
+ rot.y -= rotationAngleClamp;
|
|
159
|
+ while (rot.y < -rotationAngleClamp)
|
|
160
|
+ rot.y += rotationAngleClamp;
|
|
161
|
+
|
179
|
162
|
float dT = RunTime::getLastFrameTime();
|
180
|
|
- rot += rotSpeed * dT;
|
|
163
|
+ glm::vec2 newRot = rot + rotSpeed * dT;
|
|
164
|
+
|
|
165
|
+ if ((newRot.y > -rotationAngleVertMax) && (newRot.y < rotationAngleVertMax))
|
|
166
|
+ rot = newRot;
|
|
167
|
+ else
|
|
168
|
+ rotSpeed = glm::vec2(0.0f, 0.0f);
|
181
|
169
|
|
182
|
170
|
glm::quat quatY = glm::angleAxis(rot.x, glm::vec3(0.0f, 1.0f, 0.0f));
|
183
|
171
|
glm::quat quatX = glm::angleAxis(rot.y, glm::vec3(1.0f, 0.0f, 0.0f));
|