From e0c7730c5db161318ddc4dab1403db872f9bfe36 Mon Sep 17 00:00:00 2001 From: XProger Date: Mon, 22 Mar 2021 07:53:55 +0300 Subject: [PATCH] right stick for look --- src/camera.h | 16 +++++++++++++--- src/lara.h | 2 +- src/video.h | 1 - 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/camera.h b/src/camera.h index e3f68d6..94c47d6 100644 --- a/src/camera.h +++ b/src/camera.h @@ -44,7 +44,7 @@ struct Camera : ICamera { Frustum *frustum; float fov, aspect, znear, zfar; - vec3 lookAngle, targetAngle; + vec3 lookAngle, targetAngle, viewAngle; mat4 mViewInv; float timer; @@ -366,6 +366,8 @@ struct Camera : ICamera { speed = CAM_SPEED_COMBAT; } + viewAngle = vec3(0.0f); + if (mode == MODE_CUTSCENE) { ASSERT(level->cameraFramesCount && level->cameraFrames); @@ -439,9 +441,17 @@ struct Camera : ICamera { if (fabsf(lookAngle.x - CAM_FOLLOW_ANGLE) < EPS) lookAngle.x = CAM_FOLLOW_ANGLE; if (lookAngle.y < EPS) lookAngle.y = 0.0f; } + + vec2 R = Input::joy[Core::settings.controls[cameraIndex].joyIndex].R; + R.x = sign(R.x) * max(0.0f, (fabsf(R.x) - INPUT_JOY_DZ_STICK) / (1.0f - INPUT_JOY_DZ_STICK)); + R.y = sign(R.y) * max(0.0f, (fabsf(R.y) - INPUT_JOY_DZ_STICK) / (1.0f - INPUT_JOY_DZ_STICK)); + + viewAngle.x = -R.y * PIH; + viewAngle.y = R.x * PIH; + viewAngle.z = 0.0f; } - targetAngle = owner->angle + lookAngle; + targetAngle = owner->angle + lookAngle + viewAngle; targetAngle.x = clampAngle(targetAngle.x); targetAngle.y = clampAngle(targetAngle.y); @@ -503,7 +513,7 @@ struct Camera : ICamera { if (mode == MODE_LOOK) offset = CAM_OFFSET_LOOK; else - offset = (mode == MODE_COMBAT ? CAM_OFFSET_COMBAT : CAM_OFFSET_FOLLOW) * cosf(targetAngle.x); + offset = (mode == MODE_COMBAT ? CAM_OFFSET_COMBAT : CAM_OFFSET_FOLLOW); vec3 dir = vec3(targetAngle.x, targetAngle.y) * offset; to.pos = target.pos - dir; diff --git a/src/lara.h b/src/lara.h index 0ee1748..246bfcf 100644 --- a/src/lara.h +++ b/src/lara.h @@ -1301,7 +1301,7 @@ struct Lara : Character { updateTargets(); Controller *lookTarget = canLookAt() ? target : NULL; - if (camera->mode == Camera::MODE_LOOK) { + if (camera->mode == Camera::MODE_LOOK || (lookTarget == NULL && (camera->viewAngle.x != 0.0f || camera->viewAngle.y != 0.0f))) { vec3 p = pos + vec3(camera->targetAngle.x, camera->targetAngle.y) * 8192.0f; Character::lookAtPos(&p); } else diff --git a/src/video.h b/src/video.h index 53c1843..6f0de10 100644 --- a/src/video.h +++ b/src/video.h @@ -1304,7 +1304,6 @@ struct Video { return 0; #else if (!audioDecoder) return 0; - Sound::XA *xa = (Sound::XA*)audioDecoder; int ret = audioDecoder->decode(frames, count); if (ret < count) {