From f6c7f1adbb390cef48534ce6bca4d67c9625fa69 Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Wed, 2 Jan 2019 23:22:09 +0100 Subject: [PATCH] added a few things from SSTT as it has a newer C++11 design --- share/doc/pixwerx.xmind | Bin 119135 -> 126884 bytes src/core/CMakeLists.txt | 4 ++++ src/core/include/pw/core/matrix.hpp | 13 ++++++----- src/scene/CMakeLists.txt | 2 -- src/scene/include/pw/scene/camera.hpp | 6 +++--- src/scene/include/pw/scene/component.hpp | 12 +++++++++++ src/scene/include/pw/scene/node.hpp | 14 ++++++++++++ src/scene/include/pw/scene/nodepath.hpp | 24 --------------------- src/scene/include/pw/scene/transform.hpp | 14 ++++++------ src/scene/src/camera.cpp | 9 ++++---- src/scene/src/component.cpp | 10 +++++++++ src/scene/src/node.cpp | 6 ++++++ src/scene/src/nodepath.cpp | 11 ---------- src/scene/src/transform.cpp | 11 ++++------ src/scene/tests/pwscene_test_node.cpp | 9 +++++++- src/scene/tests/pwscene_test_traverser.cpp | 1 - 16 files changed, 79 insertions(+), 67 deletions(-) delete mode 100644 src/scene/include/pw/scene/nodepath.hpp delete mode 100644 src/scene/src/nodepath.cpp diff --git a/share/doc/pixwerx.xmind b/share/doc/pixwerx.xmind index 204f29e6197ba25c31d00a8a4b4936a0befb293a..6e061eba0dd11384bd12397d7a73ee41dff37421 100644 GIT binary patch delta 3912 zcmd^CYitzP6`pI1ZH#ecuVdB|gUy0%0$z4@?mTuHKZw#qO)bC;kn$*0vpci9vpX~U znAr`1Ag4c&Qnw(rw`eM=Hc698O-oyvX+`~`;gLsyV9bxEN=q$Bi-?k{X;D-vk*4XL zS-jp|;{_r0SI0im+bn-$_7yecJ1V#7LG?UjG33zoTSM)Eh4iqN{ey6Zd1`@!xXjjpfAWWToJ-IG+?IE zO2p02i5VG2qhdsl#8gT%m6UGA*@TgV=mm4D&k169{O<%QrYa9@$%=V7Yl!MVz@0!X zZ;zwM(|)gzh(a3Xm|R$hNrsV*>uQisP&``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!-Cc4_x?x3jhEB diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 6aff23a..d5b0ba3 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,5 +1,6 @@ set(hdrs + include/pw/core/log.hpp include/pw/core/axisangle.hpp include/pw/core/core.hpp include/pw/core/math.hpp @@ -10,12 +11,15 @@ set(hdrs include/pw/core/serialize.hpp include/pw/core/image.hpp include/pw/core/size.hpp + include/pw/core/timer.hpp include/pw/core/globals.hpp ) set(srcs + src/log.cpp src/core.cpp src/serialize.cpp + src/timer.cpp ${CMAKE_SOURCE_DIR}/README.md ${CMAKE_SOURCE_DIR}/LICENSE ) diff --git a/src/core/include/pw/core/matrix.hpp b/src/core/include/pw/core/matrix.hpp index c0dd064..25fc130 100644 --- a/src/core/include/pw/core/matrix.hpp +++ b/src/core/include/pw/core/matrix.hpp @@ -26,6 +26,7 @@ #ifndef PW_CORE_MATRIX_HPP #define PW_CORE_MATRIX_HPP +#include #include #include @@ -319,19 +320,19 @@ void matrix_::normalize() // 4x4 template -class matrix44 : public matrix_<4,4,T> +class matrix44_ : public matrix_<4,4,T> { public: using matrix_<4,4,T>::matrix_; - matrix44(const matrix_<4,4,T>& i) + matrix44_(const matrix_<4,4,T>& i) { *this = i; } - matrix44& operator = (const matrix_<4,4,T>& rhs) { + matrix44_& operator = (const matrix_<4,4,T>& rhs) { if (this != &rhs){ this->at(0,0) = rhs.at(0,0);this->at(0,1) = rhs.at(0,1);this->at(0,2) = rhs.at(0,2);this->at(0,3) = rhs.at(0,3); this->at(1,0) = rhs.at(1,0);this->at(1,1) = rhs.at(1,1);this->at(1,2) = rhs.at(1,2);this->at(1,3) = rhs.at(1,3); @@ -599,8 +600,10 @@ matrix44::LookAt(const matrix<3,1,T> &eye, const matrix<3,1,T> &target, const // predefined matricies -typedef matrix44 matrix44d; -typedef matrix44 matrix44f; +typedef matrix44_ matrix44; + +typedef matrix44_ matrix44d; +typedef matrix44_ matrix44f; } diff --git a/src/scene/CMakeLists.txt b/src/scene/CMakeLists.txt index 593de6d..ccff4ab 100644 --- a/src/scene/CMakeLists.txt +++ b/src/scene/CMakeLists.txt @@ -3,7 +3,6 @@ set(hdrs include/pw/scene/camera.hpp include/pw/scene/component.hpp include/pw/scene/node.hpp - include/pw/scene/nodepath.hpp include/pw/scene/mesh.hpp include/pw/scene/scene.hpp include/pw/scene/transform.hpp @@ -12,7 +11,6 @@ set(hdrs set(srcs src/node.cpp - src/nodepath.cpp src/camera.cpp src/component.cpp src/mesh.cpp diff --git a/src/scene/include/pw/scene/camera.hpp b/src/scene/include/pw/scene/camera.hpp index 52648bd..7b8ae9d 100644 --- a/src/scene/include/pw/scene/camera.hpp +++ b/src/scene/include/pw/scene/camera.hpp @@ -49,8 +49,8 @@ public: camera(); - void set_projection(const matrix44d &projection); - const matrix44d& projection() const; + void set_projection(const matrix44 &projection); + const matrix44& projection() const; // void set_field_of_view(float) @@ -64,7 +64,7 @@ protected: private: - matrix44d _projection; + matrix44 _projection; }; diff --git a/src/scene/include/pw/scene/component.hpp b/src/scene/include/pw/scene/component.hpp index c4c2b10..dfa3d43 100644 --- a/src/scene/include/pw/scene/component.hpp +++ b/src/scene/include/pw/scene/component.hpp @@ -41,15 +41,27 @@ class node; class component { public: + friend class node; + typedef std::shared_ptr ref; typedef std::vector array; //! only very few components can be attached multiple times virtual bool singular() const { return true; } + virtual void visit(node*) {} component(); component(const component& other); virtual ~component(); + + bool enabled() const; + void set_enabled(bool enabled); + +protected: + + node* _node; + bool _enabled; + }; } diff --git a/src/scene/include/pw/scene/node.hpp b/src/scene/include/pw/scene/node.hpp index 69c00d0..bf0c516 100644 --- a/src/scene/include/pw/scene/node.hpp +++ b/src/scene/include/pw/scene/node.hpp @@ -97,6 +97,20 @@ public: //! paths to root const ptr_array& path() const; + void traversal(); + + template + T* find() + { + for (auto c : _components) + { + T* r = static_cast(c.get()); + if (r != nullptr) return r; + } + return nullptr; + } + + protected: ref_array _children; //!< list of children diff --git a/src/scene/include/pw/scene/nodepath.hpp b/src/scene/include/pw/scene/nodepath.hpp deleted file mode 100644 index b2b726c..0000000 --- a/src/scene/include/pw/scene/nodepath.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef PW_SCENE_NODEPATH_HPP -#define PW_SCENE_NODEPATH_HPP - -#include - -namespace pw { - -class nodepath { -public: - - nodepath() {} - - void update(node* n); - -protected: - - node::ptr_array _path; - -}; - -} - - -#endif // NODEPATH_HPP diff --git a/src/scene/include/pw/scene/transform.hpp b/src/scene/include/pw/scene/transform.hpp index 30f1ab7..850489a 100644 --- a/src/scene/include/pw/scene/transform.hpp +++ b/src/scene/include/pw/scene/transform.hpp @@ -10,11 +10,12 @@ class transform : public component { public: using component::component; + using component::ref; - const matrix44d& local() const; - void set_local(const matrix44d &local); + inline const matrix44& local() const { return _local; } + void set_local(const matrix44 &local); - void set_global(const matrix44d &global); + void set_global(const matrix44 &global); void update(); @@ -24,11 +25,8 @@ public: protected: - matrix44d _local; - - matrix44d _global; - matrix44d _global_inverse; - + matrix44 _local; + matrix44 _global; }; diff --git a/src/scene/src/camera.cpp b/src/scene/src/camera.cpp index a121ab0..63c845a 100644 --- a/src/scene/src/camera.cpp +++ b/src/scene/src/camera.cpp @@ -4,19 +4,18 @@ namespace pw { camera::camera() : _fov(60.0) - , _near_plane(0.2) + , _near_plane(0.2f) , _far_plane(1000) { - set_projection(matrix44d::perspective_projection(_fov,1,_near_plane,_far_plane)); + set_projection(matrix44::perspective_projection(_fov,1,_near_plane,_far_plane)); } - -void camera::set_projection(const matrix44d& projection) +void camera::set_projection(const matrix44 &projection) { this->_projection = projection; } -const matrix44d &camera::projection() const +const matrix44 &camera::projection() const { return _projection; } diff --git a/src/scene/src/component.cpp b/src/scene/src/component.cpp index 10065d4..2b34789 100644 --- a/src/scene/src/component.cpp +++ b/src/scene/src/component.cpp @@ -36,6 +36,16 @@ component::~component() // if (_node != nullptr) _node->unregister_component(this); } +bool component::enabled() const +{ + return _enabled; +} + +void component::set_enabled(bool enabled) +{ + _enabled = enabled; +} + //class trs : public transform { diff --git a/src/scene/src/node.cpp b/src/scene/src/node.cpp index 2ac65df..f2ad15a 100644 --- a/src/scene/src/node.cpp +++ b/src/scene/src/node.cpp @@ -72,6 +72,7 @@ void node::remove_component(component::ref c) component::array::iterator it = _components.end(); while ((it = std::find(_components.begin(),_components.end(),c)) != _components.end()) { + (*it)->_node = nullptr; _components.erase(it); } } @@ -81,6 +82,11 @@ const node::ptr_array &node::path() const return _path; } +void node::traversal() +{ + for (auto c : _components) c->visit(this); +} + const component::array& node::components() const { return _components; diff --git a/src/scene/src/nodepath.cpp b/src/scene/src/nodepath.cpp deleted file mode 100644 index d8d1e02..0000000 --- a/src/scene/src/nodepath.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "pw/scene/nodepath.hpp" -#include "pw/scene/node.hpp" - -namespace pw { - -void nodepath::update(node *n) -{ -} - - -} diff --git a/src/scene/src/transform.cpp b/src/scene/src/transform.cpp index 252b82b..47e1ad0 100644 --- a/src/scene/src/transform.cpp +++ b/src/scene/src/transform.cpp @@ -2,20 +2,17 @@ namespace pw { -const matrix44d& transform::local() const -{ - return _local; -} -void transform::set_local(const matrix44d &local) +void transform::set_local(const matrix44 &local) { // TODO need to rebuild the transforms: both -> global down and global up _local = local; } -void transform::set_global(const matrix44d &global) +void transform::set_global(const matrix44 &global) { - _global = global; // need to set global inverse + //TODO need to rebuild **_local** from parent + _global = global; } diff --git a/src/scene/tests/pwscene_test_node.cpp b/src/scene/tests/pwscene_test_node.cpp index e3c355b..a065ed6 100644 --- a/src/scene/tests/pwscene_test_node.cpp +++ b/src/scene/tests/pwscene_test_node.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include @@ -46,8 +45,16 @@ int main(int argc,char **argv) { std::cout << "n components: " << n->components().size() << std::endl; + print_node_path((n)); + auto t = n->find(); + + if (t) std::cout << t->local().at(0,0) << std::endl; + + + + return 0; } diff --git a/src/scene/tests/pwscene_test_traverser.cpp b/src/scene/tests/pwscene_test_traverser.cpp index 638521f..eacc4eb 100644 --- a/src/scene/tests/pwscene_test_traverser.cpp +++ b/src/scene/tests/pwscene_test_traverser.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include