summaryrefslogtreecommitdiff
path: root/wave-sim/src/graphics/camera.h
blob: 04586afcdf1ef301619c7433be733626b748efeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once

#include "Eigen/Dense"

class Camera
{
public:
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
    Camera();

    void setPosition(const Eigen::Vector3f      &position);
    void move       (const Eigen::Vector3f &deltaPosition);

    void setRotation(float      pitch, float      yaw);
    void rotate     (float deltaPitch, float deltaYaw);

    void lookAt(const Eigen::Vector3f &eye, const Eigen::Vector3f &target);

    void setOrbitPoint(const Eigen::Vector3f &target);
    bool getIsOrbiting();
    void setIsOrbiting(bool orbit);
    void toggleIsOrbiting();
    void zoom(float zoomMultiplier);

    const Eigen::Matrix4f &getView();
    const Eigen::Matrix4f &getProjection();
    const Eigen::Vector3f &getLook();

    void setPerspective(float fovY, float aspect, float near, float far);
    void setAspect(float aspect);

private:
    void updateLook();
    void updatePitchAndYaw();

    // Do not mess with the order of these variables. Some Eigen voodoo will cause an inexplicable crash.

    Eigen::Vector3f m_position;

    float m_pitch, m_yaw;
    Eigen::Vector3f m_look;

    Eigen::Vector3f m_orbitPoint;
    bool m_isOrbiting;

    Eigen::Matrix4f m_view, m_proj;
    bool m_viewDirty, m_projDirty;

    float m_fovY, m_aspect, m_near, m_far;
    float m_zoom;
};