diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7dfd7d4..36776fb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,13 +1,13 @@ -#add_subdirectory(deps) +add_subdirectory(deps) add_subdirectory(core) -#add_subdirectory(scene) -#add_subdirectory(system) -#add_subdirectory(io) +add_subdirectory(scene) +add_subdirectory(system) +add_subdirectory(io) #add_subdirectory(ui) -#add_subdirectory(scripting) -#add_subdirectory(visual) -#add_subdirectory(geometry) +add_subdirectory(scripting) +add_subdirectory(visual) +add_subdirectory(geometry) -#add_subdirectory(engine) +add_subdirectory(engine) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index a06fc56..224d3ee 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,37 +1,37 @@ set(hdrs include/pw/core/debug.hpp - include/pw/core/axisangle.hpp + 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/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/point.hpp include/pw/core/rect.hpp include/pw/core/size.hpp include/pw/core/timer.hpp - include/pw/core/mesh.hpp + include/pw/core/mesh.hpp include/pw/core/globals.hpp include/pw/core/image.hpp ) set(misc - ${CMAKE_SOURCE_DIR}/README.md - ${CMAKE_SOURCE_DIR}/LICENSE - ${CMAKE_SOURCE_DIR}/TODO.md - ) + ${CMAKE_SOURCE_DIR}/README.md + ${CMAKE_SOURCE_DIR}/LICENSE + ${CMAKE_SOURCE_DIR}/TODO.md + ) set(srcs -# src/buffer.cpp + # src/buffer.cpp src/image.cpp src/debug.cpp -# src/mesh.cpp + src/mesh.cpp src/core.cpp - src/serialize.cpp + src/serialize.cpp src/timer.cpp src/image.cpp ) @@ -40,7 +40,7 @@ add_library(pwcore STATIC ${hdrs} ${srcs} - ${misc} + ${misc} ) target_include_directories( diff --git a/src/core/include/pw/core/matrix.hpp b/src/core/include/pw/core/matrix.hpp index 90e25cb..f199377 100644 --- a/src/core/include/pw/core/matrix.hpp +++ b/src/core/include/pw/core/matrix.hpp @@ -57,15 +57,12 @@ struct matrix_ : matrixbase_> return *this; } - - explicit matrix_(std::initializer_list args) + matrix_(std::initializer_list args) { typename std::initializer_list::iterator it = args.begin(); for (;it != args.end();it++) data[it-args.begin()] = *it; } - - template matrix_& set(Arguments ...values) { @@ -200,7 +197,11 @@ struct matrix_ : matrixbase_> return r; } - + auto column(size_t col_) const { + col_type c; + for (size_t i = 0; i < rows; i++) c[i] = (*this)(i,col_); + return c; + } }; template <> inline @@ -218,15 +219,15 @@ double matrix_<1,1,double>::determinant() const template auto operator * (const matrix_& A, - const matrix_& B - ) + const matrix_& B + ) { - matrix_ result; result.zero(); // zero the output - for (size_t r = 0; r < R; r++) - for (size_t c = 0; c < Cb; c++) - for (size_t iI = 0; iI < R; iI++) - result(r,c) += A(r,iI) * B(iI,c); // inner product - return result; + matrix_ result; result.zero(); // zero the output + for (size_t r = 0; r < R; r++) + for (size_t c = 0; c < Cb; c++) + for (size_t iI = 0; iI < R; iI++) + result(r,c) += A(r,iI) * B(iI,c); // inner product + return result; } @@ -236,48 +237,79 @@ auto operator * (const matrix_& A, template using matrix2x2_ = matrix_<2, 2, T>; -//template using matrix3x3_ = matrix_; -//template using matrix4x4_ = matrix_; +template using matrix3x3_ = matrix_<3, 3, T>; +template using matrix4x4_ = matrix_<4, 4, T>; using matrix2x2f = matrix_<2, 2,float>; using matrix2x2d = matrix_<2, 2,double>; using matrix2x2 = matrix_<2, 2,real_t>; -//using matrix3x3f = matrix_; -//using matrix3x3d = matrix_; -//using matrix3x3 = matrix_; +using matrix3x3f = matrix_<3, 3,float>; +using matrix3x3d = matrix_<3, 3,double>; +using matrix3x3 = matrix_<3, 3,real_t>; -//using matrix4x4f = matrix_; -//using matrix4x4d = matrix_; -//using matrix4x4 = matrix_; +using matrix4x4f = matrix_<4, 4,float>; +using matrix4x4d = matrix_<4, 4,double>; +using matrix4x4 = matrix_<4, 4,real_t>; // // // -//template -//struct matrix_tools { +template +struct transform_tools { -// inline static -// matrix4x4_ projection_from_frustum(T Left,T Right,T Bottom,T Top,T zNear,T zFar) -// { -// matrix4x4_ frustum; + inline static + matrix4x4_ projection_from_frustum(T Left,T Right,T Bottom,T Top,T zNear,T zFar) + { + matrix4x4_ frustum; -// frustum.fill(0); + frustum.fill(0); -// frustum(0,0) = T(2) * zNear/(Right-Left); -// frustum(1,1) = T(2) * zNear/(Top-Bottom); + frustum(0,0) = T(2) * zNear/(Right-Left); + frustum(1,1) = T(2) * zNear/(Top-Bottom); -// frustum(0,2) = (Right+Left)/(Right-Left); //A -// frustum(1,2) = (Top+Bottom)/(Top-Bottom); //B -// frustum(2,2) = - (zFar+zNear)/(zFar-zNear); //C -// frustum(3,2) = -(T(2) * zFar*zNear)/(zFar-zNear); //D + frustum(0,2) = (Right+Left)/(Right-Left); //A + frustum(1,2) = (Top+Bottom)/(Top-Bottom); //B + frustum(2,2) = - (zFar+zNear)/(zFar-zNear); //C + frustum(3,2) = -(T(2) * zFar*zNear)/(zFar-zNear); //D -// frustum(2,3) = -T(1); + frustum(2,3) = -T(1); -// return frustum; -// } -//}; + 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()); // 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 ); + } +}; } @@ -624,57 +656,6 @@ public: 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()); // 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 diff --git a/src/core/include/pw/core/mesh.hpp b/src/core/include/pw/core/mesh.hpp index db4f20d..8843179 100644 --- a/src/core/include/pw/core/mesh.hpp +++ b/src/core/include/pw/core/mesh.hpp @@ -1,6 +1,3 @@ -#ifndef PW_CORE_MESH_HPP -#define PW_CORE_MESH_HPP - /* * Copyright (c) 1999-2019 Hartmut Seichter * @@ -23,6 +20,9 @@ * SOFTWARE. * */ +#ifndef PW_CORE_MESH_HPP +#define PW_CORE_MESH_HPP + #include #include diff --git a/src/core/include/pw/core/quaternion.hpp b/src/core/include/pw/core/quaternion.hpp index 0689a2d..51a62de 100644 --- a/src/core/include/pw/core/quaternion.hpp +++ b/src/core/include/pw/core/quaternion.hpp @@ -34,16 +34,18 @@ namespace pw { template struct quaternion_ : vector4_ { - typedef vector4_ Base; + typedef vector4_ base_type; - using Base::Base; - using Base::x; - using Base::y; - using Base::z; - using Base::w; - using Base::lerp; - using Base::operator*; - using Base::operator/; + using base_type::base_type; + using base_type::x; + using base_type::y; + using base_type::z; + using base_type::w; + using base_type::lerp; + using base_type::operator*; + using base_type::operator/; + + quaternion_(const base_type& other) : base_type(other) {} inline const quaternion_ operator * (const quaternion_& rhs) const { return quaternion_( @@ -97,7 +99,7 @@ struct quaternion_ : vector4_ { return m; } - static quaternion_ from_matrix(const matrix_ &m) { + static quaternion_ from_matrix(const matrix_<4,4,T> &m) { using std::sqrt; const T wtemp = sqrt(T(1) + m(0,0) + m(1,1) + m(2,2)) / T(2); const T w4 = T(4.0) * wtemp; diff --git a/src/core/include/pw/core/vector.hpp b/src/core/include/pw/core/vector.hpp index db427df..01960dd 100644 --- a/src/core/include/pw/core/vector.hpp +++ b/src/core/include/pw/core/vector.hpp @@ -27,19 +27,6 @@ namespace pw { -//template -//struct vector_ : matrix_ -//{ -// static const size_t coefficients = N; - -// using matrix_::matrix_; -// using matrix_::operator =; - -//// static T angle_between(const vector_ &a,const vector_ &b) { -//// return std::acos( dot( a.normalized(), b.normalized() ) ); -//// } -//}; - template struct vector2_ : matrix_<2,1,T> { @@ -49,6 +36,7 @@ struct vector2_ : matrix_<2,1,T> { using base_type::operator = ; vector2_(const base_type& m) : base_type(m) {} + vector2_(T x_,T y_) : base_type({x_,y_}) {} inline const T& x() const { return (*this)[0]; } inline T& x() { return (*this)[0]; } @@ -58,6 +46,10 @@ struct vector2_ : matrix_<2,1,T> { inline auto homogenous(T w = 1) const { return matrix_<3,1,T>( { x(),y(),w } ); } + static T angle_between(const vector2_ &a,const vector2_ &b) { + return std::acos( dot( a.normalized(), b.normalized() ) ); + } + }; template @@ -69,7 +61,7 @@ struct vector3_ : matrix_<3,1,T> { using base_type::operator = ; vector3_(const base_type& m) : base_type(m) {} - + vector3_(T x_,T y_,T z_) : base_type({x_,y_,z_}) {} inline const T& x() const { return (*this)[0]; } inline T& x() { return (*this)[0]; } @@ -83,6 +75,16 @@ struct vector3_ : matrix_<3,1,T> { inline auto xy() const { return vector2_( { x(),y() } ); } inline auto homogenous(T w = 1) const { return matrix_<4,1,T>( { x(),y(),z(),w } ); } + inline const vector3_ cross(const vector3_& rhs) const { + return vector3_( { + (*this)[1] * rhs[2] - rhs[1] * (*this)[2], + (*this)[2] * rhs[0] - rhs[2] * (*this)[0], + (*this)[0] * rhs[1] - rhs[0] * (*this)[1] + } + ); + } + + inline static vector3_ forward() { return vector3_ ( { T(0), T(0),-T(1) } ); } inline static vector3_ backward() { return vector3_( { T(0), T(0), T(1) } ); } inline static vector3_ right() { return vector3_ ( { T(1), T(0), T(0) } ); } @@ -92,15 +94,16 @@ struct vector3_ : matrix_<3,1,T> { }; - -#if defined(_D) - - - template -struct vector4_ : vector_ { +struct vector4_ : matrix_<4,1,T> { - using vector_::vector_; + typedef matrix_<4,1,T> base_type; + + using base_type::base_type; + using base_type::operator = ; + + vector4_(T x_,T y_,T z_,T w_) : base_type({x_,y_,z_,w_}) {} + vector4_(const base_type& m) : base_type(m) {} inline const T& x() const { return (*this)[0]; } inline T& x() { return (*this)[0]; } @@ -117,221 +120,24 @@ struct vector4_ : vector_ { inline auto xyz() const { return vector3_({ x(),y(),z() } ); } inline auto project() const { return vector3_({ x()/w(),y()/w(),z()/w() } ); } - }; - -#endif // // // using vector2f = vector2_; using vector2d = vector2_; -//using vector2 = vector2_; +using vector2 = vector2_; -//using vector3f = vector3_; -//using vector3d = vector3_; -//using vector3 = vector3_; - -//using vector4f = vector4_; -//using vector4d = vector4_; -//using vector4 = vector4_; +using vector3f = vector3_; +using vector3d = vector3_; +using vector3 = vector3_; +using vector4f = vector4_; +using vector4d = vector4_; +using vector4 = vector4_; } - -#if defined(___OLDSTUFF) - -template -class vector_ : public matrix_ { -public: - - using typename matrix_::value_type; - using matrix_::operator = ; - - vector_() : matrix_() {} - - vector_(const vector_& other) : matrix_(other) {} - - vector_(const matrix_& other) : matrix_(other) {} - - T& operator()(unsigned int c) { return matrixbase::at(c); } - const T& operator()(unsigned int c) const { return matrixbase::at(c); } - - - const T dot(const vector_& other) const { - T res = 0; - for (unsigned int i = 0; i < components; i++) res += (*this)(i) * other(i); - return res; - } - - const T angle_to(const vector_& other) const { - using std::acos; - vector_ nself(*this); vector_ nothr = other; - nself.normalize(); nothr.normalize(); - return acos( nothr.dot(nself) ); - } - - - vector_ homogenous(const T& w) const { - return vector_(); - } - - const vector_<2,T> project() const { - return vector_<2,T>(x()/z(),y()/z()); - } - -}; - - -// Vec3 ----------------------------------------------------------------------- - -template -class vector3_ : public vector_<3,T> { -public: - - using vector_<3,T>::operator=; - - vector3_() : vector_<3,T>() {} - - vector3_(const vector_<3,T>& other) : vector_<3, T> (other) {} - - vector3_(T c1, T c2, T c3) { this->set(c1,c2,c3); } - - void set(T c1, T c2, T c3) { (*this)(0) = c1; (*this)(1) = c2; (*this)(2) = c3; } - - vector3_ clone() const { return vector3_(*this); } - - inline void set_x(const T& v) { x() = v; } - inline void set_y(const T& v) { y() = v; } - inline void set_z(const T& v) { z() = v; } - - inline const vector3_ cross(const vector3_& vec2) const { - return vector3_((*this)(1) * vec2(2) - vec2(1) * (*this)(2), - (*this)(2) * vec2(0) - vec2(2) * (*this)(0), - (*this)(0) * vec2(1) - vec2(0) * (*this)(1)); - } - - inline const T& x() const { return (*this)(0); } - inline T& x() { return (*this)(0); } - - const T& y() const { return (*this)(1); } - T& y() { return (*this)(1); } - - const T& z() const { return (*this)(2); } - T& z() { return (*this)(2); } - - - - inline static vector3_ forward() { return vector3_ ( 0, 0,-1); } - inline static vector3_ backward() { return vector3_( 0, 0, 1); } - inline static vector3_ right() { return vector3_ ( 1, 0, 0); } - inline static vector3_ left() { return vector3_ (-1, 0, 0); } - inline static vector3_ up() { return vector3_ ( 0, 1, 0); } - inline static vector3_ down() { return vector3_ ( 0,-1, 0); } - -}; - - - -// Vec2x ----------------------------------------------------------------------- - -template class vector2_ : public vector_<2,T> { -public: - - vector2_() {} - - vector2_(T v1,T v2) { - this->set(v1,v2); - } - - void set(T v1,T v2) { - (*this)(0) = v1; (*this)(1) = v2; - } - - const T& x() const { return (*this)(0); } - T& x() { return (*this)(0); } - - const T& y() const { return (*this)(1); } - T& y() { return (*this)(1); } - -}; - -// Vec4 ----------------------------------------------------------------------- - -template class vector4_ : public vector_<4,T> { -public: - - using vector_<4,T>::vector_; - - vector4_(const T& v1,const T& v2,const T& v3,const T& v4) { - this->set(v1,v2,v3,v4); - } - - void set(const T& v1,const T& v2,const T& v3,const T& v4) { - (*this)(0) = v1; - (*this)(1) = v2; - (*this)(2) = v3; - (*this)(3) = v4; - } - - inline const vector3_ xyz() const { return vector3_(x(),y(),z()); } - inline const vector2_ xy() const { return vector2_(x(),y()); } - - const T& x() const { return (*this)(0); } - T& x() { return (*this)(0); } - - const T& y() const { return (*this)(1); } - T& y() { return (*this)(1); } - - const T& z() const { return (*this)(2); } - T& z() { return (*this)(2); } - - const T& w() const { return (*this)(3); } - T& w() { return (*this)(3); } - - - -}; - - -typedef vector2_ vector2ub; -typedef vector2_ vector2b; -typedef vector2_ vector2us; -typedef vector2_ vector2s; -typedef vector2_ vector2ui; -typedef vector2_ vector2i; -typedef vector2_ vector2ul; -typedef vector2_ vector2l; - -typedef vector2_ vector2d; -typedef vector2_ vector2f; -typedef vector2_ vector2; - -typedef vector3_ vector3; -typedef vector3_ vector3d; -typedef vector3_ vector3f; -typedef vector3_ vector3i; -typedef vector3_ vector3ui; - - -typedef vector4_ vector4; -typedef vector4_ vector4d; -typedef vector4_ vector4f; -typedef vector4_ vector4i; -typedef vector4_ vector4ui; - -} - - -////////////////////////////////////////////////////////////////////////// - - - -#endif - - - #endif diff --git a/src/core/src/mesh.cpp b/src/core/src/mesh.cpp index d10794c..030d37c 100644 --- a/src/core/src/mesh.cpp +++ b/src/core/src/mesh.cpp @@ -6,14 +6,8 @@ namespace pw { void mesh::apply(const matrix4x4 &m) { for (auto &v : _vertices) - { -// v = vector4(m * v.project(1)).un_project(); - -// auto vh = v.project(1); - // m.mul(vh); - } + v = vector4(m * v.homogenous()).project(); } - } diff --git a/src/core/tests/CMakeLists.txt b/src/core/tests/CMakeLists.txt index 517f07a..7abff2a 100644 --- a/src/core/tests/CMakeLists.txt +++ b/src/core/tests/CMakeLists.txt @@ -5,25 +5,25 @@ add_executable(pwcore_test_matrix target_link_libraries(pwcore_test_matrix pwcore) -#add_executable(pwcore_test_vector -# pwcore_test_vector.cpp -# ) +add_executable(pwcore_test_vector + pwcore_test_vector.cpp + ) -#target_link_libraries(pwcore_test_vector -# pwcore) +target_link_libraries(pwcore_test_vector + pwcore) -#add_executable(pwcore_test_quaternion -# pwcore_test_quaternion.cpp -# ) +add_executable(pwcore_test_quaternion + pwcore_test_quaternion.cpp + ) -#target_link_libraries(pwcore_test_quaternion -# pwcore) +target_link_libraries(pwcore_test_quaternion + pwcore) -#add_executable(pwcore_test_axisangle -# pwcore_test_axisangle.cpp -# ) +add_executable(pwcore_test_axisangle + pwcore_test_axisangle.cpp + ) -#target_link_libraries(pwcore_test_axisangle -# pwcore) +target_link_libraries(pwcore_test_axisangle + pwcore) diff --git a/src/core/tests/pwcore_test_axisangle.cpp b/src/core/tests/pwcore_test_axisangle.cpp index 0a36a03..39864ba 100644 --- a/src/core/tests/pwcore_test_axisangle.cpp +++ b/src/core/tests/pwcore_test_axisangle.cpp @@ -13,6 +13,5 @@ int main(int argc,char **argv) { std::cout << "aa as quaternion as matrix = " << pw::serialize::matrix(qf.to_matrix()) << std::endl; std::cout << "aa.matrix() = " << pw::serialize::matrix(qf.to_matrix()) << std::endl; - return 0; } diff --git a/src/core/tests/pwcore_test_matrix.cpp b/src/core/tests/pwcore_test_matrix.cpp index c25146f..0ed0ae9 100644 --- a/src/core/tests/pwcore_test_matrix.cpp +++ b/src/core/tests/pwcore_test_matrix.cpp @@ -36,6 +36,7 @@ int main(int argc,char **argv) { auto v2_b = m22_inv * v2_f; vector2_ r_m22 = m22.row(0).transposed(); + vector2_ c_m22 = m22.column(1); auto r_m22_h = r_m22.homogenous(); diff --git a/src/core/tests/pwcore_test_vector.cpp b/src/core/tests/pwcore_test_vector.cpp index 0487ebd..c72d8e4 100644 --- a/src/core/tests/pwcore_test_vector.cpp +++ b/src/core/tests/pwcore_test_vector.cpp @@ -6,9 +6,16 @@ int main(int argc,char **argv) { - pw::vector2_ v2; + pw::vector2_ v2_A = { 3.2, 1.2 }; + pw::vector2_ v2_B = { 3.2, 1.2 }; - v2.x = 0.1f; + + auto AB_lerp = pw::vector2f::lerp(v2_A,v2_B,0.5); + + + + +// v2 = 0.1f; // pw::vector4_ v4; // pw::vector3f v; diff --git a/src/geometry/src/primitives.cpp b/src/geometry/src/primitives.cpp index c099cb6..01248d3 100644 --- a/src/geometry/src/primitives.cpp +++ b/src/geometry/src/primitives.cpp @@ -8,15 +8,15 @@ mesh primitives::box(real_t size_x,real_t size_y, real_t size_z) mesh::vertex3array_t vertices; - vertices.push_back(vector3(-size_x / 2,-size_y / 2, size_z / 2)); // 0 - vertices.push_back(vector3( size_x / 2,-size_y / 2, size_z / 2)); // 1 - vertices.push_back(vector3( size_x / 2, size_y / 2, size_z / 2)); // 2 - vertices.push_back(vector3(-size_x / 2, size_y / 2, size_z / 2)); // 3 + vertices.push_back( { -size_x / 2,-size_y / 2, size_z / 2 } ); // 0 + vertices.push_back( { size_x / 2,-size_y / 2, size_z / 2 } ); // 1 + vertices.push_back( { size_x / 2, size_y / 2, size_z / 2 } ); // 2 + vertices.push_back( {-size_x / 2, size_y / 2, size_z / 2} ); // 3 - vertices.push_back(vector3(-size_x / 2,-size_y / 2,-size_z / 2)); // 4 - vertices.push_back(vector3( size_x / 2,-size_y / 2,-size_z / 2)); // 5 - vertices.push_back(vector3( size_x / 2, size_y / 2,-size_z / 2)); // 6 - vertices.push_back(vector3(-size_x / 2, size_y / 2,-size_z / 2)); // 7 + vertices.push_back( {-size_x / 2,-size_y / 2,-size_z / 2} ); // 4 + vertices.push_back( { size_x / 2,-size_y / 2,-size_z / 2}); // 5 + vertices.push_back( { size_x / 2, size_y / 2,-size_z / 2}); // 6 + vertices.push_back( {-size_x / 2, size_y / 2,-size_z / 2}); // 7 mesh::indexarray_t indices = { 0, 1, 2, // 0 diff --git a/src/scene/include/pw/scene/transform.hpp b/src/scene/include/pw/scene/transform.hpp index f7f5c5a..66ee7a1 100644 --- a/src/scene/include/pw/scene/transform.hpp +++ b/src/scene/include/pw/scene/transform.hpp @@ -23,17 +23,17 @@ public: void set_global(const matrix4x4 &global); inline void translate(const real_t &x, const real_t &y, const real_t &z) { - _local.at(0,3) += x;_local.at(1,3) += y;_local.at(2,3) += z; + _local(0,3) += x;_local(1,3) += y;_local(2,3) += z; update_global_from_local(); } inline void rotate(const quaternion& q) { - _local *= q.to_matrix(); + _local = _local * q.to_matrix(); update_global_from_local(); } inline void scale(const real_t &x, const real_t &y, const real_t &z) { - _local.at(0,0) *= x; _local.at(1,1) *= y; _local.at(2,2) *= z; + _local(0,0) *= x; _local(1,1) *= y; _local(2,2) *= z; update_global_from_local(); } @@ -42,7 +42,7 @@ public: } inline void set_translation(const real_t &x, const real_t &y, const real_t &z) { - _local.at(0,3) = x;_local.at(1,3) = y;_local.at(2,3) = z; + _local(0,3) = x;_local(1,3) = y;_local(2,3) = z; update_global_from_local(); } diff --git a/src/scene/src/camera.cpp b/src/scene/src/camera.cpp index e3c04d2..d211710 100644 --- a/src/scene/src/camera.cpp +++ b/src/scene/src/camera.cpp @@ -7,12 +7,14 @@ camera::camera() , _near_plane(0.2f) , _far_plane(1000) { - set_projection(matrix4x4::perspective_projection(_fov,1,_near_plane,_far_plane)); + set_projection(transform_tools::perspective_projection(_fov,1,_near_plane,_far_plane)); } void camera::set_projection(const matrix4x4 &projection) { this->_projection = projection; + + // recompute the simplified parameters } const matrix4x4 &camera::projection() const diff --git a/src/scene/tests/pwscene_test_node.cpp b/src/scene/tests/pwscene_test_node.cpp index 4fb15a3..d865302 100644 --- a/src/scene/tests/pwscene_test_node.cpp +++ b/src/scene/tests/pwscene_test_node.cpp @@ -53,7 +53,7 @@ int main(int argc,char **argv) { // auto t = n->transform(); // if (t) - std::cout << n->transform().local().at(0,0) << std::endl; + std::cout << n->transform().local()(0,0) << std::endl; // else { // std::cerr << "no transform?" << std::endl; // } diff --git a/src/scripting/src/script_core.cpp b/src/scripting/src/script_core.cpp index 668d7d7..109dc86 100644 --- a/src/scripting/src/script_core.cpp +++ b/src/scripting/src/script_core.cpp @@ -19,36 +19,40 @@ void script_core::load(sol::table &ns) ns.set("pi",pw::pi()); - ns.new_usertype("vector3", - sol::constructors(), - "set",&vector3::set, - "x", scripting::property(scripting::resolve(&vector3::x), &vector3::set_x), - "y", scripting::property(scripting::resolve(&vector3::y), &vector3::set_y), - "z", scripting::property(scripting::resolve(&vector3::z), &vector3::set_z), - "norm",&vector3::norm, - "cross",&vector3::cross, - "dot",&vector3::dot, - // sol::meta_function::addition, sol::resolve(::operator+), - // sol::meta_function::subtraction, &vector3::operator- - // "v",&vector3::values, - "clone",&vector3::clone - ); + ns.new_usertype( + "vector3", + sol::constructors(), + "x", sol::property(sol::resolve(&vector3::x), [](vector3::value_type v){ x() = v}) + ); - ns.new_usertype("quaternion", - sol::constructors(), - "set",&quaternion::set, - "x", scripting::property(scripting::resolve(&quaternion::x), &quaternion::set_x), - "y", scripting::property(scripting::resolve(&quaternion::y), &quaternion::set_y), - "z", scripting::property(scripting::resolve(&quaternion::z), &quaternion::set_z), - "w", scripting::property(scripting::resolve(&quaternion::w), &quaternion::set_w), - "dot",&quaternion::dot, - "inverse",scripting::readonly_property(&quaternion::inverse), - "normalized",&quaternion::normalized, - "lerp",&quaternion::lerp, - "slerp",&quaternion::slerp - // "v",&vector3d::values, - // "clone",&vector3d::clone - ); + +// ns.new_usertype("vector3", +// sol::constructors(), +// "x",&vector3::x +//// "set",&vector3::set, +//// "x", scripting::property(scripting::resolve(&vector3::x), &vector3::set_x), +//// "y", scripting::property(scripting::resolve(&vector3::y), &vector3::set_y), +//// "z", scripting::property(scripting::resolve(&vector3::z), &vector3::set_z), +//// "norm",&vector3::norm, +//// "cross",&vector3::cross, +//// "dot",&vector3::dot +// ); + +// ns.new_usertype("quaternion", +// sol::constructors(), +// "set",&quaternion::set, +// "x", scripting::property(scripting::resolve(&quaternion::x), &quaternion::set_x), +// "y", scripting::property(scripting::resolve(&quaternion::y), &quaternion::set_y), +// "z", scripting::property(scripting::resolve(&quaternion::z), &quaternion::set_z), +// "w", scripting::property(scripting::resolve(&quaternion::w), &quaternion::set_w), +// "dot",&quaternion::dot, +// "inverse",scripting::readonly_property(&quaternion::inverse), +// "normalized",&quaternion::normalized, +// "lerp",&quaternion::lerp, +// "slerp",&quaternion::slerp +// // "v",&vector3d::values, +// // "clone",&vector3d::clone +// ); ns.new_usertype("axisangle", sol::constructors(), diff --git a/src/scripting/src/scripting.hpp b/src/scripting/src/scripting.hpp index 644ddb6..6055cb5 100644 --- a/src/scripting/src/scripting.hpp +++ b/src/scripting/src/scripting.hpp @@ -9,7 +9,6 @@ namespace pw { // include external namespace of sol namespace scripting = sol; - } #endif diff --git a/src/visual/src/shader.cpp b/src/visual/src/shader.cpp index 25bed82..690fd3a 100644 --- a/src/visual/src/shader.cpp +++ b/src/visual/src/shader.cpp @@ -149,7 +149,7 @@ struct shader::impl void bind(int location,const matrix4x4f& m) { - glUniformMatrix4fv(location,1,GL_FALSE,m.data()); // TODO transpose? + glUniformMatrix4fv(location,1,GL_FALSE,m.data); // TODO transpose? } };