added a few things from SSTT as it has a newer C++11 design

This commit is contained in:
Hartmut Seichter 2019-01-02 23:22:09 +01:00
parent 9819fa7f36
commit f6c7f1adbb
16 changed files with 79 additions and 67 deletions

Binary file not shown.

View file

@ -1,5 +1,6 @@
set(hdrs set(hdrs
include/pw/core/log.hpp
include/pw/core/axisangle.hpp include/pw/core/axisangle.hpp
include/pw/core/core.hpp include/pw/core/core.hpp
include/pw/core/math.hpp include/pw/core/math.hpp
@ -10,12 +11,15 @@ set(hdrs
include/pw/core/serialize.hpp include/pw/core/serialize.hpp
include/pw/core/image.hpp include/pw/core/image.hpp
include/pw/core/size.hpp include/pw/core/size.hpp
include/pw/core/timer.hpp
include/pw/core/globals.hpp include/pw/core/globals.hpp
) )
set(srcs set(srcs
src/log.cpp
src/core.cpp src/core.cpp
src/serialize.cpp src/serialize.cpp
src/timer.cpp
${CMAKE_SOURCE_DIR}/README.md ${CMAKE_SOURCE_DIR}/README.md
${CMAKE_SOURCE_DIR}/LICENSE ${CMAKE_SOURCE_DIR}/LICENSE
) )

View file

@ -26,6 +26,7 @@
#ifndef PW_CORE_MATRIX_HPP #ifndef PW_CORE_MATRIX_HPP
#define PW_CORE_MATRIX_HPP #define PW_CORE_MATRIX_HPP
#include <pw/core/globals.hpp>
#include <pw/core/matrixbase.hpp> #include <pw/core/matrixbase.hpp>
#include <pw/core/math.hpp> #include <pw/core/math.hpp>
@ -319,19 +320,19 @@ void matrix_<R,C,T>::normalize()
// 4x4 // 4x4
template <typename T> template <typename T>
class matrix44 : public matrix_<4,4,T> class matrix44_ : public matrix_<4,4,T>
{ {
public: public:
using matrix_<4,4,T>::matrix_; using matrix_<4,4,T>::matrix_;
matrix44(const matrix_<4,4,T>& i) matrix44_(const matrix_<4,4,T>& i)
{ {
*this = i; *this = i;
} }
matrix44& operator = (const matrix_<4,4,T>& rhs) { matrix44_& operator = (const matrix_<4,4,T>& rhs) {
if (this != &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(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); 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<T>::LookAt(const matrix<3,1,T> &eye, const matrix<3,1,T> &target, const
// predefined matricies // predefined matricies
typedef matrix44<double> matrix44d; typedef matrix44_<real_t> matrix44;
typedef matrix44<float> matrix44f;
typedef matrix44_<double> matrix44d;
typedef matrix44_<float> matrix44f;
} }

View file

@ -3,7 +3,6 @@ set(hdrs
include/pw/scene/camera.hpp include/pw/scene/camera.hpp
include/pw/scene/component.hpp include/pw/scene/component.hpp
include/pw/scene/node.hpp include/pw/scene/node.hpp
include/pw/scene/nodepath.hpp
include/pw/scene/mesh.hpp include/pw/scene/mesh.hpp
include/pw/scene/scene.hpp include/pw/scene/scene.hpp
include/pw/scene/transform.hpp include/pw/scene/transform.hpp
@ -12,7 +11,6 @@ set(hdrs
set(srcs set(srcs
src/node.cpp src/node.cpp
src/nodepath.cpp
src/camera.cpp src/camera.cpp
src/component.cpp src/component.cpp
src/mesh.cpp src/mesh.cpp

View file

@ -49,8 +49,8 @@ public:
camera(); camera();
void set_projection(const matrix44d &projection); void set_projection(const matrix44 &projection);
const matrix44d& projection() const; const matrix44& projection() const;
// void set_field_of_view(float) // void set_field_of_view(float)
@ -64,7 +64,7 @@ protected:
private: private:
matrix44d _projection; matrix44 _projection;
}; };

View file

@ -41,15 +41,27 @@ class node;
class component { class component {
public: public:
friend class node;
typedef std::shared_ptr<component> ref; typedef std::shared_ptr<component> ref;
typedef std::vector<ref> array; typedef std::vector<ref> array;
//! only very few components can be attached multiple times //! only very few components can be attached multiple times
virtual bool singular() const { return true; } virtual bool singular() const { return true; }
virtual void visit(node*) {}
component(); component();
component(const component& other); component(const component& other);
virtual ~component(); virtual ~component();
bool enabled() const;
void set_enabled(bool enabled);
protected:
node* _node;
bool _enabled;
}; };
} }

View file

@ -97,6 +97,20 @@ public:
//! paths to root //! paths to root
const ptr_array& path() const; const ptr_array& path() const;
void traversal();
template <typename T>
T* find()
{
for (auto c : _components)
{
T* r = static_cast<T*>(c.get());
if (r != nullptr) return r;
}
return nullptr;
}
protected: protected:
ref_array _children; //!< list of children ref_array _children; //!< list of children

View file

@ -1,24 +0,0 @@
#ifndef PW_SCENE_NODEPATH_HPP
#define PW_SCENE_NODEPATH_HPP
#include <pw/scene/node.hpp>
namespace pw {
class nodepath {
public:
nodepath() {}
void update(node* n);
protected:
node::ptr_array _path;
};
}
#endif // NODEPATH_HPP

View file

@ -10,11 +10,12 @@ class transform : public component {
public: public:
using component::component; using component::component;
using component::ref;
const matrix44d& local() const; inline const matrix44& local() const { return _local; }
void set_local(const matrix44d &local); void set_local(const matrix44 &local);
void set_global(const matrix44d &global); void set_global(const matrix44 &global);
void update(); void update();
@ -24,11 +25,8 @@ public:
protected: protected:
matrix44d _local; matrix44 _local;
matrix44 _global;
matrix44d _global;
matrix44d _global_inverse;
}; };

View file

@ -4,19 +4,18 @@ namespace pw {
camera::camera() camera::camera()
: _fov(60.0) : _fov(60.0)
, _near_plane(0.2) , _near_plane(0.2f)
, _far_plane(1000) , _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 matrix44 &projection)
void camera::set_projection(const matrix44d& projection)
{ {
this->_projection = projection; this->_projection = projection;
} }
const matrix44d &camera::projection() const const matrix44 &camera::projection() const
{ {
return _projection; return _projection;
} }

View file

@ -36,6 +36,16 @@ component::~component()
// if (_node != nullptr) _node->unregister_component(this); // 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 { //class trs : public transform {

View file

@ -72,6 +72,7 @@ void node::remove_component(component::ref c)
component::array::iterator it = _components.end(); component::array::iterator it = _components.end();
while ((it = std::find(_components.begin(),_components.end(),c)) != _components.end()) { while ((it = std::find(_components.begin(),_components.end(),c)) != _components.end()) {
(*it)->_node = nullptr;
_components.erase(it); _components.erase(it);
} }
} }
@ -81,6 +82,11 @@ const node::ptr_array &node::path() const
return _path; return _path;
} }
void node::traversal()
{
for (auto c : _components) c->visit(this);
}
const component::array& node::components() const const component::array& node::components() const
{ {
return _components; return _components;

View file

@ -1,11 +0,0 @@
#include "pw/scene/nodepath.hpp"
#include "pw/scene/node.hpp"
namespace pw {
void nodepath::update(node *n)
{
}
}

View file

@ -2,20 +2,17 @@
namespace pw { 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 // TODO need to rebuild the transforms: both -> global down and global up
_local = local; _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;
} }

View file

@ -2,7 +2,6 @@
#include <pw/core/serialize.hpp> #include <pw/core/serialize.hpp>
#include <pw/scene/node.hpp> #include <pw/scene/node.hpp>
#include <pw/scene/transform.hpp> #include <pw/scene/transform.hpp>
#include <pw/scene/nodepath.hpp>
#include <iostream> #include <iostream>
@ -46,8 +45,16 @@ int main(int argc,char **argv) {
std::cout << "n components: " << n->components().size() << std::endl; std::cout << "n components: " << n->components().size() << std::endl;
print_node_path((n)); print_node_path((n));
auto t = n->find<transform>();
if (t) std::cout << t->local().at(0,0) << std::endl;
return 0; return 0;
} }

View file

@ -2,7 +2,6 @@
#include <pw/core/serialize.hpp> #include <pw/core/serialize.hpp>
#include <pw/scene/node.hpp> #include <pw/scene/node.hpp>
#include <pw/scene/transform.hpp> #include <pw/scene/transform.hpp>
#include <pw/scene/nodepath.hpp>
#include <pw/scene/traverser.hpp> #include <pw/scene/traverser.hpp>
#include <iostream> #include <iostream>