AGL
A graphics library
camera.h
1 // Copyright 2009-2020, Savvy Sine, Aline Normoyle
2 
3 #ifndef AGL_CAMERA_H_
4 #define AGL_CAMERA_H_
5 
6 #include "agl/aglm.h"
7 
8 namespace agl {
9 
19 class Camera {
20  public:
21  Camera();
22  virtual ~Camera();
23 
24  // Print eyepoint position and basis
25  virtual void print();
26 
27  // Initialize the camera with gluLookAt parameters
28  virtual void set(const glm::vec3& eyepos,
29  const glm::vec3& look = glm::vec3(0, 0, 0),
30  const glm::vec3& up = glm::vec3(0, 1, 0));
31 
34  virtual const glm::mat4& viewMatrix() const;
36  virtual const glm::vec3& position() const;
37  virtual const glm::vec3& look() const;
38  virtual const glm::vec3& up() const;
39  virtual const glm::vec3& backward() const;
40  virtual const glm::vec3& right() const;
41  virtual float heading() const;
42  virtual float pitch() const;
44 
47  void onMouseMotion(int x, int y); // x and y in screen coords
49  void onMouseButton(int button, int state, int x, int y);
50  void onKeyboard(int key, int scancode, int action, int mods);
51  void onScroll(float dx, float dy);
53 
56  void moveLeft(float scale = 1.0);
58  void moveRight(float scale = 1.0);
59  void moveUp(float scale = 1.0);
60  void moveDown(float scale = 1.0);
61  void moveForward(float scale = 1.0);
62  void moveBack(float scale = 1.0);
63 
64  void turnLeft(float scale = 1.0);
65  void turnRight(float scale = 1.0);
66  void turnUp(float scale = 1.0);
67  void turnDown(float scale = 1.0);
68 
69  void orbitLeft(float scale = 1.0);
70  void orbitRight(float scale = 1.0);
71  void orbitUp(float scale = 1.0);
72  void orbitDown(float scale = 1.0);
73 
74  void setTurnRate(float rate);
75  float turnRate() const;
76 
77  void setMoveSpeed(float rate);
78  float moveSpeed() const;
80 
81  protected:
82  virtual void turn(glm::vec3* v, glm::vec3* n, float amount);
83  virtual void move(float dU, float dV, float dN);
84  virtual void orbit(float h, float p);
85  virtual void reset();
86  virtual void _set(const glm::vec3& eyepos,
87  const glm::vec3& look,
88  const glm::vec3& up);
89 
90  protected:
91  float mSpeed, mTurnRate;
92 
93  glm::vec3 mEye, mLook, mUp; // camera position
94  float mHeading, mPitch, mRadius;
95  glm::vec3 mResetEye, mResetLook, mResetUp; // cached camera position
96 
97  // Basis of camera local coord system
98  glm::vec3 mU; // up
99  glm::vec3 mV; // v points right
100  glm::vec3 mN; // -n points forward
101 
102  // Cache useful values
103  glm::mat4 mCameraMatrix;
104 
105  // Mouse input
106  mutable int mLastX, mLastY;
107  int mButtonState;
108  int mModifierState;
109 };
110 
111 } // namespace agl
112 #endif // AGL_CAMERA_H_
agl::Camera
Implements orbit and pan camera movement.
Definition: camera.h:19
aglm.h
Global utilities and common third party includes.