aboutsummaryrefslogtreecommitdiff
path: root/apps/openmb/scene/Camera.hpp
blob: 7c5edc759045ea352bc539e88fb3b79672c00fcb (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once

#include <glm/glm.hpp>
#include <utility>
#include <vector>

namespace scene {
enum class Movement {
    Forward,
    Backward,
    Left,
    Right,
    Up,
    Down
};

class Camera {
  public:
    Camera();
    Camera( const glm::vec3& position, const glm::vec3& up, float yaw, float pitch );

    glm::mat4 getViewMatrix() const;
    glm::mat4 getProjectionMatrix( float aspect ) const;

    void processKeyboard( Movement dir, float deltaTime );
    void processMouseMovement( float xoffset, float yoffset, bool constrainPitch = true );
    void processMouseScroll( float yoffset );

    void toggleFly();
    void setSpeedMultiplier( float m );
    void jump();

    bool  isFlying() const;
    bool  isGrounded() const;
    float getSpeedMultiplier() const;

    void updatePhysics( float deltaTime, const std::vector<std::pair<glm::vec3, glm::vec3>>& worldAABBs,
                        float floorY = 0.0f );

    glm::vec3 position () const { return mPosition; }

    float getPitch () const { return mPitch; }

    float getYaw () const { return mYaw; }

  private:
    void updateCameraVectors();

  private:
    glm::vec3 mPosition;
    glm::vec3 mFront;
    glm::vec3 mUp;
    glm::vec3 mRight;
    glm::vec3 mWorldUp;

    float mYaw;
    float mPitch;

    float mMovementSpeed;
    float mMouseSensitivity;
    float mFov;

    glm::vec3 mVelocity;
    bool      mFlying;
    bool      mGrounded;
    float     mSpeedMultiplier;
};

}   // namespace scene