our_dick/include/engine/object.hpp

75 lines
2.5 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_OBJECT_HPP
#define OUR_DICK_ENGINE_OBJECT_HPP
#include "graphics/gl_include.hpp" //GLfloat
#include "math/math.hpp"
namespace egn{
class object
{
protected:
enum update{
NO_UPDATE,
SCALE_UPDATE = 1,
TRANSLATION_UPDATE = 2,
ROTATION_UPDATE = 4,
};
protected:
math::vec3<GLfloat> m_position; //track current positon in world space
math::quaternion<GLfloat> m_orientation; //track current model space rotation
math::vec3<GLfloat> m_scale{1.0f, 1.0f, 1.0f}; //track model space scale
mutable math::mat4<GLfloat> m_model_matrix; //compile all the above info into a matrix
mutable int m_update_flag = NO_UPDATE; //whether or not to update the matrix upon access
public:
object() = default;
explicit object(const math::vec3<GLfloat>& position);
object(const math::vec3<GLfloat>& position, const math::quaternion<GLfloat>& orientation);
object(const object&) = default;
object(object&&) = default;
virtual ~object() = default;
object& operator=(const object&) = default;
object& operator=(object&&) = default;
void translate(const math::vec3<GLfloat>& distance);
void rotate(const math::quaternion<GLfloat>& distance);
void scale(const math::vec3<GLfloat>& distance);
void look_at(const math::vec3<GLfloat>& targ, const math::vec3<GLfloat>& up);
virtual void set_position(const math::vec3<GLfloat>& pos);
virtual void set_orientation(const math::quaternion<GLfloat>& orient);
virtual void set_scale(const math::vec3<GLfloat>& scale);
const math::mat4<GLfloat>& get_model_matrix()const;
const math::vec3<GLfloat>& get_position()const;
const math::vec3<GLfloat>& get_scale()const;
const math::quaternion<GLfloat>& get_orientation()const;
protected:
void recalc_model_matrix()const;
};
}
#endif