slowly getting tracktion again
This commit is contained in:
parent
a5dea1ede1
commit
dd23fa811a
29 changed files with 685 additions and 380 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
#
|
||||||
|
# CMake build system for pixwerx
|
||||||
|
#
|
||||||
cmake_minimum_required(VERSION 3.8)
|
cmake_minimum_required(VERSION 3.8)
|
||||||
|
|
||||||
project(pixwerx)
|
project(pixwerx)
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
add_subdirectory(deps)
|
add_subdirectory(deps)
|
||||||
add_subdirectory(core)
|
add_subdirectory(core)
|
||||||
add_subdirectory(scene)
|
add_subdirectory(scene)
|
||||||
|
#add_subdirectory(system)
|
||||||
add_subdirectory(ui)
|
add_subdirectory(ui)
|
||||||
add_subdirectory(scripting)
|
add_subdirectory(scripting)
|
||||||
add_subdirectory(engine)
|
add_subdirectory(engine)
|
||||||
|
|
|
@ -1,4 +1,38 @@
|
||||||
|
|
||||||
add_subdirectory(src)
|
set(hdrs
|
||||||
|
include/pw/core/axisangle.hpp
|
||||||
|
include/pw/core/core.hpp
|
||||||
|
include/pw/core/math.hpp
|
||||||
|
include/pw/core/matrixbase.hpp
|
||||||
|
include/pw/core/matrix.hpp
|
||||||
|
include/pw/core/vector.hpp
|
||||||
|
include/pw/core/quaternion.hpp
|
||||||
|
include/pw/core/serialize.hpp
|
||||||
|
include/pw/core/image.hpp
|
||||||
|
include/pw/core/globals.hpp
|
||||||
|
)
|
||||||
|
|
||||||
|
set(srcs
|
||||||
|
src/core.cpp
|
||||||
|
src/serialize.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(pwcore
|
||||||
|
STATIC
|
||||||
|
${hdrs}
|
||||||
|
${srcs}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(
|
||||||
|
pwcore
|
||||||
|
PUBLIC
|
||||||
|
include
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(pwcore)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#add_subdirectory(src)
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,10 @@ protected:
|
||||||
T _angle;
|
T _angle;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
axisangle() {}
|
axisangle()
|
||||||
|
: _axis(vector3<T>::up()),
|
||||||
|
_angle(0)
|
||||||
|
{}
|
||||||
|
|
||||||
axisangle(const vector3<T> &axis,const T &angle)
|
axisangle(const vector3<T> &axis,const T &angle)
|
||||||
: _axis(axis)
|
: _axis(axis)
|
||||||
|
|
|
@ -10,8 +10,6 @@ const static double __PW_PI = 3.141592653589793238462643383279502884197169399375
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline const T pi() { return static_cast<T>(__PW_PI); }
|
inline const T pi() { return static_cast<T>(__PW_PI); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline static double rad_to_deg(const T& angle_in_radian) {
|
inline static double rad_to_deg(const T& angle_in_radian) {
|
||||||
return static_cast<T>(angle_in_radian * T(180.) / pi<T>());
|
return static_cast<T>(angle_in_radian * T(180.) / pi<T>());
|
||||||
|
|
|
@ -113,6 +113,12 @@ public:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
static vector3<T> forward() { return vector3<T> ( 0, 0,-1); }
|
||||||
|
static vector3<T> backward() { return vector3<T>( 0, 0, 1); }
|
||||||
|
static vector3<T> right() { return vector3<T> ( 1, 0, 0); }
|
||||||
|
static vector3<T> left() { return vector3<T> (-1, 0, 0); }
|
||||||
|
static vector3<T> up() { return vector3<T> ( 0, 1, 0); }
|
||||||
|
static vector3<T> down() { return vector3<T> ( 0,-1, 0); }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -120,8 +126,7 @@ public:
|
||||||
|
|
||||||
// Vec2x -----------------------------------------------------------------------
|
// Vec2x -----------------------------------------------------------------------
|
||||||
|
|
||||||
template <class T> class vector2 : public vector<2,T>
|
template <class T> class vector2 : public vector<2,T> {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
vector2() {}
|
vector2() {}
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
|
|
||||||
set(hdrs
|
|
||||||
# ../include/pw/core/context.hpp
|
|
||||||
../include/pw/core/axisangle.hpp
|
|
||||||
../include/pw/core/core.hpp
|
|
||||||
# ../include/pw/core/script.hpp
|
|
||||||
# ../include/pw/core/scripting.hpp
|
|
||||||
../include/pw/core/math.hpp
|
|
||||||
../include/pw/core/matrixbase.hpp
|
|
||||||
../include/pw/core/matrix.hpp
|
|
||||||
../include/pw/core/vector.hpp
|
|
||||||
../include/pw/core/quaternion.hpp
|
|
||||||
../include/pw/core/serialize.hpp
|
|
||||||
../include/pw/core/image.hpp
|
|
||||||
../include/pw/core/globals.hpp
|
|
||||||
)
|
|
||||||
|
|
||||||
set(srcs
|
|
||||||
# script.cpp
|
|
||||||
# context.cpp
|
|
||||||
core.cpp
|
|
||||||
serialize.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
add_library(pwcore
|
|
||||||
STATIC
|
|
||||||
${hdrs}
|
|
||||||
${srcs}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(
|
|
||||||
pwcore
|
|
||||||
PUBLIC
|
|
||||||
../include
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(pwcore)
|
|
||||||
|
|
|
@ -17,8 +17,6 @@ void test_matrixbase() {
|
||||||
|
|
||||||
m.set_identity();
|
m.set_identity();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,37 @@
|
||||||
add_subdirectory(src)
|
|
||||||
|
set(hdrs
|
||||||
|
include/pw/scene/component.hpp
|
||||||
|
include/pw/scene/node.hpp
|
||||||
|
include/pw/scene/nodepath.hpp
|
||||||
|
include/pw/scene/transform.hpp
|
||||||
|
include/pw/scene/traverser.hpp
|
||||||
|
)
|
||||||
|
|
||||||
|
set(srcs
|
||||||
|
src/node.cpp
|
||||||
|
src/nodepath.cpp
|
||||||
|
src/component.cpp
|
||||||
|
src/transform.cpp
|
||||||
|
src/traverser.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(pwscene
|
||||||
|
STATIC
|
||||||
|
${hdrs}
|
||||||
|
${srcs}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(
|
||||||
|
pwscene
|
||||||
|
PUBLIC
|
||||||
|
include
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(
|
||||||
|
pwscene
|
||||||
|
PUBLIC
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(pwscene pwcore)
|
||||||
|
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
|
|
|
@ -9,8 +9,10 @@
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
|
class traverser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief nodes are representing the hierarchical structore fo the scene graph
|
* @brief nodes represent the structure for the scene graph
|
||||||
*/
|
*/
|
||||||
class node {
|
class node {
|
||||||
public:
|
public:
|
||||||
|
@ -27,6 +29,10 @@ public:
|
||||||
//! copy c'tor
|
//! copy c'tor
|
||||||
node(const node& node);
|
node(const node& node);
|
||||||
|
|
||||||
|
|
||||||
|
//! wrapper for scripting interface
|
||||||
|
std::shared_ptr<node> shared();
|
||||||
|
|
||||||
//! cloning interface
|
//! cloning interface
|
||||||
virtual node* clone(const unsigned short& copymode) const;
|
virtual node* clone(const unsigned short& copymode) const;
|
||||||
|
|
||||||
|
@ -36,11 +42,8 @@ public:
|
||||||
//! return list of parents
|
//! return list of parents
|
||||||
inline const ptr_array& parents() const { return _parents; }
|
inline const ptr_array& parents() const { return _parents; }
|
||||||
|
|
||||||
//! check if this is the root node
|
|
||||||
inline bool is_root() const { return parents().empty(); }
|
|
||||||
|
|
||||||
//! add a child node
|
//! add a child node
|
||||||
void add_child(node *anode);
|
std::shared_ptr<node> add_child(std::shared_ptr<node> anode);
|
||||||
|
|
||||||
//! get the list of children
|
//! get the list of children
|
||||||
inline const ref_array& children() const { return _children; }
|
inline const ref_array& children() const { return _children; }
|
||||||
|
@ -51,10 +54,37 @@ public:
|
||||||
//! check if this node is a leaf node
|
//! check if this node is a leaf node
|
||||||
inline bool is_leaf() const { return children().empty(); }
|
inline bool is_leaf() const { return children().empty(); }
|
||||||
|
|
||||||
|
//! check if this is the root node
|
||||||
|
inline bool is_root() const { return parents().empty(); }
|
||||||
|
|
||||||
|
//! d'tor
|
||||||
virtual ~node();
|
virtual ~node();
|
||||||
|
|
||||||
|
//! list of components
|
||||||
const component::array& components() const;
|
const component::array& components() const;
|
||||||
|
|
||||||
|
//! add a node as parent node
|
||||||
|
void add_parent(node *anode);
|
||||||
|
|
||||||
|
//! visitor to collect data from the graph
|
||||||
|
struct visitor {
|
||||||
|
enum direction {
|
||||||
|
up,
|
||||||
|
down
|
||||||
|
} direction;
|
||||||
|
|
||||||
|
visitor(enum direction d = direction::down) : direction(d) {}
|
||||||
|
|
||||||
|
virtual void enter(node* n) = 0;
|
||||||
|
virtual void leave(node* n) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
void visit(visitor &visitor);
|
||||||
|
|
||||||
|
void ascend(visitor &visitor);
|
||||||
|
|
||||||
|
void descend(visitor &visitor);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void register_component(component* c);
|
void register_component(component* c);
|
||||||
|
|
24
src/scene/include/pw/scene/nodepath.hpp
Normal file
24
src/scene/include/pw/scene/nodepath.hpp
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#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
|
30
src/scene/include/pw/scene/traverser.hpp
Normal file
30
src/scene/include/pw/scene/traverser.hpp
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#ifndef PW_SCENE_TRAVERSER_HPP
|
||||||
|
#define PW_SCENE_TRAVERSER_HPP
|
||||||
|
|
||||||
|
namespace pw {
|
||||||
|
|
||||||
|
class node;
|
||||||
|
|
||||||
|
//class traverser {
|
||||||
|
//public:
|
||||||
|
|
||||||
|
// enum direction {
|
||||||
|
// up,
|
||||||
|
// down
|
||||||
|
// };
|
||||||
|
|
||||||
|
// traverser(direction dir = direction::down);
|
||||||
|
|
||||||
|
// void enter(node* node);
|
||||||
|
|
||||||
|
// void leave(node* node);
|
||||||
|
|
||||||
|
//protected:
|
||||||
|
|
||||||
|
// direction _direction;
|
||||||
|
|
||||||
|
//};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // PW_SCENE_TRAVERSER_HPP
|
|
@ -1,32 +1,2 @@
|
||||||
|
|
||||||
set(hdrs
|
|
||||||
../include/pw/scene/component.hpp
|
|
||||||
../include/pw/scene/node.hpp
|
|
||||||
../include/pw/scene/transform.hpp
|
|
||||||
)
|
|
||||||
|
|
||||||
set(srcs
|
|
||||||
node.cpp
|
|
||||||
nodepath.cpp
|
|
||||||
component.cpp
|
|
||||||
transform.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
add_library(pwscene
|
|
||||||
STATIC
|
|
||||||
${hdrs}
|
|
||||||
${srcs}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(
|
|
||||||
pwscene
|
|
||||||
PUBLIC
|
|
||||||
../include
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(
|
|
||||||
pwscene
|
|
||||||
PUBLIC
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(pwscene pwcore)
|
|
||||||
|
|
|
@ -16,7 +16,16 @@ namespace pw {
|
||||||
component::component(node *n)
|
component::component(node *n)
|
||||||
: _node(n)
|
: _node(n)
|
||||||
{
|
{
|
||||||
if (_node != nullptr) _node->register_component(this);
|
if (_node != nullptr) {
|
||||||
|
|
||||||
|
for (const auto c : _node->components()) {
|
||||||
|
if (typeid (c.get()).name() == typeid (this).name()) {
|
||||||
|
// error
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_node->register_component(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
component::component(const component &other)
|
component::component(const component &other)
|
||||||
|
|
|
@ -22,10 +22,44 @@ void node::set_name(const std::string &name)
|
||||||
_name = name;
|
_name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void node::add_child(node *anode)
|
std::shared_ptr<node> node::add_child(std::shared_ptr<node> anode)
|
||||||
{
|
{
|
||||||
_children.push_back(std::shared_ptr<node>(anode));
|
anode->add_parent(this);
|
||||||
anode->_parents.push_back(this);
|
_children.push_back(anode);
|
||||||
|
return anode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void node::add_parent(node *anode)
|
||||||
|
{
|
||||||
|
_parents.push_back(anode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void node::visit(visitor& visitor)
|
||||||
|
{
|
||||||
|
visitor.enter(this);
|
||||||
|
|
||||||
|
if (visitor.direction == node::visitor::direction::up)
|
||||||
|
this->ascend(visitor);
|
||||||
|
else {
|
||||||
|
this->descend(visitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
visitor.leave(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void node::ascend(visitor& visitor)
|
||||||
|
{
|
||||||
|
for (auto p : this->parents()) p->visit(visitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void node::descend(visitor& visitor)
|
||||||
|
{
|
||||||
|
for (auto c : this->children()) c->visit(visitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<node> node::shared()
|
||||||
|
{
|
||||||
|
return std::shared_ptr<node>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
node::~node()
|
node::~node()
|
||||||
|
@ -34,6 +68,13 @@ node::~node()
|
||||||
_parents.clear();
|
_parents.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
void node::register_component(component *c) {
|
void node::register_component(component *c) {
|
||||||
_components.push_back(std::shared_ptr<component>(c));
|
_components.push_back(std::shared_ptr<component>(c));
|
||||||
}
|
}
|
||||||
|
@ -54,4 +95,5 @@ const component::array& node::components() const
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
|
#include "pw/scene/nodepath.hpp"
|
||||||
|
#include "pw/scene/node.hpp"
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
|
void nodepath::update(node *n)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
34
src/scene/src/traverser.cpp
Normal file
34
src/scene/src/traverser.cpp
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#include "pw/scene/traverser.hpp"
|
||||||
|
#include "pw/scene/node.hpp"
|
||||||
|
|
||||||
|
#include <stack>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace pw {
|
||||||
|
|
||||||
|
//traverser::traverser(direction dir)
|
||||||
|
//{
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void traverser::run(node *root_node)
|
||||||
|
//{
|
||||||
|
// std::stack<node*> node_stack;
|
||||||
|
// node_stack.push(root_node);
|
||||||
|
|
||||||
|
// node *n = root_node;
|
||||||
|
|
||||||
|
// while (!node_stack.empty()) {
|
||||||
|
|
||||||
|
// if (n->is_leaf()) {
|
||||||
|
// std::cout << n->name() << std::endl;
|
||||||
|
// node_stack.pop();
|
||||||
|
// // save
|
||||||
|
// } else {
|
||||||
|
// for
|
||||||
|
//// n = n->children().front().get();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
}
|
|
@ -4,3 +4,11 @@ add_executable(pwscene_test_node
|
||||||
|
|
||||||
target_link_libraries(pwscene_test_node
|
target_link_libraries(pwscene_test_node
|
||||||
pwcore pwscene)
|
pwcore pwscene)
|
||||||
|
|
||||||
|
|
||||||
|
add_executable(pwscene_test_traverser
|
||||||
|
pwscene_test_traverser.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(pwscene_test_traverser
|
||||||
|
pwcore pwscene)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#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>
|
||||||
|
|
||||||
|
@ -13,14 +14,14 @@ int main(int argc,char **argv) {
|
||||||
|
|
||||||
// check
|
// check
|
||||||
{
|
{
|
||||||
n->add_child(new node("sub"));
|
n->add_child(std::make_shared<node>("sub"));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "n name: " << n->name() << std::endl;
|
std::cout << "n name: " << n->name() << std::endl;
|
||||||
std::cout << "n leaf: " << n->is_leaf() << std::endl;
|
std::cout << "n leaf: " << n->is_leaf() << std::endl;
|
||||||
std::cout << "n root: " << n->is_root() << std::endl;
|
std::cout << "n root: " << n->is_root() << std::endl;
|
||||||
|
|
||||||
std::cout << "s name: " << n->children()[0]->name() << std::endl;
|
std::cout << "s name: " << n->children().front()->name() << std::endl;
|
||||||
std::cout << "s leaf: " << n->children()[0]->is_leaf() << std::endl;
|
std::cout << "s leaf: " << n->children()[0]->is_leaf() << std::endl;
|
||||||
std::cout << "s root: " << n->children()[0]->is_root() << std::endl;
|
std::cout << "s root: " << n->children()[0]->is_root() << std::endl;
|
||||||
|
|
||||||
|
@ -33,5 +34,7 @@ int main(int argc,char **argv) {
|
||||||
std::cout << "n components: " << n->components().size() << std::endl;
|
std::cout << "n components: " << n->components().size() << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
45
src/scene/tests/pwscene_test_traverser.cpp
Normal file
45
src/scene/tests/pwscene_test_traverser.cpp
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
#include <pw/core/vector.hpp>
|
||||||
|
#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>
|
||||||
|
|
||||||
|
struct test_visitor : pw::node::visitor {
|
||||||
|
virtual void enter(pw::node *n) override;
|
||||||
|
virtual void leave(pw::node *n) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
void test_visitor::enter(pw::node *n)
|
||||||
|
{
|
||||||
|
std::cout << n->name() << " " << n->is_leaf() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_visitor::leave(pw::node *n)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main(int argc,char **argv) {
|
||||||
|
|
||||||
|
using namespace pw;
|
||||||
|
|
||||||
|
node::ref root(std::make_shared<node>("root"));
|
||||||
|
root->add_child(std::make_shared<node>("sub-1"));
|
||||||
|
|
||||||
|
node::ref sub_2_1 = std::make_shared<node>("sub-2-1");
|
||||||
|
|
||||||
|
root->add_child(std::make_shared<node>("sub-2"))->add_child(std::make_shared<node>("sub-2-1"));
|
||||||
|
root->add_child(std::make_shared<node>("sub-3"))->add_child(sub_2_1);
|
||||||
|
|
||||||
|
std::cout << "sub-2-1 parent count: " << sub_2_1->parents().size() << std::endl;
|
||||||
|
|
||||||
|
test_visitor tv;
|
||||||
|
|
||||||
|
root->visit(tv);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -1 +1,32 @@
|
||||||
add_subdirectory(src)
|
#add_subdirectory(src)
|
||||||
|
|
||||||
|
|
||||||
|
set(hdrs
|
||||||
|
include/pw/scripting/script.hpp
|
||||||
|
include/pw/scripting/scripting.hpp
|
||||||
|
)
|
||||||
|
|
||||||
|
set(srcs
|
||||||
|
src/script.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(pwscripting
|
||||||
|
STATIC
|
||||||
|
${hdrs}
|
||||||
|
${srcs}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(
|
||||||
|
pwscripting
|
||||||
|
PUBLIC
|
||||||
|
include
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(
|
||||||
|
pwscripting
|
||||||
|
PRIVATE
|
||||||
|
${CMAKE_SOURCE_DIR}/src/deps/lua-5.3.4/src
|
||||||
|
${CMAKE_SOURCE_DIR}/src/deps/sol
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(pwscripting lualib pwcore pwui pwscene)
|
||||||
|
|
|
@ -28,6 +28,4 @@ protected:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
|
|
||||||
set(hdrs
|
|
||||||
../include/pw/scripting/script.hpp
|
|
||||||
../include/pw/scripting/scripting.hpp
|
|
||||||
)
|
|
||||||
|
|
||||||
set(srcs
|
|
||||||
script.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
add_library(pwscripting
|
|
||||||
STATIC
|
|
||||||
${hdrs}
|
|
||||||
${srcs}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(
|
|
||||||
pwscripting
|
|
||||||
PUBLIC
|
|
||||||
../include
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(
|
|
||||||
pwscripting
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_SOURCE_DIR}/src/deps/lua-5.3.4/src
|
|
||||||
${CMAKE_SOURCE_DIR}/src/deps/sol
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(pwscripting lua pwcore)
|
|
|
@ -6,6 +6,10 @@
|
||||||
#include "pw/core/quaternion.hpp"
|
#include "pw/core/quaternion.hpp"
|
||||||
#include "pw/core/axisangle.hpp"
|
#include "pw/core/axisangle.hpp"
|
||||||
|
|
||||||
|
#include "pw/scene/node.hpp"
|
||||||
|
|
||||||
|
#include "pw/ui/window.hpp"
|
||||||
|
|
||||||
|
|
||||||
struct lua_state : public pw::script::state {
|
struct lua_state : public pw::script::state {
|
||||||
|
|
||||||
|
@ -49,15 +53,22 @@ void lua_state::load_modules() {
|
||||||
using namespace pw;
|
using namespace pw;
|
||||||
|
|
||||||
_namespace.new_usertype<vector3d>("vector3",
|
_namespace.new_usertype<vector3d>("vector3",
|
||||||
|
sol::constructors<vector3d(), vector3d(Scalar,Scalar,Scalar)>(),
|
||||||
"set",&vector3d::set,
|
"set",&vector3d::set,
|
||||||
"x", scripting::property(scripting::resolve<const Scalar&() const>(&vector3d::x), &vector3d::set_x),
|
"x", scripting::property(scripting::resolve<const Scalar&() const>(&vector3d::x), &vector3d::set_x),
|
||||||
"y", scripting::property(scripting::resolve<const Scalar&() const>(&vector3d::y), &vector3d::set_y),
|
"y", scripting::property(scripting::resolve<const Scalar&() const>(&vector3d::y), &vector3d::set_y),
|
||||||
"z", scripting::property(scripting::resolve<const Scalar&() const>(&vector3d::z), &vector3d::set_z),
|
"z", scripting::property(scripting::resolve<const Scalar&() const>(&vector3d::z), &vector3d::set_z),
|
||||||
|
"norm",&vector3d::norm,
|
||||||
|
"cross",&vector3d::cross,
|
||||||
|
"dot",&vector3d::dot,
|
||||||
|
// sol::meta_function::addition, sol::resolve<vector3d(const vector3d&, const vector3d&)>(::operator+),
|
||||||
|
// sol::meta_function::subtraction, &vector3d::operator-
|
||||||
// "v",&vector3d::values,
|
// "v",&vector3d::values,
|
||||||
"clone",&vector3d::clone
|
"clone",&vector3d::clone
|
||||||
);
|
);
|
||||||
|
|
||||||
_namespace.new_usertype<quaterniond>("quaternion",
|
_namespace.new_usertype<quaterniond>("quaternion",
|
||||||
|
sol::constructors<quaterniond(), vector3d(Scalar,Scalar,Scalar,Scalar)>(),
|
||||||
"set",&quaterniond::set,
|
"set",&quaterniond::set,
|
||||||
"x", scripting::property(scripting::resolve<const Scalar&() const>(&quaterniond::x), &quaterniond::set_x),
|
"x", scripting::property(scripting::resolve<const Scalar&() const>(&quaterniond::x), &quaterniond::set_x),
|
||||||
"y", scripting::property(scripting::resolve<const Scalar&() const>(&quaterniond::y), &quaterniond::set_y),
|
"y", scripting::property(scripting::resolve<const Scalar&() const>(&quaterniond::y), &quaterniond::set_y),
|
||||||
|
@ -72,11 +83,43 @@ void lua_state::load_modules() {
|
||||||
);
|
);
|
||||||
|
|
||||||
_namespace.new_usertype<axisangled>("axisangle",
|
_namespace.new_usertype<axisangled>("axisangle",
|
||||||
|
sol::constructors<axisangled(), axisangled(vector3d,Scalar)>(),
|
||||||
"axis",scripting::property(&axisangled::axis,&axisangled::set_axis),
|
"axis",scripting::property(&axisangled::axis,&axisangled::set_axis),
|
||||||
"angle",scripting::property(&axisangled::angle,&axisangled::set_angle)
|
"angle",scripting::property(&axisangled::angle,&axisangled::set_angle)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
_namespace.new_usertype<window>("window",
|
||||||
|
"update",&window::update,
|
||||||
|
"set_title",&window::set_title,
|
||||||
|
"set_size",&window::set_size
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
_namespace.new_usertype<node>("node",
|
||||||
|
sol::constructors<node(), node(std::string)>(),
|
||||||
|
"add_child",&node::add_child,
|
||||||
|
"shared",&node::shared,
|
||||||
|
"children",&node::children,
|
||||||
|
"child_count",&node::child_count,
|
||||||
|
"create", []() -> std::shared_ptr<node> {
|
||||||
|
auto ptr = std::make_shared<node>();
|
||||||
|
return ptr;
|
||||||
|
},
|
||||||
|
// "share",scripting::property(scripting::resolve<std::shared_ptr<node>(std::make_shared<node>))
|
||||||
|
"name",scripting::property(&node::name,&node::set_name)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// _namespace.set("something", std::shared_ptr<node>(new node()));
|
||||||
|
|
||||||
|
_namespace["my_func"] = []() -> std::shared_ptr<node> {
|
||||||
|
return std::make_shared<node>();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,10 @@ pw.script:initialize()
|
||||||
|
|
||||||
print("hello pixwerx!")
|
print("hello pixwerx!")
|
||||||
|
|
||||||
local v = pw.vector3.new()
|
local v1 = pw.vector3.new(3,2,1)
|
||||||
v:set(0,1,2)
|
v1:set(0,1,2)
|
||||||
|
|
||||||
print("v",v.x,v.y,v.z)
|
print("v1 ",v1.x,v1.y,v1.z)
|
||||||
|
|
||||||
|
|
||||||
---- objects need to be cloned
|
---- objects need to be cloned
|
||||||
|
@ -23,18 +23,44 @@ print("v",v.x,v.y,v.z)
|
||||||
|
|
||||||
local q = pw.quaternion.new()
|
local q = pw.quaternion.new()
|
||||||
print("q",q.x,q.y,q.z,q.w)
|
print("q",q.x,q.y,q.z,q.w)
|
||||||
|
|
||||||
qi = q:inverse()
|
qi = q:inverse()
|
||||||
print("q.inverse",qi.x,qi.y,qi.z,qi.w)
|
print("q.inverse",qi.x,qi.y,qi.z,qi.w)
|
||||||
|
|
||||||
|
local q2 = pw.quaternion.new(0,0,0,1)
|
||||||
|
|
||||||
qm = pw.quaternion.lerp(q,qi)
|
qm = pw.quaternion.lerp(q,qi)
|
||||||
print("q.m",qm.x,qm.y,qm.z,qm.w)
|
print("q.m",qm.x,qm.y,qm.z,qm.w)
|
||||||
|
|
||||||
--local aa = pw.axisangle.new()
|
|
||||||
|
|
||||||
---- assign vector to axis
|
-- axis angle test
|
||||||
----aa.axis = v
|
local aa = pw.axisangle.new(v1,0.707)
|
||||||
|
|
||||||
--print("aa",aa.axis.x)
|
print("aa.axis",aa.axis.x,aa.axis.y,aa.axis.z)
|
||||||
|
print("aa.angle",aa.angle)
|
||||||
|
|
||||||
|
|
||||||
|
local n_1 = pw.node.new("node-1")
|
||||||
|
local n_2 = pw.node.new("node-2")
|
||||||
|
|
||||||
|
print("node 1: ", n_1.name)
|
||||||
|
print("node 2: ", n_2.name)
|
||||||
|
|
||||||
|
print(pw.node.create())
|
||||||
|
|
||||||
|
print("node children ",n_1:children())
|
||||||
|
|
||||||
|
--print(n_1:shared())
|
||||||
|
--print(pw.my_func())
|
||||||
|
|
||||||
|
--n_1:add_child()
|
||||||
|
|
||||||
|
--local w = pw.window.new()
|
||||||
|
|
||||||
|
--while w:update()
|
||||||
|
--do
|
||||||
|
-- -- print("update")
|
||||||
|
--end
|
||||||
|
|
||||||
--local scene = pw:scene.new()
|
--local scene = pw:scene.new()
|
||||||
|
|
||||||
|
|
|
@ -1 +1,23 @@
|
||||||
add_subdirectory(src)
|
#add_subdirectory(src)
|
||||||
|
|
||||||
|
set(hdrs
|
||||||
|
include/pw/ui/window.hpp
|
||||||
|
)
|
||||||
|
|
||||||
|
set(srcs
|
||||||
|
src/window.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(pwui
|
||||||
|
STATIC
|
||||||
|
${hdrs}
|
||||||
|
${srcs}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(
|
||||||
|
pwui
|
||||||
|
PUBLIC
|
||||||
|
include
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(pwui pwcore glfw glad)
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
set(hdrs
|
|
||||||
../include/pw/ui/window.hpp
|
|
||||||
)
|
|
||||||
|
|
||||||
set(srcs
|
|
||||||
window.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
add_library(pwui
|
|
||||||
STATIC
|
|
||||||
${hdrs}
|
|
||||||
${srcs}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(
|
|
||||||
pwui
|
|
||||||
PUBLIC
|
|
||||||
../include
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(pwui pwcore glfw glad)
|
|
|
@ -2,9 +2,11 @@
|
||||||
|
|
||||||
//#include "glad/glad.h"
|
//#include "glad/glad.h"
|
||||||
|
|
||||||
pw::window::window() {
|
pw::window::window()
|
||||||
|
{
|
||||||
|
glfwInit();
|
||||||
|
|
||||||
_window = glfwCreateWindow(640, 480, "pixwerxs", NULL, NULL);
|
_window = glfwCreateWindow(640, 480, "pixwerxs", nullptr, nullptr);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
glfwMakeContextCurrent(_window);
|
glfwMakeContextCurrent(_window);
|
||||||
|
@ -50,12 +52,8 @@ void pw::window::set_size(int w,int h) {
|
||||||
|
|
||||||
//void pw::window::load(sol::table &ns)
|
//void pw::window::load(sol::table &ns)
|
||||||
//{
|
//{
|
||||||
// glfwInit();
|
//
|
||||||
|
|
||||||
|
|
||||||
// ns.new_usertype<window>("window",
|
|
||||||
// "update",&window::update,
|
|
||||||
// "set_title",&window::set_title,
|
|
||||||
// "set_size",&window::set_size
|
|
||||||
// );
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue