1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-08-20 03:41:33 +02:00

#27 analog gamepad control support

This commit is contained in:
XProger
2017-03-16 14:52:31 +03:00
parent e669f6c395
commit 10017c7907
3 changed files with 36 additions and 5 deletions

View File

@@ -33,7 +33,7 @@ struct Character : Controller {
Collision collision; Collision collision;
Character(IGame *game, int entity, int health) : Controller(game, entity), target(-1), health(health), tilt(0.0f), stand(STAND_GROUND), lastInput(0), velocity(0.0f) { Character(IGame *game, int entity, int health) : Controller(game, entity), target(-1), health(health), tilt(0.0f), stand(STAND_GROUND), lastInput(0), velocity(0.0f), angleExt(0.0f) {
animation.initOverrides(); animation.initOverrides();
rotHead = rotChest = quat(0, 0, 0, 1); rotHead = rotChest = quat(0, 0, 0, 1);
} }

View File

@@ -14,7 +14,7 @@ enum InputKey { ikNone,
// touch // touch
ikTouchA, ikTouchB, ikTouchA, ikTouchB,
// gamepad // gamepad
ikJoyA, ikJoyB, ikJoyX, ikJoyY, ikJoyLB, ikJoyRB, ikJoyL, ikJoyR, ikJoySelect, ikJoyStart, ikJoyLT, ikJoyRT, ikJoyPOV, ikJoyA, ikJoyB, ikJoyX, ikJoyY, ikJoyLB, ikJoyRB, ikJoySelect, ikJoyStart, ikJoyL, ikJoyR, ikJoyLT, ikJoyRT, ikJoyPOV,
ikMAX }; ikMAX };
namespace Input { namespace Input {

View File

@@ -214,6 +214,7 @@ struct Lara : Character {
int lastPickUp; int lastPickUp;
int viewTarget; int viewTarget;
int roomPrev; // water out from room int roomPrev; // water out from room
vec2 rotFactor;
struct Braid { struct Braid {
Lara *lara; Lara *lara;
@@ -1593,6 +1594,7 @@ struct Lara : Character {
} }
virtual int getStateDeath() { virtual int getStateDeath() {
velocity = vec3(0.0f);
return STATE_DEATH; return STATE_DEATH;
} }
@@ -1633,6 +1635,35 @@ struct Lara : Character {
if (Input::down[ikShift] || Input::down[ikJoyLB]) input |= WALK; if (Input::down[ikShift] || Input::down[ikJoyLB]) input |= WALK;
if (Input::down[ikE] || Input::down[ikCtrl] || Input::down[ikJoyA]) input |= ACTION; if (Input::down[ikE] || Input::down[ikCtrl] || Input::down[ikJoyA]) input |= ACTION;
if (Input::down[ikQ] || Input::down[ikAlt] || Input::down[ikJoyY]) input |= WEAPON; if (Input::down[ikQ] || Input::down[ikAlt] || Input::down[ikJoyY]) input |= WEAPON;
// analog control
rotFactor = vec2(1.0f);
if (Input::down[ikJoyL]) input = FORTH | BACK;
if ((state == STATE_STOP || stand == STATE_SURF_TREAD) && fabsf(Input::joy.L.x) < 0.5f && fabsf(Input::joy.L.y) < 0.5f)
return input;
bool moving = state == STATE_RUN || state == STATE_WALK || state == STATE_BACK || state == STATE_FAST_BACK || state == STATE_SURF_SWIM || state == STATE_SURF_BACK;
if (!moving)
if (fabsf(Input::joy.L.x) < fabsf(Input::joy.L.y))
Input::joy.L.x = 0.0f;
else
Input::joy.L.y = 0.0f;
if (Input::joy.L.x != 0.0f) {
input |= (Input::joy.L.x < 0.0f) ? LEFT : RIGHT;
if (moving || stand == STAND_UNDERWATER || stand == STAND_ONWATER)
rotFactor.y = min(fabsf(Input::joy.L.x) / 0.75f, 1.0f);
}
if (Input::joy.L.y != 0.0f) {
input |= (Input::joy.L.y < 0.0f) ? FORTH : BACK;
if (stand == STAND_UNDERWATER)
rotFactor.x = min(fabsf(Input::joy.L.y) / 0.75f, 1.0f);
}
return input; return input;
} }
@@ -1692,11 +1723,10 @@ struct Lara : Character {
w = 0.0f; w = 0.0f;
if (w != 0.0f) if (w != 0.0f)
rotateY(w * Core::deltaTime); rotateY(w * rotFactor.y * Core::deltaTime);
// pitch (underwater only) // pitch (underwater only)
if (stand == STAND_UNDERWATER && (input & (FORTH | BACK))) if (stand == STAND_UNDERWATER && (input & (FORTH | BACK)))
rotateX(((input & FORTH) ? -TURN_WATER_SLOW : TURN_WATER_SLOW) * Core::deltaTime); rotateX(((input & FORTH) ? -TURN_WATER_SLOW : TURN_WATER_SLOW) * rotFactor.x * Core::deltaTime);
// get animation direction // get animation direction
angleExt = angle.y; angleExt = angle.y;
@@ -1782,6 +1812,7 @@ struct Lara : Character {
vec2 vTilt(LARA_TILT_SPEED * Core::deltaTime, LARA_TILT_MAX); vec2 vTilt(LARA_TILT_SPEED * Core::deltaTime, LARA_TILT_MAX);
if (stand == STAND_UNDERWATER) if (stand == STAND_UNDERWATER)
vTilt *= 2.0f; vTilt *= 2.0f;
vTilt *= rotFactor.y;
updateTilt(state == STATE_RUN || stand == STAND_UNDERWATER, vTilt.x, vTilt.y); updateTilt(state == STATE_RUN || stand == STAND_UNDERWATER, vTilt.x, vTilt.y);
if (velocity.length() >= 1.0f) if (velocity.length() >= 1.0f)