/** 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 . */ #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 m_position; //track current positon in world space math::quaternion m_orientation; //track current model space rotation math::vec3 m_scale{1.0f, 1.0f, 1.0f}; //track model space scale private: mutable math::mat4 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& position); object_base(const math::vec3& position, const math::quaternion& 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& distance); void rotate(const math::quaternion& distance); void scale(const math::vec3& distance); void look_at(const math::vec3& targ, const math::vec3& up); virtual void set_position(const math::vec3& pos); virtual void set_orientation(const math::quaternion& orient); virtual void set_scale(const math::vec3& scale); const math::mat4& model_matrix()const; const math::vec3& position()const; const math::vec3& scale()const; const math::quaternion& orientation()const; protected: void recalc_model_matrix()const; }; } #endif