added camera implementation and plenty of other rendering related stuff - splitted out the initialization of the render context

This commit is contained in:
Hartmut Seichter 2018-12-30 23:36:53 +01:00
parent ae37273021
commit f7043fc0cb
43 changed files with 23280 additions and 15161 deletions

Binary file not shown.

View file

@ -3,7 +3,10 @@
add_subdirectory(deps) add_subdirectory(deps)
add_subdirectory(core) add_subdirectory(core)
add_subdirectory(scene) add_subdirectory(scene)
#add_subdirectory(system) add_subdirectory(system)
add_subdirectory(ui) #add_subdirectory(ui)
add_subdirectory(scripting) add_subdirectory(scripting)
add_subdirectory(visual)
add_subdirectory(engine) add_subdirectory(engine)

View file

@ -9,6 +9,7 @@ set(hdrs
include/pw/core/quaternion.hpp include/pw/core/quaternion.hpp
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/globals.hpp include/pw/core/globals.hpp
) )

View file

@ -3,11 +3,14 @@
#include <cstddef> #include <cstddef>
#include <memory> #include <memory>
#include <string>
namespace pw { namespace pw {
using std::shared_ptr; using std::shared_ptr;
typedef float real_t;
} }
#endif #endif

View file

@ -2,11 +2,10 @@
#define PW_CORE_IMAGE_HPP #define PW_CORE_IMAGE_HPP
#include <pw/core/globals.hpp> #include <pw/core/globals.hpp>
#include <pw/core/referenced.hpp>
namespace pw { namespace pw {
class image : public referenced<image> { class image {
}; };

View file

@ -342,6 +342,58 @@ public:
return *this; return *this;
} }
inline static
matrix<4,4,T> projection_from_frustum(T Left,T Right,T Bottom,T Top,T zNear,T zFar)
{
matrix<4,4,T> frustum;
frustum.fill(0);
frustum.at(0,0) = 2 * zNear/(Right-Left);
frustum.at(1,1) = 2 * zNear/(Top-Bottom);
frustum.at(0,2) = (Right+Left)/(Right-Left); //A
frustum.at(1,2) = (Top+Bottom)/(Top-Bottom); //B
frustum.at(2,2) = - (zFar+zNear)/(zFar-zNear); //C
frustum.at(3,2) = -(2 * zFar*zNear)/(zFar-zNear); //D
frustum.at(2,3) = -1;
return frustum;
}
inline static
matrix<4,4,T> orthogonal_projection(T Left, T Right,
T Bottom,T Top,
T Near, T Far)
{
matrix<4,4,T> ortho;
ortho.fill(0);
ortho(0,0) = 2 / (Right-Left);
ortho(1,1) = 2 / (Top-Bottom);
ortho(2,2) = -2 / (Far-Near);
ortho(0,3) = -(Right+Left)/(Right-Left);
ortho(1,3) = -(Top+Bottom)/(Top-Bottom);
ortho(2,3) = -(Far+Near)/(Far-Near);
ortho(3,3) = 1;
return ortho;
}
inline static
matrix<4,4,T> perspective_projection(T fovY, T aspectRatio, T zNear, T zFar)
{
const T height = zNear * tan(fovY/T(360) * pi<T>()); // half height of near plane
const T width = height * aspectRatio; // half width of near plane
return projection_from_frustum(-width, width, -height, height, zNear, zFar );
}
#if TACIT_PIXEL_STUFF_NEEDS_TO_MOVE_TO_SCENE #if TACIT_PIXEL_STUFF_NEEDS_TO_MOVE_TO_SCENE
@ -396,27 +448,7 @@ public:
matrix<4,4,T> matrix<4,4,T>
AngleAxis(const T& radianRotation,const matrix<3,1,T>& vec); AngleAxis(const T& radianRotation,const matrix<3,1,T>& vec);
inline static
matrix<4,4,T> OrthogonalProjection(T Left, T Right,
T Bottom,T Top,
T Near, T Far)
{
matrix<4,4,T> ortho;
ortho.fill(0);
ortho(0,0) = 2 / (Right-Left);
ortho(1,1) = 2 / (Top-Bottom);
ortho(2,2) = -2 / (Far-Near);
ortho(0,3) = -(Right+Left)/(Right-Left);
ortho(1,3) = -(Top+Bottom)/(Top-Bottom);
ortho(2,3) = -(Far+Near)/(Far-Near);
ortho(3,3) = 1;
return ortho;
}
inline static inline static
matrix<4,4,T> Frustum(T Left,T Right,T Bottom,T Top,T zNear,T zFar) matrix<4,4,T> Frustum(T Left,T Right,T Bottom,T Top,T zNear,T zFar)
@ -439,15 +471,6 @@ public:
} }
inline static
matrix<4,4,T> PerspectiveProjection(T fovY, T aspectRatio, T zNear, T zFar)
{
T height = zNear * tan(fovY/T(360) * Pi); // half height of near plane
T width = height * aspectRatio; // half width of near plane
return Frustum(-width, width, -height, height, zNear, zFar );
}
inline static inline static
matrix<4,4,T> LookAt(const matrix<3,1,T>& eye, matrix<4,4,T> LookAt(const matrix<3,1,T>& eye,
const matrix<3,1,T>& target, const matrix<3,1,T>& target,

View file

@ -0,0 +1,50 @@
/*
* Copyright (C) 1999-2017 Hartmut Seichter
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef PW_CORE_SIZE_HPP
#define PW_CORE_SIZE_HPP
#include <pw/core/globals.hpp>
namespace pw {
template <typename T_>
struct size {
T_ dim[2] = { 0, 0};
size(T_ w,T_ h) : dim( { w, h }) {}
const T_ width() { return dim[0]; }
const T_ height() { return dim[1]; }
};
typedef size<int> sizei;
typedef size<float> sizef;
}
#endif

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -16,4 +16,4 @@ target_include_directories(pixwerx
${CMAKE_SOURCE_DIR}/src/scripting/include ${CMAKE_SOURCE_DIR}/src/scripting/include
) )
target_link_libraries(pixwerx pwcore pwui pwscripting) target_link_libraries(pixwerx pwcore pwsystem pwscripting)

View file

@ -1,5 +1,6 @@
set(hdrs set(hdrs
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/nodepath.hpp
@ -10,6 +11,7 @@ set(hdrs
set(srcs set(srcs
src/node.cpp src/node.cpp
src/nodepath.cpp src/nodepath.cpp
src/camera.cpp
src/component.cpp src/component.cpp
src/transform.cpp src/transform.cpp
src/traverser.cpp src/traverser.cpp

View file

@ -0,0 +1,48 @@
#ifndef PW_SCENE_CAMERA_HPP
#define PW_SCENE_CAMERA_HPP
#include <pw/core/matrix.hpp>
#include <pw/scene/component.hpp>
namespace pw {
class camera : public component {
public:
enum clearflags {
color,
depth,
none
};
enum projection {
orthographic,
perspective
};
using component::component;
camera();
void set_projection(const matrix44d &projection);
const matrix44d& projection() const;
protected:
double _fov;
double _near_plane;
double _far_plane;
double _ortho_size = 2;
private:
matrix44d _projection;
};
}
#endif

View file

@ -23,13 +23,9 @@ public:
//! 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; }
explicit component(node* n = nullptr); component();
component(const component& other); component(const component& other);
virtual ~component(); virtual ~component();
protected:
node* _node;
}; };
} }

View file

@ -1,3 +1,27 @@
/*
* Copyright (C) 1999-2017 Hartmut Seichter
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef PW_SCENE_NODE_HPP #ifndef PW_SCENE_NODE_HPP
#define PW_SCENE_NODE_HPP #define PW_SCENE_NODE_HPP
@ -9,8 +33,6 @@
namespace pw { namespace pw {
class traverser;
/** /**
* @brief nodes represent the structure for the scene graph * @brief nodes represent the structure for the scene graph
*/ */
@ -29,21 +51,20 @@ public:
//! copy c'tor //! copy c'tor
node(const node& node); node(const node& node);
//! d'tor
//! wrapper for scripting interface virtual ~node();
std::shared_ptr<node> shared();
//! cloning interface //! cloning interface
virtual node* clone(const unsigned short& copymode) const; virtual ref clone(const unsigned short& copymode) const;
std::string name() const; std::string name() const; //!< get name
void set_name(const std::string &name); void set_name(const std::string &name); //!< set name
//! return list of parents //! return list of parents
inline const ptr_array& parents() const { return _parents; } inline const ptr_array& parents() const { return _parents; }
//! add a child node //! add a child node
std::shared_ptr<node> add_child(std::shared_ptr<node> anode); ref add_child(ref 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; }
@ -57,45 +78,29 @@ public:
//! check if this is the root node //! check if this is the root node
inline bool is_root() const { return parents().empty(); } inline bool is_root() const { return parents().empty(); }
//! d'tor
virtual ~node();
//! list of components //! list of components
const component::array& components() const; const component::array& components() const;
//! add a node as parent node //! add a node component
void add_parent(node *anode); void add_component(component::ref c);
//! visitor to collect data from the graph //! remove a node component
struct visitor { void remove_component(component::ref c);
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 unregister_component(component* c);
ref_array _children; ref_array _children;
ptr_array _parents; ptr_array _parents;
component::array _components; component::array _components;
std::string _name; std::string _name;
private:
//! add a node as parent node
void add_parent(node *anode);
}; };
} }

