80 lines
2.7 KiB
C++
80 lines
2.7 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 "gfx/ogl/gl_include.hpp" //GLfloat
|
|
#include "math/math.hpp"
|
|
#include "base_types.hpp"
|
|
|
|
namespace egn{
|
|
|
|
class object_base
|
|
{
|
|
protected:
|
|
enum update{
|
|
NO_UPDATE,
|
|
SCALE_UPDATE = 1,
|
|
TRANSLATION_UPDATE = 2,
|
|
ROTATION_UPDATE = 4,
|
|
BOUNDING_VOLUME_UPDATE = 8,
|
|
};
|
|
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
|
|
private:
|
|
mutable math::mat4<GLfloat> m_model_matrix; //compile all the above info into a matrix
|
|
protected:
|
|
mutable int m_update_flag = NO_UPDATE; //whether or not to update the matrix upon access
|
|
//make the update flag protected so subclasses can share it
|
|
|
|
public:
|
|
object_base() = default;
|
|
explicit object_base(const math::vec3<GLfloat>& position);
|
|
object_base(const math::vec3<GLfloat>& position, const math::quaternion<GLfloat>& orientation);
|
|
object_base(const object_base&) = default;
|
|
object_base(object_base&&) = default;
|
|
virtual ~object_base() = default;
|
|
|
|
object_base& operator=(const object_base&) = default;
|
|
object_base& operator=(object_base&&) = 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>& model_matrix()const;
|
|
const math::vec3<GLfloat>& position()const;
|
|
const math::vec3<GLfloat>& scale()const;
|
|
const math::quaternion<GLfloat>& orientation()const;
|
|
|
|
protected:
|
|
void recalc_model_matrix()const;
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|