diff --git a/src/core/include/pw/core/matrix.hpp b/src/core/include/pw/core/matrix.hpp index 2f9a13f..2843872 100644 --- a/src/core/include/pw/core/matrix.hpp +++ b/src/core/include/pw/core/matrix.hpp @@ -48,6 +48,11 @@ public: matrix_& operator = (const matrix_& other); + matrix_(std::initializer_list il) + { +// for (int i = 0;i < il.size();i++) (*this).at(i) = il[i]; + } + matrix_ transposed() const; inline matrix_& operator *= (const T& b) { for (unsigned int i = this->cells(); i--> 0;) this->at(i) *= b; return *this; } @@ -102,7 +107,7 @@ public: matrix_& copy_from_data(const T* src) { for (unsigned int i = 0; i < R*C; ++i) { (*this).at(i) = src[i]; } return *this; } matrix_ operator * (const matrix_& rhs) const { - return mul(*this,rhs); + return mul(rhs); } const matrix_ reshape() const { @@ -124,6 +129,26 @@ public: } void normalize(); + + template + matrix_ mul(const matrix_& B) const + { + // aC == bR + // set all null + matrix_ res; + res.fill(0); + + // compute all resulting cells + for (unsigned int r = 0; r < R; ++r) { + for (unsigned int c = 0; c < bC; ++c) { + // building inner product + for (unsigned int iI = 0; iI < R;iI++) { + res.at(r,c) += (*this).at(r,iI) * B.at(iI,c); + } + } + } + return res; + } }; ///////////////////////////////////////////////////////////////////////////// @@ -176,28 +201,32 @@ inline matrix_ operator - (const matrix_& a, const matrix_& return res; } + + +//template +//matrix_ static inline +//mul(const matrix_& A, const matrix_& B) +//{ +// // aC == bR +// // set all null +// matrix_ res; +// res.fill(0); + +// // compute all resulting cells +// for (unsigned int r = 0; r < aR; ++r) { +// for (unsigned int c = 0; c < bC; ++c) { +// // building inner product +// for (unsigned int iI = 0; iI < aCbR;iI++) { +// res.at(r,c) += A.at(r,iI) * B.at(iI,c); +// } +// } +// } +// return res; +//} + + ///////////////////////////////////////////////////////////////////////////// -template -matrix_ static inline -mul(const matrix_& A, const matrix_& B) -{ - // aC == bR - // set all null - matrix_ res; - res.fill(0); - - // compute all resulting cells - for (unsigned int r = 0; r < aR; ++r) { - for (unsigned int c = 0; c < bC; ++c) { - // building inner product - for (unsigned int iI = 0; iI < aCbR;iI++) { - res.at(r,c) += A.at(r,iI) * B.at(iI,c); - } - } - } - return res; -} @@ -206,7 +235,7 @@ mul(const matrix_& A, const matrix_& B) template matrix_& matrix_::operator *= (const matrix_& rhs) { - *this = mul(*this,rhs); + *this = mul(rhs); return *this; } diff --git a/src/core/include/pw/core/matrixbase.hpp b/src/core/include/pw/core/matrixbase.hpp index 327a88e..85608ec 100644 --- a/src/core/include/pw/core/matrixbase.hpp +++ b/src/core/include/pw/core/matrixbase.hpp @@ -23,6 +23,9 @@ #ifndef PW_CORE_MATRIXBASE_HPP #define PW_CORE_MATRIXBASE_HPP + +#include + namespace pw { /** @@ -36,6 +39,9 @@ public: typedef unsigned int size_type; + matrixbase() {} + + //! assignment constructor explicit matrixbase(int rows, int cols,T* ptr,bool row_major,int data_offset = 0) : _data(ptr) @@ -47,6 +53,11 @@ public: { } +// matrixbase(std::initializer_list il) +// { +// for (int i = 0;i < il.size();i++) this->at(i) = il[i]; +// } + inline const T& get_element(int e) const { return this->at(e); } inline void set_element(int e,const T &v) { this->at(e) = v; } diff --git a/src/core/include/pw/core/mesh.hpp b/src/core/include/pw/core/mesh.hpp index e2b5852..7b85d57 100644 --- a/src/core/include/pw/core/mesh.hpp +++ b/src/core/include/pw/core/mesh.hpp @@ -51,6 +51,8 @@ public: const indexarray_t& indices() const { return _indices; } const vertex3array_t& vertices() const { return _vertices; } + void apply(const matrix4x4& m); + void reset(); protected: diff --git a/src/core/include/pw/core/rect.hpp b/src/core/include/pw/core/rect.hpp index 8c91b54..779626f 100644 --- a/src/core/include/pw/core/rect.hpp +++ b/src/core/include/pw/core/rect.hpp @@ -38,7 +38,7 @@ struct rect_ { rect_(point_ const & p,size_ const & s) : size(s), position(p) {} - bool contains(const point_& p) + bool contains(const point_& p) const { return p.x >= position.x && p.x <= position.x + size.width && p.y >= position.y && p.y <= position.y + size.height; diff --git a/src/core/include/pw/core/vector.hpp b/src/core/include/pw/core/vector.hpp index 9875df1..bd1d2a7 100644 --- a/src/core/include/pw/core/vector.hpp +++ b/src/core/include/pw/core/vector.hpp @@ -98,8 +98,8 @@ public: T& z() { return (*this)(2); } - const vector_<4,T> project(const T& w) const { - return vector_<4,T>(x(),y(),z(),w); + vector_<4,T> project(const T& w) const { + return vector_<4,T>({ x(),y(),z(),w } ); } const vector_<2,T> unproject() const { diff --git a/src/core/src/mesh.cpp b/src/core/src/mesh.cpp index 1423211..7e69764 100644 --- a/src/core/src/mesh.cpp +++ b/src/core/src/mesh.cpp @@ -3,6 +3,17 @@ namespace pw { +void mesh::apply(const matrix4x4 &m) +{ + for (auto &v : _vertices) + { +// v = m * v.project(1); + + auto vh = v.project(1); + m.mul(vh); + } +} + } diff --git a/src/core/src/timer.cpp b/src/core/src/timer.cpp index 16ae81e..f6c5c44 100644 --- a/src/core/src/timer.cpp +++ b/src/core/src/timer.cpp @@ -24,8 +24,6 @@ namespace pw { -static timer global_timer; - timer::timer() { reset(); @@ -48,6 +46,7 @@ double timer::elapsed() const double timer::now() { + static timer global_timer; return global_timer.elapsed(); } diff --git a/src/scripting/src/script_system.cpp b/src/scripting/src/script_system.cpp index 96d81b8..bbc45cc 100644 --- a/src/scripting/src/script_system.cpp +++ b/src/scripting/src/script_system.cpp @@ -17,7 +17,8 @@ void script_system::load(sol::table &ns) "size",sol::property(&window::size,&window::set_size), "client_size",sol::readonly_property(&window::client_size), "position",sol::property(&window::position,&window::set_position), - "fullscreen",sol::property(&window::fullscreen,&window::set_fullscreen) + "fullscreen",sol::property(&window::fullscreen,&window::set_fullscreen), + "visible",sol::property(&window::visible,&window::set_visible) ); diff --git a/src/scripts/demos/simple_000.lua b/src/scripts/demos/simple_000.lua index 8fea86d..2145f44 100644 --- a/src/scripts/demos/simple_000.lua +++ b/src/scripts/demos/simple_000.lua @@ -66,6 +66,7 @@ end --n_1:add_child() local w = pw.window.new() +w.visible = false -- set title w.title = "pixwerx 0.1" @@ -75,6 +76,8 @@ w.size = pw.size.new(800,600) -- move window w.position = pw.point.new(100,100) +print("client size after resize: ",w.client_size.width,w.client_size.height) + local pl = pw.pipeline.new() if pl:create(w.client_size) then @@ -83,12 +86,11 @@ else print("pipeline failed") end - --- setup a lua callback function +-- setup a lua callback function as callback w.on_update = function(self) - pl:draw() -- print("test on update",w.position.x,w.position.y,pw.timer.now) + end local ds = pw.display:all() @@ -98,8 +100,9 @@ end local t = pw.timer.new() -while w:update() -do +w.visible = true + +while w:update() do -- somehow works if (pw.input.get().input_string == 'f') then w.fullscreen = not w.fullscreen @@ -109,7 +112,7 @@ do if (pw.input:get().mouse_button == 1) then print("elapsed",t.elapsed) t:reset() - print(pw.input:get().mouse_position.x,pw.input:get().mouse_position.y) + print(pw.input:get().mouse_position.x,pw.input:get().mouse_position.y,w.client_size.width,w.client_size.height) end -- print("update") diff --git a/src/system/include/pw/system/input.hpp b/src/system/include/pw/system/input.hpp index 337f1b4..6eeddcc 100644 --- a/src/system/include/pw/system/input.hpp +++ b/src/system/include/pw/system/input.hpp @@ -40,6 +40,9 @@ private: int _mouse_button; bool _mouse_pressed; + int _key_code; + bool _key_pressed; + std::string _input_string; diff --git a/src/system/include/pw/system/window.hpp b/src/system/include/pw/system/window.hpp index 1c20213..0a9d585 100644 --- a/src/system/include/pw/system/window.hpp +++ b/src/system/include/pw/system/window.hpp @@ -35,6 +35,8 @@ public: void set_on_update(on_update_t f) { _on_update = f; } + bool visible() const; + void set_visible(bool is_visible); protected: on_update_t _on_update; diff --git a/src/system/src/window.cpp b/src/system/src/window.cpp index e9fea3e..e8a50d9 100644 --- a/src/system/src/window.cpp +++ b/src/system/src/window.cpp @@ -70,12 +70,15 @@ struct window::impl { static void cursor_pos_callback(GLFWwindow* window, double xpos, double ypos) { - input::get()._mouse_position = point(xpos,ypos); + input::get()._mouse_position = pointd(xpos,ypos).cast(); } static void key_callback(GLFWwindow *window,int key, int scancode, int action, int mods) { - std::cout << __FUNCTION__ << std::endl; + input::get()._key_code = scancode; + input::get()._key_pressed = action; + // action 0,1,2 +// std::cout << __FUNCTION__ << action << std::endl; } // static void character_callback(GLFWwindow* window, unsigned int codepoint) @@ -167,7 +170,7 @@ struct window::impl { glfwSetWindowUserPointer(_window,this); - glfwSetFramebufferSizeCallback(_window, window::impl::framebuffer_size_callback); + //glfwSetFramebufferSizeCallback(_window, window::impl::framebuffer_size_callback); glfwSetKeyCallback(_window, window::impl::key_callback); // glfwSetCharCallback(_window, character_callback); glfwSetCharModsCallback(_window, charmods_callback); @@ -200,13 +203,6 @@ struct window::impl { _parent._on_update(_parent); - - // do other stuff -#if 0 - glClearColor(1,0,0,1); - glClear(GL_COLOR_BUFFER_BIT); -#endif - glfwSwapBuffers(_window); return true; @@ -280,6 +276,14 @@ struct window::impl { bool fullscreen() const { return glfwGetWindowMonitor(_window) != nullptr; } + + void set_visible(bool show) { + (show) ? glfwShowWindow(_window) : glfwHideWindow(_window); + } + + bool visible() const { + return glfwGetWindowAttrib(_window, GLFW_VISIBLE) > 0; + } }; @@ -343,6 +347,15 @@ void window::set_fullscreen(bool use_fullscreen) _impl->set_fullscreen(use_fullscreen); } +bool window::visible() const +{ + return _impl->visible(); +} + +void window::set_visible(bool is_visible) +{ + _impl->set_visible(is_visible); +} diff --git a/src/visual/src/pipeline.cpp b/src/visual/src/pipeline.cpp index 1ba3956..ced54c3 100644 --- a/src/visual/src/pipeline.cpp +++ b/src/visual/src/pipeline.cpp @@ -42,7 +42,7 @@ struct triangle_renderer glBindVertexArray(vao); glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, vbo); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr); const char* vertex_shader = "#version 400\n" @@ -56,7 +56,7 @@ struct triangle_renderer "#version 400\n" "out vec4 frag_colour;" "void main() {" - " frag_colour = vec4(0.5, 0.0, 0.5, 1.0);" + " frag_colour = vec4(0.1, 0.0, 0.5, 1.0);" "}"; #if 0 GLuint vs = glCreateShader(GL_VERTEX_SHADER); @@ -185,10 +185,13 @@ bool pipeline::impl::create(sizei size) void pipeline::impl::draw() { + glClearColor(0,0,0,1); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _fbo_msaa); - glClearColor(1,0,0,1); - glClear(GL_COLOR_BUFFER_BIT); + glClearColor(1,1,1,1); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); tr.draw(); @@ -225,7 +228,12 @@ void pipeline::impl::draw() GL_COLOR_BUFFER_BIT, // buffer mask GL_LINEAR); // scale filter - debug::d() << _size.width << "x" << _size.height; + + + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); + + // debug::d() << _size.width << "x" << _size.height; #endif