View file

@ -25,10 +25,10 @@ protected:
matrix44d _global; matrix44d _global;
matrix44d _global_inverse; matrix44d _global_inverse;
std::vector<ref> _path;
}; };
} }
#endif #endif

View file

@ -1,29 +1,32 @@
#ifndef PW_SCENE_TRAVERSER_HPP #ifndef PW_SCENE_TRAVERSER_HPP
#define PW_SCENE_TRAVERSER_HPP #define PW_SCENE_TRAVERSER_HPP
#include <pw/scene/node.hpp>
#include <functional>
namespace pw { namespace pw {
class node; class traverser {
//class traverser { public:
//public:
// enum direction { enum direction {
// up, up,
// down down
// }; };
// traverser(direction dir = direction::down); typedef std::function<void(node*)> edge_function;
// void enter(node* node); direction _direction = direction::up;
// void leave(node* node); edge_function on_enter,on_leave;
//protected: void visit(node* node);
// direction _direction; void bfs(node::ref root);
//}; };
} }

25
src/scene/src/camera.cpp Normal file
View file

@ -0,0 +1,25 @@
#include "pw/scene/camera.hpp"
namespace pw {
camera::camera()
: _fov(60.0)
, _near_plane(0.2)
, _far_plane(1000)
{
set_projection(matrix44d::perspective_projection(_fov,1,_near_plane,_far_plane));
}
void camera::set_projection(const matrix44d& projection)
{
this->_projection = projection;
}
const matrix44d &camera::projection() const
{
return _projection;
}
}

View file

@ -11,30 +11,29 @@
namespace pw { namespace pw {
component::component()
// : _node(n)
component::component(node *n)
: _node(n)
{ {
if (_node != nullptr) { // if (_node != nullptr) {
for (const auto c : _node->components()) { // for (const auto c : _node->components()) {
if (typeid (c.get()).name() == typeid (this).name()) { // if (typeid (c.get()).name() == typeid (this).name()) {
// error // // error
return; // return;
} // }
} // }
_node->register_component(this); //// _node->register_component(this);
} // }
} }
component::component(const component &other) component::component(const component &other)
: _node(other._node) // : _node(other._node)
{ {
} }
component::~component() { component::~component()
if (_node != nullptr) _node->unregister_component(this); {
// if (_node != nullptr) _node->unregister_component(this);
} }

View file

@ -14,7 +14,7 @@ node::node(const node &node)
{ {
} }
node *node::clone(const unsigned short &copymode) const node::ref node::clone(const unsigned short &copymode) const
{ {
return nullptr; return nullptr;
} }
@ -29,7 +29,7 @@ void node::set_name(const std::string &name)
_name = name; _name = name;
} }
std::shared_ptr<node> node::add_child(std::shared_ptr<node> anode) node::ref node::add_child(ref anode)
{ {
anode->add_parent(this); anode->add_parent(this);
_children.push_back(anode); _children.push_back(anode);
@ -41,33 +41,28 @@ void node::add_parent(node *anode)
_parents.push_back(anode); _parents.push_back(anode);
} }
void node::visit(visitor& visitor) //void node::visit(visitor& visitor)
{ //{
visitor.enter(this); // visitor.enter(this);
if (visitor.direction == node::visitor::direction::up) // if (visitor.direction == node::visitor::direction::up)
this->ascend(visitor); // this->ascend(visitor);
else { // else {
this->descend(visitor); // this->descend(visitor);
} // }
visitor.leave(this); // visitor.leave(this);
} //}
void node::ascend(visitor& visitor) //void node::ascend(visitor& visitor)
{ //{
for (auto p : this->parents()) p->visit(visitor); // for (auto p : this->parents()) p->visit(visitor);
} //}
void node::descend(visitor& visitor) //void node::descend(visitor& visitor)
{ //{
for (auto c : this->children()) c->visit(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()
{ {
@ -75,24 +70,21 @@ node::~node()
_parents.clear(); _parents.clear();
} }
// //
// components
// //
// void node::add_component(component::ref c)
{
void node::register_component(component *c) { _components.push_back(c);
_components.push_back(std::shared_ptr<component>(c));
} }
void node::unregister_component(component *c) 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(),std::shared_ptr<component>(c))) != _components.end()) { while ((it = std::find(_components.begin(),_components.end(),std::shared_ptr<component>(c))) != _components.end()) {
// _components.erase(it); _components.erase(it);
// } }
} }
const component::array& node::components() const const component::array& node::components() const

