added a few things from SSTT as it has a newer C++11 design
This commit is contained in:
parent
9819fa7f36
commit
f6c7f1adbb
16 changed files with 79 additions and 67 deletions
|
@ -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
|
||||
)
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#ifndef PW_CORE_MATRIX_HPP
|
||||
#define PW_CORE_MATRIX_HPP
|
||||
|
||||
#include <pw/core/globals.hpp>
|
||||
#include <pw/core/matrixbase.hpp>
|
||||
#include <pw/core/math.hpp>
|
||||
|
||||
|
@ -319,19 +320,19 @@ void matrix_<R,C,T>::normalize()
|
|||
// 4x4
|
||||
|
||||
template <typename T>
|
||||
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<T>::LookAt(const matrix<3,1,T> &eye, const matrix<3,1,T> &target, const
|
|||
|
||||
// predefined matricies
|
||||
|
||||
typedef matrix44<double> matrix44d;
|
||||
typedef matrix44<float> matrix44f;
|
||||
typedef matrix44_<real_t> matrix44;
|
||||
|
||||
typedef matrix44_<double> matrix44d;
|
||||
typedef matrix44_<float> matrix44f;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -41,15 +41,27 @@ class node;
|
|||
class component {
|
||||
public:
|
||||
|
||||
friend class node;
|
||||
|
||||
typedef std::shared_ptr<component> ref;
|
||||
typedef std::vector<ref> 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;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -97,6 +97,20 @@ public:
|
|||
//! paths to root
|
||||
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:
|
||||
|
||||
ref_array _children; //!< list of children
|
||||
|
|
|
@ -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
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
#include "pw/scene/nodepath.hpp"
|
||||
#include "pw/scene/node.hpp"
|
||||
|
||||
namespace pw {
|
||||
|
||||
void nodepath::update(node *n)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include <pw/core/serialize.hpp>
|
||||
#include <pw/scene/node.hpp>
|
||||
#include <pw/scene/transform.hpp>
|
||||
#include <pw/scene/nodepath.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
@ -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<transform>();
|
||||
|
||||
if (t) std::cout << t->local().at(0,0) << std::endl;
|
||||
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include <pw/core/serialize.hpp>
|
||||
#include <pw/scene/node.hpp>
|
||||
#include <pw/scene/transform.hpp>
|
||||
#include <pw/scene/nodepath.hpp>
|
||||
#include <pw/scene/traverser.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue