98 lines
3.0 KiB
C++
98 lines
3.0 KiB
C++
/**
|
|
This file is a part of our_dick
|
|
Copyright (C) 2020 rexy712
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef OUR_DICK_ENGINE_CAMERA_HPP
|
|
#define OUR_DICK_ENGINE_CAMERA_HPP
|
|
|
|
#include "graphics/gl_include.hpp" //GLfloat
|
|
#include "math/math.hpp"
|
|
#include "object.hpp"
|
|
|
|
namespace egn{
|
|
|
|
class camera_iface : public object
|
|
{
|
|
protected:
|
|
enum update{
|
|
VIEW_UPDATE = 8,
|
|
PROJ_UPDATE = 16,
|
|
};
|
|
protected:
|
|
//mutable because they're only really a cached value representation of the data
|
|
//in position, orientation, near, far, etc
|
|
mutable math::mat4<GLfloat> m_projection_matrix; //camera-to-sceen matrix
|
|
mutable math::mat4<GLfloat> m_view_matrix; //world-to-camera matrix
|
|
GLfloat m_near = 1; //near clipping plane in camera space
|
|
GLfloat m_far = 100; //far clipping plane in camera space
|
|
|
|
public:
|
|
camera_iface() = default;
|
|
camera_iface(const math::mat4<GLfloat>& proj, GLfloat n, GLfloat f);
|
|
camera_iface(const camera_iface&) = default;
|
|
camera_iface(camera_iface&&) = default;
|
|
virtual ~camera_iface() = default;
|
|
|
|
camera_iface& operator=(const camera_iface&) = default;
|
|
camera_iface& operator=(camera_iface&&) = default;
|
|
|
|
void set_position(const math::vec3<GLfloat>& pos)override;
|
|
void set_orientation(const math::quaternion<GLfloat>& distance)override;
|
|
|
|
//getters
|
|
const math::mat4<GLfloat>& get_projection_matrix()const;
|
|
const math::mat4<GLfloat>& get_view_matrix()const;
|
|
GLfloat get_near_plane()const;
|
|
GLfloat get_far_plane()const;
|
|
|
|
//setters
|
|
void set_near_plane(GLfloat n);
|
|
void set_far_plane(GLfloat f);
|
|
|
|
protected:
|
|
void recalc_view_matrix()const;
|
|
virtual void recalc_projection_matrix()const = 0;
|
|
};
|
|
|
|
class ortho_camera : public camera_iface
|
|
{
|
|
protected:
|
|
GLfloat m_width, m_height; //width and height of the camera space box
|
|
|
|
public:
|
|
ortho_camera(GLfloat w, GLfloat h, GLfloat n, GLfloat f);
|
|
ortho_camera(const ortho_camera&) = default;
|
|
ortho_camera(ortho_camera&&) = default;
|
|
~ortho_camera() = default;
|
|
|
|
ortho_camera& operator=(const ortho_camera&) = default;
|
|
ortho_camera& operator=(ortho_camera&&) = default;
|
|
|
|
GLfloat get_projection_width()const;
|
|
GLfloat get_projection_height()const;
|
|
|
|
void set_projection_width(GLfloat w);
|
|
void set_projection_height(GLfloat h);
|
|
void set_projection_box(GLfloat w, GLfloat h);
|
|
protected:
|
|
void recalc_projection_matrix()const override;
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|