View file

@ -19,8 +19,8 @@ void transform::set_global(const matrix44d &global)
} }
void transform::update() { void transform::update()
{
} }
} }

View file

@ -3,32 +3,50 @@
#include <stack> #include <stack>
#include <iostream> #include <iostream>
#include <queue>
namespace pw { namespace pw {
//traverser::traverser(direction dir)
//{
//}
//void traverser::run(node *root_node) traverser t = traverser();
//{
// std::stack<node*> node_stack;
// node_stack.push(root_node);
// node *n = root_node; void traverser::visit(node *node)
{
// enter node
on_enter(node);
// visit
if (direction::up == _direction)
for (auto p : node->parents()) this->visit(p);
else
for (auto c : node->children()) this->visit(c.get());
// while (!node_stack.empty()) { //leave node
on_leave(node);
}
// if (n->is_leaf()) { void traverser::bfs(node::ref root)
// std::cout << n->name() << std::endl; {
// node_stack.pop(); std::stack<node::ref> q;
// // save q.push(root);
// } else {
// for
//// n = n->children().front().get();
// }
// } node::ref_array leafs;
//}
while (!q.empty())
{
node::ref n = q.top();
std::cout << "d:" << q.size() << " l:" << n->is_leaf() << " n:" << n->name();
// visit n
q.pop();
// add all children
for(auto c : n->children()) q.push(c);
std::cout << std::endl;
}
}
} }

