diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1063ae2..ccd9945 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,12 +4,12 @@ add_subdirectory(deps) # build internal core add_subdirectory(core) add_subdirectory(scene) -add_subdirectory(system) -add_subdirectory(io) +# add_subdirectory(system) +# add_subdirectory(io) #add_subdirectory(ui) -add_subdirectory(binding) -add_subdirectory(visual) +# add_subdirectory(binding) +# add_subdirectory(visual) # add_subdirectory(geometry) -add_subdirectory(runtime) +# add_subdirectory(runtime) diff --git a/src/scene/include/pw/scene/components/camera.hpp b/src/scene/include/pw/scene/components/camera.hpp index ac1298a..645f832 100644 --- a/src/scene/include/pw/scene/components/camera.hpp +++ b/src/scene/include/pw/scene/components/camera.hpp @@ -33,8 +33,8 @@ namespace pw { struct camera { matrix4x4f projection = matrix4x4f::identity(); - matrix4x4f view = matrix_transform::look_at(vector3f{}, vector3f::x_axis(), - vector3f::y_axis()); + matrix4x4f view = matrix_transform::look_at_matrix( + vector3f{}, vector3f::x_axis(), vector3f::y_axis()); matrix4x4f viewport = pw::rectangle{{0.f, 0.f} {1.f, 1.f}}; diff --git a/src/scene/include/pw/scene/components/relationship.hpp b/src/scene/include/pw/scene/components/relationship.hpp index 94dc6c4..5b3049f 100644 --- a/src/scene/include/pw/scene/components/relationship.hpp +++ b/src/scene/include/pw/scene/components/relationship.hpp @@ -25,7 +25,6 @@ #ifndef PW_SCENE_COMPONENTS_RELATIONSHIP_HPP #define PW_SCENE_COMPONENTS_RELATIONSHIP_HPP - #include namespace pw { @@ -34,22 +33,16 @@ namespace pw { * @brief entity relations are hidden and managed by the entity itself */ struct parent { - parent() = default; - parent(const parent&) = default; - entt::entity entity { entt::null }; + entt::entity entity{entt::null}; operator bool() const { return entity != entt::null; } }; struct children { - children() = default; - children(const children&) = default; - std::vector entities; }; - -} +} // namespace pw #endif diff --git a/src/scene/include/pw/scene/components/transform.hpp b/src/scene/include/pw/scene/components/transform.hpp index bf42d01..af940fd 100644 --- a/src/scene/include/pw/scene/components/transform.hpp +++ b/src/scene/include/pw/scene/components/transform.hpp @@ -33,12 +33,12 @@ struct transform final { } inline transform& rotate(const quaternionf& q) { - _local = _local * q.to_matrix(); + _local = _local * q.to_matrix().unproject(1); return *this; } inline transform& set_rotation(const quaternionf& q) { - _local = q.to_matrix(); + _local = q.to_matrix().unproject(1); return *this; } diff --git a/src/scene/include/pw/scene/entity.hpp b/src/scene/include/pw/scene/entity.hpp index bcdc203..ff14ef9 100644 --- a/src/scene/include/pw/scene/entity.hpp +++ b/src/scene/include/pw/scene/entity.hpp @@ -150,6 +150,6 @@ private: #include #include -#include +// #include #endif diff --git a/src/scene/include/pw/scene/scene.hpp b/src/scene/include/pw/scene/scene.hpp index 389d8dd..a89a6d5 100644 --- a/src/scene/include/pw/scene/scene.hpp +++ b/src/scene/include/pw/scene/scene.hpp @@ -33,9 +33,7 @@ namespace pw { class entity; -class scene { -public: - +struct scene final { using registry = entt::registry; diff --git a/src/scene/src/entity.cpp b/src/scene/src/entity.cpp index 5a914ae..8d89992 100644 --- a/src/scene/src/entity.cpp +++ b/src/scene/src/entity.cpp @@ -7,7 +7,6 @@ namespace pw { namespace detail { - // entity identiy is hidden struct identity { @@ -15,25 +14,23 @@ struct identity { identity(const std::string& name) : name(name) {} identity(const identity&) = default; - bool enabled = true; - std::string name = ""; - std::vector tags = {}; + bool enabled = true; + std::string name = ""; + std::vector tags = {}; std::vector layers = {}; }; -} +} // namespace detail -entity::entity(scene &s,const std::string& name) - : _registry(s._registry) - , _entity(s._registry ? _registry->create() : entt::null) -{ +entity::entity(scene& s, const std::string& name) + : _registry(s._registry), + _entity(s._registry ? _registry->create() : entt::null) { if (s._registry) { this->add_component(name); } } -bool entity::add_child(entity &child) -{ +bool entity::add_child(entity& child) { // not mixing scenes (yet) if (child._registry != this->_registry) { debug::e() << "Cannot mix entities from different scenes"; @@ -47,14 +44,13 @@ bool entity::add_child(entity &child) c.entities.push_back(child._entity); // declare parent - auto& p_r = child.get_or_create_component(); + auto& p_r = child.get_or_create_component(); p_r.entity = _entity; return true; } -bool entity::remove_child(entity& child) -{ +bool entity::remove_child(entity& child) { // not mixing scenes (yet) if (child._registry != this->_registry) { debug::e() << "Cannot mix entities from different scenes"; @@ -62,19 +58,17 @@ bool entity::remove_child(entity& child) } // both need to have a relationship component - if (child.has_component() && - this->has_component()) - { + if (child.has_component() && this->has_component()) { // we need to check if the child is related to the parent auto r_p = child.get_component(); - if (r_p.entity == _entity) - { + if (r_p.entity == _entity) { // now go ahead delete parent r_p.entity = entt::null; // now remove all children auto& c = this->get_component(); - c.entities.erase(std::remove(c.entities.begin(),c.entities.end(),child._entity)); + c.entities.erase(std::remove(c.entities.begin(), c.entities.end(), + child._entity)); // flag success return true; @@ -83,38 +77,24 @@ bool entity::remove_child(entity& child) return false; } - -size_t entity::child_count() const -{ - return this->has_component() ? - get_component().entities.size() : - 0; +size_t entity::child_count() const { + return this->has_component() + ? get_component().entities.size() + : 0; } - -void entity::set_name(const std::string& n) -{ - auto &ident = get_or_create_component(); - ident.name = n; +void entity::set_name(const std::string& n) { + auto& ident = get_or_create_component(); + ident.name = n; } -std::string entity::name() -{ - auto &ident = get_or_create_component(); +std::string entity::name() { + auto& ident = get_or_create_component(); return ident.name; } +entity::~entity() { this->destroy(); } +void entity::destroy() { _registry->destroy(_entity); } -entity::~entity() -{ - this->destroy(); -} - -void entity::destroy() -{ - _registry->destroy(_entity); -} - -} - +} // namespace pw diff --git a/src/scene/src/scene.cpp b/src/scene/src/scene.cpp index 0194622..f1d4787 100644 --- a/src/scene/src/scene.cpp +++ b/src/scene/src/scene.cpp @@ -4,23 +4,11 @@ #include "pw/core/debug.hpp" #include "pw/core/serialize.hpp" -#include "pw/core/geometry.hpp" +#include "pw/core/mesh.hpp" #include "pw/core/matrix_transform.hpp" namespace pw { - -struct mesh { - geometry geom; -}; - -struct renderer { - std::unique_ptr state; -// std::vector mat; -}; - - - scene::scene() : _registry{ std::make_shared()} { @@ -39,7 +27,7 @@ void scene::update_transforms() //auto [t,r] = view.get(entity); -#if 1 +#if 0 // search for nodes with parent and transform (only find leaf nodes) auto view = _registry->view(entt::exclude); @@ -61,7 +49,7 @@ void scene::update_transforms() debug::d() << "\tpath length " << path.size(); std::reverse(path.begin(),path.end()); - auto m = pw::matrix4x4::identity(); + auto m = pw::matrix4x4f::identity(); for (auto& transform : path) {