gramods
Loading...
Searching...
No Matches
Camera.hh
1
2#ifndef GRAMODS_GRAPHICS_CAMERA
3#define GRAMODS_GRAPHICS_CAMERA
4
5#include <gmGraphics/config.hh>
6
7#include <gmGraphics/Eye.hh>
8#include <gmCore/Console.hh>
9
10#include <Eigen/Eigen>
11#include <functional>
12#include <optional>
13
14BEGIN_NAMESPACE_GMGRAPHICS;
15
19class Camera {
20
21public:
25 Camera(size_t frame_number) : frame_number(frame_number) {}
26
27 Camera(const Camera &other)
28 : frame_number(other.frame_number),
29 left(other.left),
30 right(other.right),
31 bottom(other.bottom),
32 top(other.top),
33 near(other.near),
34 far(other.far),
35 position(other.position),
36 orientation(other.orientation),
37 eye(other.eye) {}
38
39 Camera &operator=(const Camera &other) {
40 if (frame_number != other.frame_number)
42 GM_STR("Cannot assign with camera from different frame ("
43 << frame_number << " != " << other.frame_number << ")"));
44
45 left = other.left;
46 right = other.right;
47 bottom = other.bottom;
48 top = other.top;
49 near = other.near;
50 far = other.far;
51 position = other.position;
52 orientation = other.orientation;
53 eye = other.eye;
54
55 return *this;
56 }
57
61 template<class T>
62 Camera(const T &object) : frame_number(object.frame_number) {}
63
68 Eigen::Matrix4f getProjectionMatrix() const;
69
73 Eigen::Affine3f getViewMatrix() const;
74
78 Eigen::Vector3f getPosition() const { return position; }
79
83 void setPosition(Eigen::Vector3f p) { position = p; }
84
88 Eigen::Quaternionf getOrientation() const { return orientation; }
89
93 void setOrientation(Eigen::Quaternionf q) { orientation = q; }
94
100 void setClipPlanes(float l, float r, float b, float t) {
101 left = l;
102 right = r;
103 top = t;
104 bottom = b;
105 }
106
110 void getClipPlanes(float &l, float &r, float &b, float &t) const {
111 l = left;
112 r = right;
113 t = top;
114 b = bottom;
115 }
116
122 void setFieldOfView(float fov_h, float fov_v);
123
130 void setClipAngles(float l, float r, float b, float t);
131
135 void setPose(Eigen::Vector3f p, Eigen::Quaternionf r) {
136 position = p;
137 orientation = r;
138 }
139
145 bool setLookAtPoints(Eigen::Vector3f p,
146 const std::vector<Eigen::Vector3f> &pts,
147 bool symmetric = true,
148 Eigen::Vector3f up = Eigen::Vector3f::Zero());
149
153 void setNearFar(float near, float far) {
154 this->near = near;
155 this->far = far;
156 }
157
161 void setEye(Eye e) { eye = e; }
162
167 Eye getEye() const { return eye; }
168
172 const size_t frame_number;
173
174private:
178 float left = -1.f, right = 1.f, bottom = -1.f, top = 1.f;
179
183 std::optional<float> near, far;
184
188 Eigen::Vector3f position = Eigen::Vector3f::Zero();
189
193 Eigen::Quaternionf orientation = Eigen::Quaternionf::Identity();
194
198 Eye eye = Eye::MONO;
199};
200
201END_NAMESPACE_GMGRAPHICS;
202
203#endif
The base of graphics Camera implementations.
Definition Camera.hh:19
const size_t frame_number
The frame currently being rendered.
Definition Camera.hh:172
void setOrientation(Eigen::Quaternionf q)
Set the orientation of the camera.
Definition Camera.hh:93
void getClipPlanes(float &l, float &r, float &b, float &t) const
Gets the frustum clip planes at a distance of 1.
Definition Camera.hh:110
void setClipPlanes(float l, float r, float b, float t)
Explicitly sets the frustum clip planes at a distance of 1.
Definition Camera.hh:100
Eigen::Vector3f getPosition() const
Get the position of the camera.
Definition Camera.hh:78
Eye getEye() const
Sets which eye the camera is supposed to render.
Definition Camera.hh:167
Camera(size_t frame_number)
Creates a camera for rendering the specified frame number.
Definition Camera.hh:25
void setPose(Eigen::Vector3f p, Eigen::Quaternionf r)
Sets the pose of the camera.
Definition Camera.hh:135
void setPosition(Eigen::Vector3f p)
Set the position of the camera.
Definition Camera.hh:83
void setEye(Eye e)
Sets which eye the camera is supposed to render.
Definition Camera.hh:161
void setNearFar(float near, float far)
Sets the near and far planes.
Definition Camera.hh:153
Eigen::Quaternionf getOrientation() const
Get the orientation of the camera.
Definition Camera.hh:88
Camera(const T &object)
Creates a camera copying frame number from another object.
Definition Camera.hh:62
Standard exception for invalid arguments in a call to a function or object.
Definition InvalidArgument.hh:15
An indexed eye that can be rendered.
Definition Eye.hh:20