View file

@ -27,9 +27,9 @@ int main(int argc,char **argv) {
// thats the only and most ugly way to register a component // thats the only and most ugly way to register a component
new component(n.get()); // new component(n.get());
new transform(n.get()); n->add_component(std::make_shared<transform>());
std::cout << "n components: " << n->components().size() << std::endl; std::cout << "n components: " << n->components().size() << std::endl;

View file

@ -3,23 +3,23 @@
#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/nodepath.hpp>
//#include <pw/scene/traverser.hpp> #include <pw/scene/traverser.hpp>
#include <iostream> #include <iostream>
struct test_visitor : pw::node::visitor { //struct test_visitor : pw::node::visitor {
virtual void enter(pw::node *n) override; // virtual void enter(pw::node *n) override;
virtual void leave(pw::node *n) override; // virtual void leave(pw::node *n) override;
}; //};
void test_visitor::enter(pw::node *n) //void test_visitor::enter(pw::node *n)
{ //{
std::cout << n->name() << " " << n->is_leaf() << std::endl; // std::cout << n->name() << " " << n->is_leaf() << std::endl;
} //}
void test_visitor::leave(pw::node *n) //void test_visitor::leave(pw::node *n)
{ //{
} //}
#include <iostream> #include <iostream>
@ -37,9 +37,10 @@ int main(int argc,char **argv) {
std::cout << "sub-2-1 parent count: " << sub_2_1->parents().size() << std::endl; std::cout << "sub-2-1 parent count: " << sub_2_1->parents().size() << std::endl;
test_visitor tv;
root->visit(tv); traverser tv;
tv.bfs(root);
return 0; return 0;
} }

