diff --git a/src/core/include/pw/core/rectangle.hpp b/src/core/include/pw/core/rectangle.hpp index afdea20..fc37d17 100644 --- a/src/core/include/pw/core/rectangle.hpp +++ b/src/core/include/pw/core/rectangle.hpp @@ -23,6 +23,8 @@ #ifndef PW_CORE_RECT_HPP #define PW_CORE_RECT_HPP +#include + #include #include @@ -31,21 +33,27 @@ namespace pw { template struct rectangle_ { - size_ size; - point_ position; + point_ position; + size_ size; - rectangle_() = default; + rectangle_() = default; - rectangle_(point_ const & p,size_ const & s) : size(s), position(p) {} + rectangle_(const T_(&l)[4]) + { + position.x = l[0]; position.y = l[1]; + size.width = l[2]; size.height = l[3]; + } - bool contains(const point_& p) const noexcept + rectangle_(point_ const & p,size_ const & s) : size(s), position(p) {} + + bool contains(const point_& p) const noexcept { return p.x >= position.x && p.x <= position.x + size.width && - p.y >= position.y && p.y <= position.y + size.height; + p.y >= position.y && p.y <= position.y + size.height; } template - rectangle_ cast() const { return rectangle_(position.template cast(),size.template cast()); } + rectangle_ cast() const { return rectangle_(position.template cast(),size.template cast()); } }; diff --git a/src/scene/CMakeLists.txt b/src/scene/CMakeLists.txt index 4b9ef6a..e8da538 100644 --- a/src/scene/CMakeLists.txt +++ b/src/scene/CMakeLists.txt @@ -8,6 +8,7 @@ set(hdrs_components include/pw/scene/components/relationship.hpp include/pw/scene/components/transform.hpp include/pw/scene/components/projection.hpp + include/pw/scene/components/camera.hpp ) set(srcs diff --git a/src/scene/include/pw/scene/entity.hpp b/src/scene/include/pw/scene/entity.hpp index 5d32725..29e6f0c 100644 --- a/src/scene/include/pw/scene/entity.hpp +++ b/src/scene/include/pw/scene/entity.hpp @@ -142,9 +142,8 @@ private: } - - #include #include +#include #endif diff --git a/src/scene/src/scene.cpp b/src/scene/src/scene.cpp index 498b4ee..eeed05d 100644 --- a/src/scene/src/scene.cpp +++ b/src/scene/src/scene.cpp @@ -4,8 +4,23 @@ #include "pw/core/debug.hpp" #include "pw/core/serialize.hpp" +#include "pw/core/geometry.hpp" +#include "pw/core/matrix_transform.hpp" + namespace pw { + +struct mesh { + geometry geom; +}; + +struct mesh_renderer { + std::unique_ptr state; +// std::vector mat; +}; + + + scene::scene() : _registry{ std::make_shared()} { @@ -24,6 +39,9 @@ size_t scene::count_alive_enties() const void scene::update_transforms() { + + //auto [t,r] = view.get(entity); + #if 1 // search for nodes with parent and transform (only find leaf nodes) @@ -33,63 +51,60 @@ void scene::update_transforms() { debug::d() << "info for entity " << (int)entity; - //auto [t,r] = view.get(entity); - - // collect node path + // collect node path std::vector path; while (_registry->has(entity)) { - if (_registry->has(entity)) { path.push_back(_registry->get(entity)); } - + // entity = _registry->get(entity).entity; } - debug::d() << "\tpath length " << path.size(); - std::reverse(path.begin(),path.end()); auto m = pw::matrix4x4::identity(); for (auto& transform : path) { + transform._global = transform._local * m; m = transform._global; debug::d() << pw::serialize::matrix(m); } - - -// r = _registry->view - + // r = _registry->view } + + + + #else -// auto view = _registry->view(); + // auto view = _registry->view(); -// for (auto e : view) { + // for (auto e : view) { -// const auto& r = view.get(e); + // const auto& r = view.get(e); -// if (r.children.size() && r.parent == entt::null) { -// debug::d() << "root '" << (int)e << "'"; -// } + // if (r.children.size() && r.parent == entt::null) { + // debug::d() << "root '" << (int)e << "'"; + // } -//// debug::d() << __PRETTY_FUNCTION__ << " " << view.get(e).children.size(); + //// debug::d() << __PRETTY_FUNCTION__ << " " << view.get(e).children.size(); -//// if -// } + //// if + // } #endif -// auto vr = _registry->view(); + // auto vr = _registry->view(); -// for (auto [rel] : vr) { + // for (auto [rel] : vr) { -// } + // } } diff --git a/src/visual/include/pw/visual/shader.hpp b/src/visual/include/pw/visual/shader.hpp index a11681b..11a5435 100644 --- a/src/visual/include/pw/visual/shader.hpp +++ b/src/visual/include/pw/visual/shader.hpp @@ -61,7 +61,7 @@ public: protected: - std::map _source; + std::unordered_map _source; struct impl; std::unique_ptr _impl; diff --git a/src/visual/include/pw/visual/vertex_array.hpp b/src/visual/include/pw/visual/vertex_array.hpp index 0e2987c..d648944 100644 --- a/src/visual/include/pw/visual/vertex_array.hpp +++ b/src/visual/include/pw/visual/vertex_array.hpp @@ -12,12 +12,12 @@ class geometry; /** * @brief Connects mesh data with the render backend */ -class vertex_array { +class mesh_renderer { public: - vertex_array(); - vertex_array(const geometry& m); + mesh_renderer(); + mesh_renderer(const geometry& m); - ~vertex_array(); + ~mesh_renderer(); void create(const geometry &m); void release(); diff --git a/src/visual/src/pipeline.cpp b/src/visual/src/pipeline.cpp index 20259a5..96ec433 100644 --- a/src/visual/src/pipeline.cpp +++ b/src/visual/src/pipeline.cpp @@ -40,7 +40,7 @@ struct triangle_renderer shader shader_p; geometry amesh; - vertex_array amesh_renderer; + mesh_renderer amesh_renderer; time::tick_t tick; triangle_renderer() diff --git a/src/visual/src/texture.cpp b/src/visual/src/texture.cpp index a184c44..115767a 100644 --- a/src/visual/src/texture.cpp +++ b/src/visual/src/texture.cpp @@ -12,10 +12,12 @@ struct texture::impl { GLuint _texture_id; GLuint _texture_sampler; + impl() = delete; + impl(texture& host) : _host(host) { - } + } GLuint gl_shape() { switch (_host.shape()) { diff --git a/src/visual/src/vertex_array.cpp b/src/visual/src/vertex_array.cpp index 8e714b0..dfb9a87 100644 --- a/src/visual/src/vertex_array.cpp +++ b/src/visual/src/vertex_array.cpp @@ -11,7 +11,7 @@ namespace pw { -struct vertex_array::impl { +struct mesh_renderer::impl { GLuint _vao = 0; @@ -73,7 +73,8 @@ struct vertex_array::impl { // indices glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vbos[1]); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(m.indices().front()) * m.indices().size(), m.indices().data(), + glBufferData(GL_ELEMENT_ARRAY_BUFFER, + sizeof(m.indices().front()) * m.indices().size(), m.indices().data(), GL_STATIC_DRAW); // stop binding @@ -120,37 +121,37 @@ struct vertex_array::impl { // // -vertex_array::vertex_array() - : _impl(std::make_unique()) +mesh_renderer::mesh_renderer() + : _impl(std::make_unique()) { } -vertex_array::vertex_array(const geometry &m) +mesh_renderer::mesh_renderer(const geometry &m) { - vertex_array(); + mesh_renderer(); _impl->create(m); } -vertex_array::~vertex_array() +mesh_renderer::~mesh_renderer() { } -bool vertex_array::ready() const +bool mesh_renderer::ready() const { return _impl->ready(); } -void vertex_array::create(const geometry &m) +void mesh_renderer::create(const geometry &m) { _impl->create(m); } -void vertex_array::release() +void mesh_renderer::release() { _impl->release(); } -void vertex_array::draw() +void mesh_renderer::draw() { _impl->draw(); }