Переглянути джерело

Controller menu navigation & limit camera rotation

Thomas Buck 9 роки тому
джерело
коміт
187855894f
6 змінених файлів з 62 додано та 43 видалено
  1. 4
    0
      ChangeLog.md
  2. 0
    1
      include/Camera.h
  3. 0
    1
      include/Game.h
  4. 20
    32
      src/Camera.cpp
  5. 2
    8
      src/Game.cpp
  6. 36
    1
      src/UI.cpp

+ 4
- 0
ChangeLog.md Переглянути файл

2
 
2
 
3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4
 
4
 
5
+    [ 20140213 ]
6
+    * The menu can be navigated using a controller
7
+    * Vertical camera rotation is now also clamped when using a controller
8
+
5
     [ 20140211 ]
9
     [ 20140211 ]
6
     * Updated imgui to version 1.32
10
     * Updated imgui to version 1.32
7
     * Included some SDL game controller configurations
11
     * Included some SDL game controller configurations

+ 0
- 1
include/Camera.h Переглянути файл

21
     static void handleAction(ActionEvents action, bool isFinished);
21
     static void handleAction(ActionEvents action, bool isFinished);
22
     static void handleMouseMotion(int x, int y);
22
     static void handleMouseMotion(int x, int y);
23
     static void handleControllerAxis(float value, KeyboardButton axis);
23
     static void handleControllerAxis(float value, KeyboardButton axis);
24
-    static void handleControllerButton(KeyboardButton button, bool released);
25
 
24
 
26
     //! \fixme The Y axis seems to be the source of all evil?
25
     //! \fixme The Y axis seems to be the source of all evil?
27
     static void setPosition(glm::vec3 p) { pos = glm::vec3(p.x, -p.y, p.z); }
26
     static void setPosition(glm::vec3 p) { pos = glm::vec3(p.x, -p.y, p.z); }

+ 0
- 1
include/Game.h Переглянути файл

23
     static void handleAction(ActionEvents action, bool isFinished);
23
     static void handleAction(ActionEvents action, bool isFinished);
24
     static void handleMouseMotion(int xrel, int yrel, int xabs, int yabs);
24
     static void handleMouseMotion(int xrel, int yrel, int xabs, int yabs);
25
     static void handleControllerAxis(float value, KeyboardButton axis);
25
     static void handleControllerAxis(float value, KeyboardButton axis);
26
-    static void handleControllerButton(KeyboardButton button, bool released);
27
 
26
 
28
     static Entity& getLara();
27
     static Entity& getLara();
29
     static void setLara(long lara);
28
     static void setLara(long lara);

+ 20
- 32
src/Camera.cpp Переглянути файл

37
 const static float nearDist = 0.1f;
37
 const static float nearDist = 0.1f;
38
 const static float farDist = 75000.0f;
38
 const static float farDist = 75000.0f;
39
 const static float maxSpeed = 3072.0f;
39
 const static float maxSpeed = 3072.0f;
40
+const static float controllerDeadZone = 0.33f;
40
 const static float controllerViewFactor = glm::pi<float>();
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
 const static glm::vec3 rightUnit(1.0f, 0.0f, 0.0f);
45
 const static glm::vec3 rightUnit(1.0f, 0.0f, 0.0f);
44
 const static glm::vec3 upUnit(0.0f, 1.0f, 0.0f);
46
 const static glm::vec3 upUnit(0.0f, 1.0f, 0.0f);
111
     }
113
     }
112
 
114
 
113
     while (y > 0) {
115
     while (y > 0) {
114
-        if (rot.y > -(glm::pi<float>() / 2.0f)) {
116
+        if (rot.y > -rotationAngleVertMax) {
115
             rot.y -= rotationDeltaY;
117
             rot.y -= rotationDeltaY;
116
         }
118
         }
117
         y--;
119
         y--;
118
     }
120
     }
119
 
121
 