View file

@ -1,5 +1,3 @@
#add_subdirectory(src)
set(hdrs set(hdrs
include/pw/scripting/script.hpp include/pw/scripting/script.hpp
@ -8,6 +6,12 @@ set(hdrs
set(srcs set(srcs
src/script.cpp src/script.cpp
src/script_core.hpp
src/script_core.cpp
src/script_system.hpp
src/script_system.cpp
src/script_scene.hpp
src/script_scene.cpp
) )
add_library(pwscripting add_library(pwscripting
@ -16,17 +20,14 @@ add_library(pwscripting
${srcs} ${srcs}
) )
target_include_directories(
pwscripting
PUBLIC
include
)
target_include_directories( target_include_directories(
pwscripting pwscripting
PRIVATE PRIVATE
${CMAKE_SOURCE_DIR}/src/deps/lua-5.3.4/src ${CMAKE_SOURCE_DIR}/src/deps/lua-5.3.4/src
${CMAKE_SOURCE_DIR}/src/deps/sol ${CMAKE_SOURCE_DIR}/src/deps/sol2-2.20.6
PUBLIC
include
) )
target_link_libraries(pwscripting lualib pwcore pwui pwscene) target_link_libraries(pwscripting lualib pwcore pwsystem pwscene)

View file

@ -1,7 +1,7 @@
#ifndef PW_SCRIPTING_SCRIPTING_HPP #ifndef PW_SCRIPTING_SCRIPTING_HPP
#define PW_SCRIPTING_SCRIPTING_HPP #define PW_SCRIPTING_SCRIPTING_HPP
#include "sol.hpp" #include "sol/sol.hpp"
#include <lua.hpp> #include <lua.hpp>
namespace pw { namespace pw {

View file

@ -2,19 +2,18 @@
#include "pw/scripting/scripting.hpp" #include "pw/scripting/scripting.hpp"
#include "pw/core/vector.hpp"
#include "pw/core/quaternion.hpp"
#include "pw/core/axisangle.hpp"
#include "pw/scene/node.hpp" #include "pw/scene/node.hpp"
#include "pw/ui/window.hpp" #include "script_core.hpp"
#include "script_system.hpp"
#include "script_scene.hpp"
namespace pw {
struct lua_state : public pw::script::state { struct lua_state : public script::state {
pw::scripting::state _state; scripting::state _state;
pw::scripting::table _namespace; scripting::table _namespace;
void load_modules(); void load_modules();
@ -46,88 +45,32 @@ void lua_state::load_modules() {
// open all libraries // open all libraries
_state.open_libraries(); _state.open_libraries();
typedef double Scalar; script_core::load(_namespace);
script_system::load(_namespace);
_namespace.set("pi",pw::pi<Scalar>()); script_scene::load(_namespace);
using namespace pw;
_namespace.new_usertype<vector3d>("vector3",
sol::constructors<vector3d(), vector3d(Scalar,Scalar,Scalar)>(),
"set",&vector3d::set,
"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),
"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,
"clone",&vector3d::clone
);
_namespace.new_usertype<quaterniond>("quaternion",
sol::constructors<quaterniond(), vector3d(Scalar,Scalar,Scalar,Scalar)>(),
"set",&quaterniond::set,
"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),
"z", scripting::property(scripting::resolve<const Scalar&() const>(&quaterniond::z), &quaterniond::set_z),
"w", scripting::property(scripting::resolve<const Scalar&() const>(&quaterniond::w), &quaterniond::set_w),
"dot",&quaterniond::dot,
"inverse",&quaterniond::inverse,
"normalized",&quaterniond::normalized,
"lerp",&quaterniond::lerp
// "v",&vector3d::values,
// "clone",&vector3d::clone
);
_namespace.new_usertype<axisangled>("axisangle",
sol::constructors<axisangled(), axisangled(vector3d,Scalar)>(),
"axis",scripting::property(&axisangled::axis,&axisangled::set_axis),
"angle",scripting::property(&axisangled::angle,&axisangled::set_angle)
);
_namespace.new_usertype<window>("window",
"update",&window::update,
"title",sol::writeonly_property(&window::set_title),
"set_size",&window::set_size
);
_namespace.new_usertype<node>("node",
sol::constructors<node(), node(std::string)>(),
"add_child",&node::add_child,
"children",sol::readonly_property(&node::children),
"child_count",sol::readonly_property(&node::child_count),
"create", []() -> std::shared_ptr<node> { return std::make_shared<node>(); },
"is_leaf", sol::readonly_property(&node::is_leaf),
"is_root", sol::readonly_property(&node::is_root),
// "share",scripting::property(scripting::resolve<std::shared_ptr<node>(std::make_shared<node>))
"name",scripting::property(&node::name,&node::set_name)
);
} }
pw::script::script() script::script()
{ {
_state.reset(new lua_state()); _state.reset(new lua_state());
} }
pw::script::~script() script::~script()
{ {
_state = nullptr; _state = nullptr;
} }
int pw::script::run(const std::string &s) int script::run(const std::string &s)
{ {
return _state->run(s); return _state->run(s);
} }
}

View file

@ -0,0 +1,59 @@
#include "script_core.hpp"
#include "pw/core/vector.hpp"
#include "pw/core/quaternion.hpp"
#include "pw/core/axisangle.hpp"
namespace pw {
void script_core::load(sol::table &ns)
{
typedef double Scalar;
ns.set("pi",pw::pi<Scalar>());
ns.new_usertype<vector3d>("vector3",
sol::constructors<vector3d(), vector3d(Scalar,Scalar,Scalar)>(),
"set",&vector3d::set,
"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),
"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,
"clone",&vector3d::clone
);
ns.new_usertype<quaterniond>("quaternion",
sol::constructors<quaterniond(), quaterniond(Scalar,Scalar,Scalar,Scalar)>(),
"set",&quaterniond::set,
"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),
"z", scripting::property(scripting::resolve<const Scalar&() const>(&quaterniond::z), &quaterniond::set_z),
"w", scripting::property(scripting::resolve<const Scalar&() const>(&quaterniond::w), &quaterniond::set_w),
"dot",&quaterniond::dot,
"inverse",scripting::readonly_property(&quaterniond::inverse),
"normalized",&quaterniond::normalized,
"lerp",&quaterniond::lerp
// "v",&vector3d::values,
// "clone",&vector3d::clone
);
ns.new_usertype<axisangled>("axisangle",
sol::constructors<axisangled(), axisangled(vector3d,Scalar)>(),
"axis",scripting::property(&axisangled::axis,&axisangled::set_axis),
"angle",scripting::property(&axisangled::angle,&axisangled::set_angle)
);
}
}

View file

@ -0,0 +1,17 @@
#ifndef PW_SCRIPTING_PRIVATE_CORE_HPP
#define PW_SCRIPTING_PRIVATE_CORE_HPP
#include <pw/scripting/scripting.hpp>
namespace pw {
struct script_core {
static void load(scripting::table& ns);
};
}
#endif

View file

@ -0,0 +1,23 @@
#include "script_scene.hpp"
#include <pw/scene/node.hpp>
namespace pw {
void script_scene::load(sol::table &ns)
{
ns.new_usertype<node>("node",
sol::constructors<node(), node(std::string)>(),
"add_child",&node::add_child,
"children",sol::readonly_property(&node::children),
"child_count",sol::readonly_property(&node::child_count),
"create", []() -> std::shared_ptr<node> { return std::make_shared<node>(); },
"is_leaf", sol::readonly_property(&node::is_leaf),
"is_root", sol::readonly_property(&node::is_root),
// "share",scripting::property(scripting::resolve<std::shared_ptr<node>(std::make_shared<node>))
"name",scripting::property(&node::name,&node::set_name)
);
}
}

View file

@ -0,0 +1,17 @@
#ifndef PW_SCRIPTING_PRIVATE_SCENE_HPP
#define PW_SCRIPTING_PRIVATE_SCENE_HPP
#include <pw/scripting/scripting.hpp>
namespace pw {
struct script_scene {
static void load(scripting::table& ns);
};
}
#endif

View file

@ -0,0 +1,16 @@
#include "script_system.hpp"
#include "pw/system/window.hpp"
namespace pw {
void script_system::load(sol::table &ns)
{
ns.new_usertype<window>("window",
"update",&window::update,
"title",sol::writeonly_property(&window::set_title),
"set_size",&window::set_size
);
}
}

View file

@ -0,0 +1,17 @@
#ifndef PW_SCRIPTING_PRIVATE_SYSTEM_HPP
#define PW_SCRIPTING_PRIVATE_SYSTEM_HPP
#include <pw/scripting/scripting.hpp>
namespace pw {
struct script_system {
static void load(scripting::table& ns);
};
}
#endif

View file

@ -24,12 +24,12 @@ print("v1 ",v1.x,v1.y,v1.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) local q2 = pw.quaternion.new(0,0,0,1)
qm = pw.quaternion.lerp(q,qi) qm = pw.quaternion.lerp(q,qi,0.5)
print("q.m",qm.x,qm.y,qm.z,qm.w) print("q.m",qm.x,qm.y,qm.z,qm.w)
@ -71,6 +71,8 @@ local w = pw.window.new()
w.title = "pixwerx 1.0" w.title = "pixwerx 1.0"
w:set_size(1280,768)
while w:update() while w:update()
do do
-- print("update") -- print("update")

24
src/system/CMakeLists.txt Normal file
View file

@ -0,0 +1,24 @@
set(hdrs
include/pw/system/window.hpp
)
set(srcs
src/window.cpp
)
add_library(pwsystem
STATIC
${hdrs}
${srcs}
)
target_include_directories(
pwsystem
PUBLIC
include
)
target_link_libraries(pwsystem pwcore pwvisual glfw glad)
#add_subdirectory(tests)

View file

@ -0,0 +1,33 @@
#ifndef PW_WINDOW_HPP
#define PW_WINDOW_HPP
#include <pw/core/globals.hpp>
namespace pw {
class window {
public:
window();
~window();
bool update();
void set_title(const std::string& title);
void set_size(int w, int h);
// context* get_context();
int get_heigth();
int get_width();
protected:
struct impl;
std::unique_ptr<impl> _impl;
};
}
#endif

143
src/system/src/window.cpp Normal file
View file

@ -0,0 +1,143 @@
#include "pw/system/window.hpp"
#include "GLFW/glfw3.h"
//#include "glad/glad.h"
#include "pw/visual/context.hpp"
#include <iostream>
namespace pw {
struct window_context : context {
virtual bool make_current() override;
virtual void resize() override;
// virtual context::size size() override;
virtual void flush() override;
};
bool window_context::make_current()
{
}
void window_context::resize()
{
}
void window_context::flush()
{
}
struct window::impl {
GLFWwindow *_window = nullptr;
// window_context _context;
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
window::impl* impl = static_cast<window::impl*>(glfwGetWindowUserPointer(window));
// impl->on_resize(width,height);
// std::cout << "framebuffer " << width << "x" << height << std::endl;
// glViewport(0, 0, width, height);
}
impl()
{
glfwInit();
_window = glfwCreateWindow(640, 480, "pixwerxs", nullptr, nullptr);
glfwSetWindowUserPointer(_window,this);
glfwSetFramebufferSizeCallback(_window, window::impl::framebuffer_size_callback);
#if 0
glfwMakeContextCurrent(_window);
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
#endif
}
~impl()
{
glfwDestroyWindow(_window);
}
bool update()
{
if (!glfwWindowShouldClose(_window)) {
glfwPollEvents();
// do other stuff
#if 0
glClearColor(1,0,0,1);
glClear(GL_COLOR_BUFFER_BIT);
#endif
glfwSwapBuffers(_window);
return true;
}
return false;
}
void set_title(const std::string& title)
{
glfwSetWindowTitle(_window,title.c_str());
}
void set_size(int w,int h)
{
glfwSetWindowSize(_window,w,h);
}
};
window::window()
: _impl(std::make_unique<window::impl>())
{
}
window::~window()
{
}
bool window::update()
{
return _impl->update();
}
void window::set_title(const std::string& title)
{
_impl->set_title(title);
}
void window::set_size(int w,int h)
{
_impl->set_size(w,h);
}
int window::get_width()
{
// int w,h;
// glfwGetWindowSize(_window,&w,&h);
// return w;
}
int window::get_heigth()
{
// int w,h;
// glfwGetWindowSize(_window,&w,&h);
// return h;
}
}

View file

@ -1,43 +0,0 @@
#ifndef PW_WINDOW_HPP
#define PW_WINDOW_HPP
//#include "glad/glad.h"
#include "GLFW/glfw3.h"
//#include "sol.hpp"
namespace pw {
class window;
class context {
GLFWwindow* _window;
public:
context(window& other);
~context();
};
class window {
GLFWwindow* _window;
public:
window();
~window();
bool update();
void set_title(const char* t);
void set_size(int w, int h);
context* get_context();
// static void load(sol::table &ns);
};
}
#endif

View file

@ -1,66 +0,0 @@
#include "pw/ui/window.hpp"
//#include "glad/glad.h"
pw::window::window()
{
glfwInit();
_window = glfwCreateWindow(640, 480, "pixwerxs", nullptr, nullptr);
#if 0
glfwMakeContextCurrent(_window);
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
#endif
}
pw::window::~window() {
glfwDestroyWindow(_window);
}
bool pw::window::update()
{
if (!glfwWindowShouldClose(_window)) {
// do other stuff
#if 0
glClearColor(1,0,0,1);
glClear(GL_COLOR_BUFFER_BIT);
#endif
glfwSwapBuffers(_window);
glfwPollEvents();
return true;
}
return false;
}
void pw::window::set_title(const char *t)
{
glfwSetWindowTitle(_window,t);
}
void pw::window::set_size(int w,int h) {
glfwSetWindowSize(_window,w,h);
}
std::pair<int,int> pw::window::get_size()
{
int x,y;
glfwGetWindowSize(_window,&x,&y);
return std::make_pair(x,y);
}
//void pw::window::load(sol::table &ns)
//{
//
//}

26
src/visual/CMakeLists.txt Normal file
View file

@ -0,0 +1,26 @@
set(hdrs
include/pw/visual/renderer.hpp
include/pw/visual/context.hpp
)
set(srcs
src/renderer.cpp
src/context.cpp
)
add_library(pwvisual
STATIC
${hdrs}
${srcs}
)
target_include_directories(
pwvisual
PUBLIC
include
)
target_link_libraries(pwvisual pwscene)
#add_subdirectory(tests)

View file

@ -0,0 +1,25 @@
#ifndef PW_VISUAL_CONTEXT_HPP
#define PW_VISUAL_CONTEXT_HPP
#include <pw/scene/component.hpp>
namespace pw {
class context {
public:
struct size {
int width,height;
};
virtual bool make_current() = 0;
virtual void resize() = 0;
virtual size size() = 0;
virtual void flush() = 0;
virtual ~context() = default;
};
}
#endif

View file

@ -0,0 +1,19 @@
#ifndef PW_VISUAL_RENDERER_HPP
#define PW_VISUAL_RENDERER_HPP
#include <pw/scene/component.hpp>
namespace pw {
class context;
class renderer {
void render(context& context);
};
}
#endif

View file

View file

@ -0,0 +1,9 @@
#include "pw/visual/renderer.hpp"
namespace pw {
void renderer::render(pw::context &context)
{
}
}