| 1 | #pragma once |
| 2 | |
| 3 | #include <math/seadMatrix.h> |
| 4 | #include <math/seadVector.h> |
| 5 | #include <prim/seadRuntimeTypeInfo.h> |
| 6 | |
| 7 | namespace sead |
| 8 | { |
| 9 | class OrthoProjection; |
| 10 | class Projection; |
| 11 | class Viewport; |
| 12 | template <typename T> |
| 13 | class Ray; |
| 14 | |
| 15 | class Camera |
| 16 | { |
| 17 | SEAD_RTTI_BASE(Camera) |
| 18 | |
| 19 | public: |
| 20 | Camera() = default; |
| 21 | virtual ~Camera(); |
| 22 | |
| 23 | virtual void doUpdateMatrix(Matrix34f* dst) const = 0; |
| 24 | |
| 25 | void getWorldPosByMatrix(Vector3f* dst) const; |
| 26 | void getLookVectorByMatrix(Vector3f* dst) const; |
| 27 | void getRightVectorByMatrix(Vector3f* dst) const; |
| 28 | void getUpVectorByMatrix(Vector3f* dst) const; |
| 29 | |
| 30 | void worldPosToCameraPosByMatrix(Vector3f* dst, const Vector3f& world_pos) const; |
| 31 | void cameraPosToWorldPosByMatrix(Vector3f* dst, const Vector3f& camera_pos) const; |
| 32 | |
| 33 | void projectByMatrix(Vector2f* dst, const Vector3f& world_pos, const Projection& projection, |
| 34 | const Viewport& viewport) const; |
| 35 | void unprojectRayByMatrix(Ray<Vector3f>* dst, const Vector3f& camera_pos) const; |
| 36 | |
| 37 | Matrix34f& getMatrix() { return mMatrix; } |
| 38 | const Matrix34f& getMatrix() const { return mMatrix; } |
| 39 | |
| 40 | void updateViewMatrix() { doUpdateMatrix(dst: &mMatrix); } |
| 41 | |
| 42 | private: |
| 43 | Matrix34f mMatrix = Matrix34f::ident; |
| 44 | }; |
| 45 | |
| 46 | class LookAtCamera : public Camera |
| 47 | { |
| 48 | SEAD_RTTI_OVERRIDE(LookAtCamera, Camera) |
| 49 | public: |
| 50 | LookAtCamera() = default; |
| 51 | LookAtCamera(const Vector3f& pos, const Vector3f& at, const Vector3f& up); |
| 52 | ~LookAtCamera() override = default; |
| 53 | |
| 54 | void doUpdateMatrix(Matrix34f* dst) const override; |
| 55 | |
| 56 | Vector3f& getPos() { return mPos; } |
| 57 | Vector3f& getAt() { return mAt; } |
| 58 | Vector3f& getUp() { return mUp; } |
| 59 | |
| 60 | const Vector3f& getPos() const { return mPos; } |
| 61 | const Vector3f& getAt() const { return mAt; } |
| 62 | const Vector3f& getUp() const { return mUp; } |
| 63 | |
| 64 | void setPos(const Vector3f& pos) { mPos = pos; } |
| 65 | void setAt(const Vector3f& at) { mAt = at; } |
| 66 | void setUp(const Vector3f& up) { mUp = up; } |
| 67 | |
| 68 | void normalizeUp() { mUp.normalize(); } |
| 69 | void addPos(const Vector3f& pos) { mPos += pos; } |
| 70 | void addAt(const Vector3f& at) { mAt += at; } |
| 71 | |
| 72 | private: |
| 73 | Vector3f mPos = {0.0f, 0.0f, 10.0f}; |
| 74 | Vector3f mAt = {0.0f, 0.0f, 0.0f}; |
| 75 | Vector3f mUp = {0.0f, 1.0f, 0.0f}; |
| 76 | }; |
| 77 | |
| 78 | class DirectCamera : public Camera |
| 79 | { |
| 80 | SEAD_RTTI_OVERRIDE(DirectCamera, Camera) |
| 81 | public: |
| 82 | virtual ~DirectCamera(); |
| 83 | |
| 84 | void doUpdateMatrix(Matrix34f* dst) const override; |
| 85 | |
| 86 | private: |
| 87 | Matrix34f mDirectMatrix = Matrix34f::ident; |
| 88 | }; |
| 89 | |
| 90 | class OrthoCamera : public LookAtCamera |
| 91 | { |
| 92 | SEAD_RTTI_OVERRIDE(OrthoCamera, LookAtCamera) |
| 93 | public: |
| 94 | OrthoCamera(); |
| 95 | OrthoCamera(const Vector2f&, float); |
| 96 | OrthoCamera(const OrthoProjection&); |
| 97 | ~OrthoCamera() override; |
| 98 | |
| 99 | void setByOrthoProjection(const OrthoProjection&); |
| 100 | void setRotation(float rotation); |
| 101 | }; |
| 102 | } // namespace sead |
| 103 | |