79 lines
2.4 KiB
C++
79 lines
2.4 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 <rml/math.hpp>
|
|
#include "base_types.hpp"
|
|
|
|
namespace egn{
|
|
|
|
class object
|
|
{
|
|
protected:
|
|
enum update{
|
|
NO_UPDATE,
|
|
SCALE_UPDATE = 1,
|
|
TRANSLATION_UPDATE = 2,
|
|
ROTATION_UPDATE = 4,
|
|
BOUNDING_VOLUME_UPDATE = 8,
|
|
};
|
|
protected:
|
|
rml::vec3f m_position; //track current positon in world space
|
|
rml::quat_f m_orientation; //track current model space rotation
|
|
rml::vec3f m_scale{1.0f, 1.0f, 1.0f}; //track model space scale
|
|
private:
|
|
mutable rml::mat4f 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(void) = default;
|
|
explicit object(const rml::vec3f& position);
|
|
object(const rml::vec3f& position, const rml::quat_f& orientation);
|
|
object(const object&) = default;
|
|
object(object&&) = default;
|
|
virtual ~object(void) = default;
|
|
|
|
object& operator=(const object&) = default;
|
|
object& operator=(object&&) = default;
|
|
|
|
void translate(const rml::vec3f& distance);
|
|
void rotate(const rml::quat_f& distance);
|
|
void scale(const rml::vec3f& distance);
|
|
void look_at(const rml::vec3f& targ, const rml::vec3f& up);
|
|
|
|
virtual void set_position(const rml::vec3f& pos);
|
|
virtual void set_orientation(const rml::quat_f& orient);
|
|
virtual void set_scale(const rml::vec3f& scale);
|
|
|
|
const rml::mat4f& model_matrix(void)const;
|
|
const rml::vec3f& position(void)const;
|
|
const rml::vec3f& scale(void)const;
|
|
const rml::quat_f& orientation(void)const;
|
|
|
|
protected:
|
|
void recalc_model_matrix(void)const;
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|