8#include "glm/gtc/matrix_transform.hpp"
40 Camera(
const std::vector<Atom> & atoms, uint16_t resX, uint16_t resY,
float fieldOfView)
41 : resX(resX), resY(resY), fieldOfView(fieldOfView)
53 Camera(glm::vec3 positionSpherical, uint16_t resX, uint16_t resY,
float fieldOfView)
54 : resX(resX), resY(resY), fieldOfView(fieldOfView), positionSpherical(positionSpherical)
64 focus = {0.0, 0.0, 0.0};
67 projection = glm::perspective
69 glm::radians(fieldOfView),
float(resX)/
float(resY),
73 invProjection = glm::inverse(projection);
79 glm::vec3(0.0, up, 0.0)
81 invView = glm::inverse(view);
84 invPv = glm::inverse(pv);
93 void reset(
const std::vector<Atom> & atoms)
95 glm::vec3 ext =
extent(atoms);
96 positionSpherical = glm::vec3
98 2.0f*std::max(std::max(ext.x, ext.y), ext.z),
110 void zoom(
float increment) { positionSpherical.x += increment; setView(); }
119 positionSpherical.y += increment*up;
120 if (positionSpherical.y > M_PI || positionSpherical.y < 0.0)
122 positionSpherical.y -= 2.0*increment*up;
124 positionSpherical.z += M_PI;
125 if ( positionSpherical.z < 0) { positionSpherical.z += 2.0*M_PI; }
126 else if ( positionSpherical.z > 2.0*M_PI) { positionSpherical.z = std::fmod(positionSpherical.z, 2.0*M_PI); }
138 positionSpherical.z -= increment;
139 if ( positionSpherical.z < 0) { positionSpherical.z += 2.0*M_PI; }
140 else if ( positionSpherical.z > 2.0*M_PI) { positionSpherical.z = std::fmod(positionSpherical.z, 2.0*M_PI); }
152 this->positionSpherical = positionSpherical;
174 void setUp(
float up) { this->up = up < 0 ? -1.0 : 1.0; setView(); }
191 fieldOfView = std::min(std::max(30.0f, degrees), 90.0f);
235 glm::mat4
getPV()
const {
return pv; }
326 glm::vec3 positionSpherical;
330 glm::mat4 projection;
331 glm::mat4 invProjection;
343 glm::vec3(0.0, up, 0.0)
345 invView = glm::inverse(view);
346 pv = projection*view;
347 invPv = glm::inverse(pv);
glm::vec3 extent(const std::vector< Atom > &atoms)
Calculate the extent of some Atoms.
Definition atom.h:195
A 3D projective camera centered on a focus moving on a sphere.
Definition camera.h:30
void reset()
Set the default view.
Definition camera.h:62
glm::mat4 getInverseView() const
Get the inverse View matrix.
Definition camera.h:228
Camera(glm::vec3 positionSpherical, uint16_t resX, uint16_t resY, float fieldOfView)
Construct a new Camera at a given position.
Definition camera.h:53
int lua_setCameraPosition(lua_State *lua)
Set Camera position.
Definition camera.h:42
void setPosition(glm::vec3 positionSpherical)
Set the camera's position.
Definition camera.h:150
int lua_cameraPosition(lua_State *lua)
Get the Camera position.
Definition camera.h:12
void setUp(float up)
Set the up direction.
Definition camera.h:174
glm::mat4 getProjection() const
Get the Projection matrix.
Definition camera.h:207
int lua_rotateCamera(lua_State *lua)
Rotate the Camera.
Definition camera.h:69
glm::mat4 getInversePV() const
Get the inverse Projection*View matrix.
Definition camera.h:242
uint16_t getResY() const
Definition camera.h:246
glm::mat4 getView() const
Get the View matrix.
Definition camera.h:221
void setFieldOfView(float degrees)
Set the Field Of View.
Definition camera.h:189
int lua_getCameraFieldOfView(lua_State *lua)
Set the field of view.
Definition camera.h:169
glm::vec3 position(bool spherical=false) const
Return the cartesian position vector.
Definition camera.h:163
glm::mat4 getInverseProjection() const
Get the inverse Projection matrix.
Definition camera.h:214
int lua_inclineCamera(lua_State *lua)
Incline the camera.
Definition camera.h:119
void rotate(float increment)
Rotate about the y OpenGL axis.
Definition camera.h:136
float getFieldOfView() const
Get the Field Of View.
Definition camera.h:200
int lua_setCameraFieldOfView(lua_State *lua)
Set the field of view.
Definition camera.h:144
Camera(const std::vector< Atom > &atoms, uint16_t resX, uint16_t resY, float fieldOfView)
Construct a new Camera focussing on some Atoms.
Definition camera.h:40
void reset(const std::vector< Atom > &atoms)
Set the default view.
Definition camera.h:93
void zoom(float increment)
Increment the zoom.
Definition camera.h:110
float getUp() const
Get the up direction.
Definition camera.h:181
uint16_t getResX() const
Definition camera.h:245
void incline(float increment)
Incline about the y OpenGL axis.
Definition camera.h:117
glm::mat4 getPV() const
Get the Projection*View matrix.
Definition camera.h:235
int lua_zoomCamera(lua_State *lua)
Zoom the Camera.
Definition camera.h:94
glm::vec3 spherical2cartesian(glm::vec3 rthetaphi)
convert spherical coordinates to cartesian coordinates.
Definition util.h:63