| 1 | #include "Project/Camera/CameraAngleSwingInfo.h" |
| 2 | |
| 3 | #include "Library/Math/MathUtil.h" |
| 4 | #include "Library/Yaml/ByamlUtil.h" |
| 5 | |
| 6 | namespace al { |
| 7 | |
| 8 | CameraAngleSwingInfo::CameraAngleSwingInfo() { |
| 9 | // these need to be explicit in this constructor, otherwise mismatch |
| 10 | mCurrentAngle = {0.0f, 0.0f}; |
| 11 | _14 = 0.3f; |
| 12 | _18 = 0.1f; |
| 13 | } |
| 14 | |
| 15 | void CameraAngleSwingInfo::load(const ByamlIter& iter) { |
| 16 | tryGetByamlBool(&mIsInvalidSwing, iter, "IsInvalidSwing" ); |
| 17 | if (mIsInvalidSwing) |
| 18 | return; |
| 19 | |
| 20 | tryGetByamlF32(&mMaxSwingDegreeH, iter, "MaxSwingDegreeH" ); |
| 21 | tryGetByamlF32(&mMaxSwingDegreeV, iter, "MaxSwingDegreeV" ); |
| 22 | } |
| 23 | |
| 24 | void CameraAngleSwingInfo::update(const sead::Vector2f& stickInput, f32 stickSensitivity) { |
| 25 | if (mIsInvalidSwing) { |
| 26 | mCurrentAngle = {0.0f, 0.0f}; |
| 27 | return; |
| 28 | } |
| 29 | |
| 30 | sead::Vector2f swingDegrees = { |
| 31 | -stickInput.x * mMaxSwingDegreeH, |
| 32 | stickInput.y * mMaxSwingDegreeV, |
| 33 | }; |
| 34 | |
| 35 | lerpVec(&swingDegrees, mCurrentAngle, swingDegrees, _14 * stickSensitivity); |
| 36 | lerpVec(&mCurrentAngle, mCurrentAngle, swingDegrees, _18); |
| 37 | } |
| 38 | |
| 39 | void CameraAngleSwingInfo::makeLookAtCamera(sead::LookAtCamera* camera) const { |
| 40 | sead::Vector3f cameraLookDirection = camera->getAt() - camera->getPos(); |
| 41 | f32 cameraLookDistance = cameraLookDirection.length(); |
| 42 | normalize(vec: &cameraLookDirection); |
| 43 | sead::Vector3f cameraLookHDir = sead::Vector3f::ey; |
| 44 | verticalizeVec(out: &cameraLookHDir, vertical: cameraLookDirection, vec: cameraLookHDir); |
| 45 | if (!tryNormalizeOrZero(out: &cameraLookHDir)) |
| 46 | return; |
| 47 | |
| 48 | rotateVectorDegree(&cameraLookDirection, cameraLookDirection, cameraLookHDir, mCurrentAngle.x); |
| 49 | normalize(vec: &cameraLookDirection); |
| 50 | sead::Vector3f cameraSideDir; |
| 51 | cameraSideDir.setCross(a: cameraLookDirection, b: cameraLookHDir); |
| 52 | normalize(vec: &cameraSideDir); |
| 53 | rotateVectorDegree(&cameraLookDirection, cameraLookDirection, cameraSideDir, mCurrentAngle.y); |
| 54 | camera->setAt((cameraLookDistance * cameraLookDirection) + camera->getPos()); |
| 55 | } |
| 56 | |
| 57 | } // namespace al |
| 58 | |