update to add more functionality to the ECS and connect it to the rendering system
Signed-off-by: Hartmut Seichter <hartmut@technotecture.com>
This commit is contained in:
parent
a4f9308aa7
commit
8253756e4c
9 changed files with 76 additions and 50 deletions
|
@ -23,6 +23,8 @@
|
||||||
#ifndef PW_CORE_RECT_HPP
|
#ifndef PW_CORE_RECT_HPP
|
||||||
#define PW_CORE_RECT_HPP
|
#define PW_CORE_RECT_HPP
|
||||||
|
|
||||||
|
#include <initializer_list>
|
||||||
|
|
||||||
#include <pw/core/point.hpp>
|
#include <pw/core/point.hpp>
|
||||||
#include <pw/core/size.hpp>
|
#include <pw/core/size.hpp>
|
||||||
|
|
||||||
|
@ -31,21 +33,27 @@ namespace pw {
|
||||||
template <typename T_>
|
template <typename T_>
|
||||||
struct rectangle_ {
|
struct rectangle_ {
|
||||||
|
|
||||||
size_<T_> size;
|
point_<T_> position;
|
||||||
point_<T_> position;
|
size_<T_> size;
|
||||||
|
|
||||||
rectangle_() = default;
|
rectangle_() = default;
|
||||||
|
|
||||||
rectangle_(point_<T_> const & p,size_<T_> 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_<T_>& p) const noexcept
|
rectangle_(point_<T_> const & p,size_<T_> const & s) : size(s), position(p) {}
|
||||||
|
|
||||||
|
bool contains(const point_<T_>& p) const noexcept
|
||||||
{
|
{
|
||||||
return p.x >= position.x && p.x <= position.x + size.width &&
|
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 <typename To_>
|
template <typename To_>
|
||||||
rectangle_<To_> cast() const { return rectangle_<To_>(position.template cast<To_>(),size.template cast<To_>()); }
|
rectangle_<To_> cast() const { return rectangle_<To_>(position.template cast<To_>(),size.template cast<To_>()); }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ set(hdrs_components
|
||||||
include/pw/scene/components/relationship.hpp
|
include/pw/scene/components/relationship.hpp
|
||||||
include/pw/scene/components/transform.hpp
|
include/pw/scene/components/transform.hpp
|
||||||
include/pw/scene/components/projection.hpp
|
include/pw/scene/components/projection.hpp
|
||||||
|
include/pw/scene/components/camera.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(srcs
|
set(srcs
|
||||||
|
|
|
@ -142,9 +142,8 @@ private:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <pw/scene/components/relationship.hpp>
|
#include <pw/scene/components/relationship.hpp>
|
||||||
#include <pw/scene/components/transform.hpp>
|
#include <pw/scene/components/transform.hpp>
|
||||||
|
#include <pw/scene/components/camera.hpp>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,8 +4,23 @@
|
||||||
#include "pw/core/debug.hpp"
|
#include "pw/core/debug.hpp"
|
||||||
#include "pw/core/serialize.hpp"
|
#include "pw/core/serialize.hpp"
|
||||||
|
|
||||||
|
#include "pw/core/geometry.hpp"
|
||||||
|
#include "pw/core/matrix_transform.hpp"
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
|
|
||||||
|
struct mesh {
|
||||||
|
geometry geom;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct mesh_renderer {
|
||||||
|
std::unique_ptr<int> state;
|
||||||
|
// std::vector<matrials> mat;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
scene::scene()
|
scene::scene()
|
||||||
: _registry{ std::make_shared<entt::registry>()}
|
: _registry{ std::make_shared<entt::registry>()}
|
||||||
{
|
{
|
||||||
|
@ -24,6 +39,9 @@ size_t scene::count_alive_enties() const
|
||||||
void scene::update_transforms()
|
void scene::update_transforms()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
//auto [t,r] = view.get<transform,parent>(entity);
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
|
|
||||||
// search for nodes with parent and transform (only find leaf nodes)
|
// 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;
|
debug::d() << "info for entity " << (int)entity;
|
||||||
|
|
||||||
//auto [t,r] = view.get<transform,parent>(entity);
|
// collect node path
|
||||||
|
|
||||||
// collect node path
|
|
||||||
std::vector<transform> path;
|
std::vector<transform> path;
|
||||||
while (_registry->has<parent>(entity)) {
|
while (_registry->has<parent>(entity)) {
|
||||||
|
|
||||||
if (_registry->has<transform>(entity)) {
|
if (_registry->has<transform>(entity)) {
|
||||||
path.push_back(_registry->get<transform>(entity));
|
path.push_back(_registry->get<transform>(entity));
|
||||||
}
|
}
|
||||||
|
//
|
||||||
entity = _registry->get<parent>(entity).entity;
|
entity = _registry->get<parent>(entity).entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
debug::d() << "\tpath length " << path.size();
|
debug::d() << "\tpath length " << path.size();
|
||||||
|
|
||||||
std::reverse(path.begin(),path.end());
|
std::reverse(path.begin(),path.end());
|
||||||
|
|
||||||
auto m = pw::matrix4x4::identity();
|
auto m = pw::matrix4x4::identity();
|
||||||
|
|
||||||
for (auto& transform : path) {
|
for (auto& transform : path) {
|
||||||
|
|
||||||
transform._global = transform._local * m;
|
transform._global = transform._local * m;
|
||||||
m = transform._global;
|
m = transform._global;
|
||||||
|
|
||||||
debug::d() << pw::serialize::matrix(m);
|
debug::d() << pw::serialize::matrix(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// r = _registry->view<relationship>
|
||||||
|
|
||||||
// r = _registry->view<relationship>
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// auto view = _registry->view<relationship>();
|
// auto view = _registry->view<relationship>();
|
||||||
|
|
||||||
// for (auto e : view) {
|
// for (auto e : view) {
|
||||||
|
|
||||||
// const auto& r = view.get<relationship>(e);
|
// const auto& r = view.get<relationship>(e);
|
||||||
|
|
||||||
// if (r.children.size() && r.parent == entt::null) {
|
// if (r.children.size() && r.parent == entt::null) {
|
||||||
// debug::d() << "root '" << (int)e << "'";
|
// debug::d() << "root '" << (int)e << "'";
|
||||||
// }
|
// }
|
||||||
|
|
||||||
//// debug::d() << __PRETTY_FUNCTION__ << " " << view.get<relationship>(e).children.size();
|
//// debug::d() << __PRETTY_FUNCTION__ << " " << view.get<relationship>(e).children.size();
|
||||||
|
|
||||||
//// if
|
//// if
|
||||||
// }
|
// }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// auto vr = _registry->view<relationship>();
|
// auto vr = _registry->view<relationship>();
|
||||||
|
|
||||||
// for (auto [rel] : vr) {
|
// for (auto [rel] : vr) {
|
||||||
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
std::map<code_type,std::string> _source;
|
std::unordered_map<code_type,std::string> _source;
|
||||||
|
|
||||||
struct impl;
|
struct impl;
|
||||||
std::unique_ptr<impl> _impl;
|
std::unique_ptr<impl> _impl;
|
||||||
|
|
|
@ -12,12 +12,12 @@ class geometry;
|
||||||
/**
|
/**
|
||||||
* @brief Connects mesh data with the render backend
|
* @brief Connects mesh data with the render backend
|
||||||
*/
|
*/
|
||||||
class vertex_array {
|
class mesh_renderer {
|
||||||
public:
|
public:
|
||||||
vertex_array();
|
mesh_renderer();
|
||||||
vertex_array(const geometry& m);
|
mesh_renderer(const geometry& m);
|
||||||
|
|
||||||
~vertex_array();
|
~mesh_renderer();
|
||||||
|
|
||||||
void create(const geometry &m);
|
void create(const geometry &m);
|
||||||
void release();
|
void release();
|
||||||
|
|
|
@ -40,7 +40,7 @@ struct triangle_renderer
|
||||||
|
|
||||||
shader shader_p;
|
shader shader_p;
|
||||||
geometry amesh;
|
geometry amesh;
|
||||||
vertex_array amesh_renderer;
|
mesh_renderer amesh_renderer;
|
||||||
time::tick_t tick;
|
time::tick_t tick;
|
||||||
|
|
||||||
triangle_renderer()
|
triangle_renderer()
|
||||||
|
|
|
@ -12,10 +12,12 @@ struct texture::impl {
|
||||||
GLuint _texture_id;
|
GLuint _texture_id;
|
||||||
GLuint _texture_sampler;
|
GLuint _texture_sampler;
|
||||||
|
|
||||||
|
impl() = delete;
|
||||||
|
|
||||||
impl(texture& host)
|
impl(texture& host)
|
||||||
: _host(host)
|
: _host(host)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint gl_shape() {
|
GLuint gl_shape() {
|
||||||
switch (_host.shape()) {
|
switch (_host.shape()) {
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
struct vertex_array::impl {
|
struct mesh_renderer::impl {
|
||||||
|
|
||||||
GLuint _vao = 0;
|
GLuint _vao = 0;
|
||||||
|
|
||||||
|
@ -73,7 +73,8 @@ struct vertex_array::impl {
|
||||||
|
|
||||||
// indices
|
// indices
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vbos[1]);
|
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);
|
GL_STATIC_DRAW);
|
||||||
|
|
||||||
// stop binding
|
// stop binding
|
||||||
|
@ -120,37 +121,37 @@ struct vertex_array::impl {
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
vertex_array::vertex_array()
|
mesh_renderer::mesh_renderer()
|
||||||
: _impl(std::make_unique<vertex_array::impl>())
|
: _impl(std::make_unique<mesh_renderer::impl>())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
vertex_array::vertex_array(const geometry &m)
|
mesh_renderer::mesh_renderer(const geometry &m)
|
||||||
{
|
{
|
||||||
vertex_array();
|
mesh_renderer();
|
||||||
_impl->create(m);
|
_impl->create(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
vertex_array::~vertex_array()
|
mesh_renderer::~mesh_renderer()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool vertex_array::ready() const
|
bool mesh_renderer::ready() const
|
||||||
{
|
{
|
||||||
return _impl->ready();
|
return _impl->ready();
|
||||||
}
|
}
|
||||||
|
|
||||||
void vertex_array::create(const geometry &m)
|
void mesh_renderer::create(const geometry &m)
|
||||||
{
|
{
|
||||||
_impl->create(m);
|
_impl->create(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vertex_array::release()
|
void mesh_renderer::release()
|
||||||
{
|
{
|
||||||
_impl->release();
|
_impl->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void vertex_array::draw()
|
void mesh_renderer::draw()
|
||||||
{
|
{
|
||||||
_impl->draw();
|
_impl->draw();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue