diff --git a/share/doc/pixwerx.xmind b/share/doc/pixwerx.xmind index 204f29e..6e061eb 100644 Binary files a/share/doc/pixwerx.xmind and b/share/doc/pixwerx.xmind differ 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