120
     while (y < 0) {
122
     while (y < 0) {
121
-        if (rot.y < (glm::pi<float>() / 2.0f)) {
123
+        if (rot.y < rotationAngleVertMax) {
122
             rot.y += rotationDeltaY;
124
             rot.y += rotationDeltaY;
123
         }
125
         }
124
         y++;
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
 void Camera::handleControllerAxis(float value, KeyboardButton axis) {
130
 void Camera::handleControllerAxis(float value, KeyboardButton axis) {
135
     if (glm::epsilonEqual(value, 0.0f, controllerDeadZone))
131
     if (glm::epsilonEqual(value, 0.0f, controllerDeadZone))
136
         value = 0.0f;
132
         value = 0.0f;
137
 
133
 
138
-    // TODO clamp Y rotation axis somehow...?
139
-
140
     if (axis == leftXAxis) {
134
     if (axis == leftXAxis) {
141
         posSpeed.x = -maxSpeed * value;
135
         posSpeed.x = -maxSpeed * value;
142
     } else if (axis == leftYAxis) {
136
     } else if (axis == leftYAxis) {
152
     dirty = true;
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
 bool Camera::update() {
149
 bool Camera::update() {
176
     if ((!dirty) && equal(posSpeed, 0.0f) && equal(rotSpeed, 0.0f))
150
     if ((!dirty) && equal(posSpeed, 0.0f) && equal(rotSpeed, 0.0f))
177
         return false;
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
     float dT = RunTime::getLastFrameTime();
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
     glm::quat quatY = glm::angleAxis(rot.x, glm::vec3(0.0f, 1.0f, 0.0f));
170
     glm::quat quatY = glm::angleAxis(rot.x, glm::vec3(0.0f, 1.0f, 0.0f));
183
     glm::quat quatX = glm::angleAxis(rot.y, glm::vec3(1.0f, 0.0f, 0.0f));
171
     glm::quat quatX = glm::angleAxis(rot.y, glm::vec3(1.0f, 0.0f, 0.0f));

+ 2
- 8
src/Game.cpp Переглянути файл

87
         return;
87
         return;
88
 
88
 
89
     if (isFinished) {
89
     if (isFinished) {
90
+        if (activeEvents[action])
91
+            Camera::handleAction(action, isFinished);
90
         activeEvents[action] = false;
92
         activeEvents[action] = false;
91
-        Camera::handleAction(action, isFinished);
92
     } else {
93
     } else {
93
         if (!activeEvents[action])
94
         if (!activeEvents[action])
94
             Camera::handleAction(action, isFinished);
95
             Camera::handleAction(action, isFinished);
110
     Camera::handleControllerAxis(value, axis);
111
     Camera::handleControllerAxis(value, axis);
111
 }
112
 }
112
 
113
 
113
-void Game::handleControllerButton(KeyboardButton button, bool released) {
114
-    if (!mLoaded)
115
-        return;
116
-
117
-    Camera::handleControllerButton(button, released);
118
-}
119
-
120
 Entity& Game::getLara() {
114
 Entity& Game::getLara() {
121
     assert(mLara >= 0);
115
     assert(mLara >= 0);
122
     assert(mLara < (int)getWorld().sizeEntity());
116
     assert(mLara < (int)getWorld().sizeEntity());

+ 36
- 1
src/UI.cpp Переглянути файл

360
 }
360
 }
361
 
361
 
362
 void UI::handleControllerButton(KeyboardButton button, bool released) {
362
 void UI::handleControllerButton(KeyboardButton button, bool released) {
363
-    Game::handleControllerButton(button, released);
363
+    if (visible || Console::isVisible())
364
+        return;
365
+
366
+    if (getMenu().isVisible()) {
367
+        if (button == aButton) {
368
+            handleKeyboard(enterKey, !released);
369
+        } else if (button == padUp) {
370
+            handleKeyboard(upKey, !released);
371
+        } else if (button == padDown) {
372
+            handleKeyboard(downKey, !released);
373
+        } else if (button == padLeft) {
374
+            handleKeyboard(leftKey, !released);
375
+        } else if (button == padRight) {
376
+            handleKeyboard(rightKey, !released);
377
+        } else if (button == startButton) {
378
+            if (!released)
379
+                getMenu().setVisible(false);
380
+        }
381
+    } else {
382
+        if (button == aButton) {
383
+            Game::handleAction(jumpAction, released);
384
+        } else if (button == bButton) {
385
+            Game::handleAction(crouchAction, released);
386
+        } else if (button == padUp) {
387
+            Game::handleAction(forwardAction, released);
388
+        } else if (button == padDown) {
389
+            Game::handleAction(backwardAction, released);
390
+        } else if (button == padLeft) {
391
+            Game::handleAction(leftAction, released);
392
+        } else if (button == padRight) {
393
+            Game::handleAction(rightAction, released);
394
+        } else if (button == startButton) {
395
+            if (!released)
396
+                getMenu().setVisible(true);
397
+        }
398
+    }
364
 }
399
 }
365
 
400
 
366
 void UI::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) {
401
 void UI::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) {

Завантаження…
Відмінити
Зберегти