@@ -37,8 +37,8 @@ class Camera
3737 * @param resX the screen resolution width.
3838 * @param resY the screen resolution in height.
3939 */
40- Camera (const std::vector<Atom> & atoms, uint16_t resX, uint16_t resY)
41- : resX(resX), resY(resY)
40+ Camera (const std::vector<Atom> & atoms, uint16_t resX, uint16_t resY, float fieldOfView )
41+ : resX(resX), resY(resY), fieldOfView(fieldOfView)
4242 {
4343 reset (atoms);
4444 }
@@ -50,8 +50,8 @@ class Camera
5050 * @param resX the screen resolution width.
5151 * @param resY the screen resolution in height.
5252 */
53- Camera (glm::vec3 positionSpherical, uint16_t resX, uint16_t resY)
54- : resX(resX), resY(resY), positionSpherical(positionSpherical)
53+ Camera (glm::vec3 positionSpherical, uint16_t resX, uint16_t resY, float fieldOfView )
54+ : resX(resX), resY(resY), fieldOfView(fieldOfView), positionSpherical(positionSpherical)
5555 {
5656 reset ();
5757 }
@@ -66,7 +66,7 @@ class Camera
6666
6767 projection = glm::perspective
6868 (
69- glm::radians (45 . 0f ), float (resX)/float (resY),
69+ glm::radians (fieldOfView ), float (resX)/float (resY),
7070 0 .1f ,
7171 1000 .0f
7272 );
@@ -180,6 +180,25 @@ class Camera
180180 */
181181 float getUp () const { return up; }
182182
183+ /* *
184+ * @brief Set the Field Of View
185+ *
186+ * @param degrees the field of view in degrees.
187+ * @remark clipped to [30, 90].
188+ */
189+ void setFieldOfView (float degrees)
190+ {
191+ fieldOfView = std::min (std::max (30 .0f , degrees), 90 .0f );
192+ reset ();
193+ }
194+
195+ /* *
196+ * @brief Get the Field Of View
197+ *
198+ * @return float the field of view in degrees.
199+ */
200+ float getFieldOfView () const { return fieldOfView; }
201+
183202 /* *
184203 * @brief Get the Projection matrix.
185204 *
@@ -278,10 +297,31 @@ class Camera
278297 */
279298 inline int lua_inclineCamera (lua_State * lua);
280299
300+ /* *
301+ * @brief Set the field of view.
302+ *
303+ * @remark Lua arguments are:
304+ * 1. Field of view in degrees.
305+ * @param lua the Lua context.
306+ * @return int the return code.
307+ */
308+ inline int lua_setCameraFieldOfView (lua_State * lua);
309+
310+ /* *
311+ * @brief Set the field of view.
312+ *
313+ * @remark Lua arguments are:
314+ * 1. Field of view in degrees.
315+ * @param lua the Lua context.
316+ * @return int the return code.
317+ */
318+ inline int lua_getCameraFieldOfView (lua_State * lua);
319+
281320private:
282321
283322 uint16_t resX;
284323 uint16_t resY;
324+ float fieldOfView;
285325
286326 glm::vec3 positionSpherical;
287327 glm::vec3 focus;
0 commit comments