Library/Camera: Implement CameraParamMoveLimit (#154)

This commit is contained in:
MonsterDruide1 2024-09-04 12:03:53 +02:00 committed by GitHub
parent 3c23d9b0c3
commit b51a8b420a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 124 additions and 4 deletions

View File

@ -65930,10 +65930,10 @@ Address,Quality,Size,Name
0x0000007100a4bc2c,U,000020,_ZN2al18CameraOffsetPresetC2Ev
0x0000007100a4bc40,U,000012,_ZN2al18CameraOffsetPresetC2EPKNS_22CameraOffsetPresetDataEi
0x0000007100a4bc4c,U,000140,_ZN2al18CameraOffsetPreset9loadParamERKNS_9ByamlIterE
0x0000007100a4bcd8,U,000180,_ZN2al20CameraParamMoveLimit6createEPKNS_11CameraPoserE
0x0000007100a4bd8c,U,000264,_ZN2al20CameraParamMoveLimit4loadERKNS_9ByamlIterE
0x0000007100a4be94,U,000736,_ZNK2al20CameraParamMoveLimit5applyEPN4sead12LookAtCameraE
0x0000007100a4c174,U,000124,_ZN2al20CameraParamMoveLimitC2Ev
0x0000007100a4bcd8,O,000180,_ZN2al20CameraParamMoveLimit6createEPKNS_11CameraPoserE
0x0000007100a4bd8c,O,000264,_ZN2al20CameraParamMoveLimit4loadERKNS_9ByamlIterE
0x0000007100a4be94,O,000736,_ZNK2al20CameraParamMoveLimit5applyEPN4sead12LookAtCameraE
0x0000007100a4c174,O,000124,_ZN2al20CameraParamMoveLimitC2Ev
0x0000007100a4c1f0,U,000056,_ZN2al15CameraStateBaseC1EPKcPNS_11CameraPoserE
0x0000007100a4c228,U,000036,_ZN2al15CameraStateBaseD0Ev
0x0000007100a4c24c,O,000284,_ZN2al24CameraSubTargetTurnParam4initERKNS_13ActorInitInfoE

Can't render this file because it is too large.

View File

@ -0,0 +1,84 @@
#include "Library/Camera/CameraParamMoveLimit.h"
#include <gfx/seadCamera.h>
#include "Library/Camera/CameraPoser.h"
#include "Library/Matrix/MatrixUtil.h"
#include "Library/Yaml/ByamlIter.h"
#include "Library/Yaml/ByamlUtil.h"
namespace al {
CameraParamMoveLimit* CameraParamMoveLimit::create(const CameraPoser* poser) {
CameraParamMoveLimit* result = new CameraParamMoveLimit();
result->mViewMtx = poser->getViewMtx();
result->mInvViewMtx.setInverse(poser->getViewMtx());
return result;
}
CameraParamMoveLimit::CameraParamMoveLimit() {}
void CameraParamMoveLimit::load(const ByamlIter& iter) {
ByamlIter moveLimitIter;
if (!iter.tryGetIterByKey(&moveLimitIter, "MoveLimit"))
return;
if (tryGetByamlF32(&mPlus.x, moveLimitIter, "PlusX"))
mHasPlusX = true;
if (tryGetByamlF32(&mMinus.x, moveLimitIter, "MinusX"))
mHasMinusX = true;
if (tryGetByamlF32(&mPlus.y, moveLimitIter, "PlusY"))
mHasPlusY = true;
if (tryGetByamlF32(&mMinus.y, moveLimitIter, "MinusY"))
mHasMinusY = true;
if (tryGetByamlF32(&mPlus.z, moveLimitIter, "PlusZ"))
mHasPlusZ = true;
if (tryGetByamlF32(&mMinus.z, moveLimitIter, "MinusZ"))
mHasMinusZ = true;
}
void CameraParamMoveLimit::apply(sead::LookAtCamera* camera) const {
sead::Vector3f constrainedViewAt;
// required to enforce lifetimes of variables
{
f32 preRotYDegree = -mRotYDegree;
sead::Vector3f inverseViewAt;
inverseViewAt.setMul(mInvViewMtx, camera->getAt());
sead::Matrix34f mtxRotateY = sead::Matrix34f::ident;
rotateMtxYDirDegree(&mtxRotateY, mtxRotateY, preRotYDegree);
constrainedViewAt.setMul(mtxRotateY, inverseViewAt);
if (mHasPlusX)
constrainedViewAt.x = constrainedViewAt.x > mPlus.x ? mPlus.x : constrainedViewAt.x;
if (mHasPlusY)
constrainedViewAt.y = constrainedViewAt.y > mPlus.y ? mPlus.y : constrainedViewAt.y;
if (mHasPlusZ)
constrainedViewAt.z = constrainedViewAt.z > mPlus.z ? mPlus.z : constrainedViewAt.z;
if (mHasMinusX)
constrainedViewAt.x = constrainedViewAt.x < mMinus.x ? mMinus.x : constrainedViewAt.x;
if (mHasMinusY)
constrainedViewAt.y = constrainedViewAt.y < mMinus.y ? mMinus.y : constrainedViewAt.y;
if (mHasMinusZ)
constrainedViewAt.z = constrainedViewAt.z < mMinus.z ? mMinus.z : constrainedViewAt.z;
}
f32 rotYDegree = mRotYDegree;
sead::Matrix34f mtxRotateY = sead::Matrix34f::ident;
rotateMtxYDirDegree(&mtxRotateY, mtxRotateY, rotYDegree);
sead::Vector3f finalInverseViewAt;
finalInverseViewAt.setMul(mtxRotateY, constrainedViewAt);
sead::Vector3f finalViewAt;
finalViewAt.setMul(mViewMtx, finalInverseViewAt);
sead::Vector3f constraintAdjustment = finalViewAt - camera->getAt();
camera->getAt() = constraintAdjustment + camera->getAt();
camera->getPos() = constraintAdjustment + camera->getPos();
}
} // namespace al

View File

@ -0,0 +1,34 @@
#pragma once
#include <gfx/seadCamera.h>
namespace al {
class ByamlIter;
class CameraPoser;
class CameraParamMoveLimit {
public:
static CameraParamMoveLimit* create(const CameraPoser* poser);
CameraParamMoveLimit();
void load(const ByamlIter& iter);
void apply(sead::LookAtCamera* camera) const;
private:
sead::Vector3f mPlus = {100000.0f, 100000.0f, 100000.0f};
sead::Vector3f mMinus = {-100000.0f, -100000.0f, -100000.0f};
bool mHasPlusX = false;
bool mHasMinusX = false;
bool mHasPlusY = false;
bool mHasMinusY = false;
bool mHasPlusZ = false;
bool mHasMinusZ = false;
sead::Matrix34f mViewMtx = sead::Matrix34f::ident;
sead::Matrix34f mInvViewMtx = sead::Matrix34f::ident;
f32 mRotYDegree = 0;
};
static_assert(sizeof(CameraParamMoveLimit) == 0x84);
} // namespace al

View File

@ -108,6 +108,8 @@ public:
sead::Vector3f getCameraUp() const { return mCameraUp; };
const sead::Matrix34f& getViewMtx() const { return mViewMtx; };
private:
const char* mPoserName;
f32 field_38;