From 24154087ba3f1065831a1fc4f5e389e6fe1d7d0e Mon Sep 17 00:00:00 2001 From: Hartmut Seichter <hartmut@technotecture.com> Date: Mon, 7 Jan 2019 17:09:20 +0100 Subject: [PATCH] small update to put more transformation code into the right spots --- src/core/CMakeLists.txt | 59 ++++++++++++------------ src/core/include/pw/core/axisangle.hpp | 48 ++++++++++++++++--- src/core/include/pw/core/image.hpp | 10 ++++ src/core/include/pw/core/matrix.hpp | 12 ++--- src/core/include/pw/core/size.hpp | 12 +++-- src/core/include/pw/core/vector.hpp | 8 +--- src/core/src/core.cpp | 2 +- src/core/src/image.cpp | 7 +++ src/core/tests/pwcore_test_axisangle.cpp | 2 +- src/core/tests/pwcore_test_matrix.cpp | 10 ++-- src/deps/CMakeLists.txt | 2 +- src/scene/include/pw/scene/camera.hpp | 6 +-- src/scene/include/pw/scene/transform.hpp | 12 ++--- src/scene/src/camera.cpp | 6 +-- src/scene/src/transform.cpp | 4 +- src/scripting/CMakeLists.txt | 2 +- 16 files changed, 126 insertions(+), 76 deletions(-) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index d5b0ba3..daf8522 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,40 +1,41 @@ set(hdrs - include/pw/core/log.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/image.hpp - include/pw/core/size.hpp - include/pw/core/timer.hpp - include/pw/core/globals.hpp - ) + include/pw/core/log.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/image.hpp + include/pw/core/size.hpp + include/pw/core/timer.hpp + include/pw/core/globals.hpp + ) set(srcs - src/log.cpp - src/core.cpp - src/serialize.cpp - src/timer.cpp - ${CMAKE_SOURCE_DIR}/README.md - ${CMAKE_SOURCE_DIR}/LICENSE - ) + src/image.cpp + src/log.cpp + src/core.cpp + src/serialize.cpp + src/timer.cpp + ${CMAKE_SOURCE_DIR}/README.md + ${CMAKE_SOURCE_DIR}/LICENSE + ) add_library(pwcore - STATIC - ${hdrs} - ${srcs} - ) + STATIC + ${hdrs} + ${srcs} + ) target_include_directories( - pwcore - PUBLIC - include - ) + pwcore + PUBLIC + include + ) target_link_libraries(pwcore) diff --git a/src/core/include/pw/core/axisangle.hpp b/src/core/include/pw/core/axisangle.hpp index 6ae295d..64175e4 100644 --- a/src/core/include/pw/core/axisangle.hpp +++ b/src/core/include/pw/core/axisangle.hpp @@ -6,18 +6,18 @@ namespace pw { template <typename T> -class axisangle { +class axisangle_ { protected: vector3_<T> _axis; T _angle; public: - axisangle() - : _axis(vector3_<T>::up()), - _angle(0) - {} + 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) , _angle(angle) { @@ -29,9 +29,43 @@ public: T angle() const { return _angle; } void set_angle(const T &angle) { _angle = angle; } + matrix4x4_<T> to_matrix() const + { + using std::cos; + using std::sin; + + matrix4x4_<T> R; R.set_identity(); // = matrix44<T>::Identity(); + + if (_axis.norm() < std::numeric_limits<T>::epsilon()) return R; + + const T _fCos = cos(_angle); + + matrix_<3,1,T> _vCos(_axis * (1 - _fCos)); + matrix_<3,1,T> _vSin(_axis * sin(_angle)); + +// R.at(0) = (_axis(0,0) * _vCos(0,0)) + _fCos; + // R.at(4) = (T) ((vec(0,0) * _vCos(1,0)) - _vSin(2,0)); + // R.at(8) = (T) ((vec(0,0) * _vCos(2,0)) + _vSin(1,0)); + + // R.at(1) = (T) ((vec(1,0) * _vCos(0,0)) + _vSin(2,0)); + // R.at(5) = (T) ((vec(1,0) * _vCos(1,0)) + _fCos); + // R.at(9) = (T) ((vec(1,0) * _vCos(2,0)) - _vSin(0,0)); + + // R.at(2) = (T) ((vec(2,0) * _vCos(0,0)) - _vSin(1,0)); + // R.at(6) = (T) ((vec(2,0) * _vCos(1,0)) + _vSin(0,0)); + // R.at(10)= (T) ((vec(2,0) * _vCos(2,0)) + _fCos); + + return R; + } + + + }; -typedef axisangle<double> axisangled; + +typedef axisangle_<real_t> axisangle; +typedef axisangle_<double> axisangled; +typedef axisangle_<float> axisanglef; } diff --git a/src/core/include/pw/core/image.hpp b/src/core/include/pw/core/image.hpp index dbd64f9..7475527 100644 --- a/src/core/include/pw/core/image.hpp +++ b/src/core/include/pw/core/image.hpp @@ -6,6 +6,16 @@ namespace pw { class image { +public: + + image() = default; + + + +protected: + + std::vector<unsigned char> _data; + std::string _uri; }; diff --git a/src/core/include/pw/core/matrix.hpp b/src/core/include/pw/core/matrix.hpp index 25fc130..202ed78 100644 --- a/src/core/include/pw/core/matrix.hpp +++ b/src/core/include/pw/core/matrix.hpp @@ -320,19 +320,19 @@ void matrix_<R,C,T>::normalize() // 4x4 template <typename T> -class matrix44_ : public matrix_<4,4,T> +class matrix4x4_ : public matrix_<4,4,T> { public: using matrix_<4,4,T>::matrix_; - matrix44_(const matrix_<4,4,T>& i) + matrix4x4_(const matrix_<4,4,T>& i) { *this = i; } - matrix44_& operator = (const matrix_<4,4,T>& rhs) { + matrix4x4_& operator = (const matrix_<4,4,T>& rhs) { if (this != &rhs){ this->at(0,0) = rhs.at(0,0);this->at(0,1) = rhs.at(0,1);this->at(0,2) = rhs.at(0,2);this->at(0,3) = rhs.at(0,3); this->at(1,0) = rhs.at(1,0);this->at(1,1) = rhs.at(1,1);this->at(1,2) = rhs.at(1,2);this->at(1,3) = rhs.at(1,3); @@ -600,10 +600,10 @@ matrix44<T>::LookAt(const matrix<3,1,T> &eye, const matrix<3,1,T> &target, const // predefined matricies -typedef matrix44_<real_t> matrix44; +typedef matrix4x4_<real_t> matrix4x4; -typedef matrix44_<double> matrix44d; -typedef matrix44_<float> matrix44f; +typedef matrix4x4_<double> matrix4x4d; +typedef matrix4x4_<float> matrix4x4f; } diff --git a/src/core/include/pw/core/size.hpp b/src/core/include/pw/core/size.hpp index cb26169..9d5ae7a 100644 --- a/src/core/include/pw/core/size.hpp +++ b/src/core/include/pw/core/size.hpp @@ -31,19 +31,21 @@ namespace pw { template <typename T_> -struct size { +struct size_ { - T_ dim[2] = { 0, 0}; + T_ dim[2] = { 0, 0 }; - size(T_ w,T_ h) : dim( { w, h }) {} + 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; +typedef size_<real_t> size; + +typedef size_<int> sizei; +typedef size_<float> sizef; } diff --git a/src/core/include/pw/core/vector.hpp b/src/core/include/pw/core/vector.hpp index eab298e..a95dd38 100644 --- a/src/core/include/pw/core/vector.hpp +++ b/src/core/include/pw/core/vector.hpp @@ -60,7 +60,6 @@ public: return acos( nothr.dot(nself) ); } - }; @@ -106,12 +105,9 @@ public: return vector_<4,T>(x(),y(),z(),w); } -#if _GCC_STUPID_ - inline std::tuple<T,T,T> values() const { - return std::make_tuple(x(),y(),z()); + const vector_<2,T> unproject() const { + return vector_<2,T>(x()/z(),y()/z()); } -#endif - inline static vector3_<T> forward() { return vector3_<T> ( 0, 0,-1); } inline static vector3_<T> backward() { return vector3_<T>( 0, 0, 1); } diff --git a/src/core/src/core.cpp b/src/core/src/core.cpp index 1e4b5a1..2cd3346 100644 --- a/src/core/src/core.cpp +++ b/src/core/src/core.cpp @@ -13,7 +13,7 @@ void test_matrixbase() { using namespace pw; - matrix44f m; + matrix4x4f m; m.set_identity(); diff --git a/src/core/src/image.cpp b/src/core/src/image.cpp index e69de29..fdd0408 100644 --- a/src/core/src/image.cpp +++ b/src/core/src/image.cpp @@ -0,0 +1,7 @@ +#include "pw/core/image.hpp" + +namespace pw { + + + +} diff --git a/src/core/tests/pwcore_test_axisangle.cpp b/src/core/tests/pwcore_test_axisangle.cpp index a618fb1..da495be 100644 --- a/src/core/tests/pwcore_test_axisangle.cpp +++ b/src/core/tests/pwcore_test_axisangle.cpp @@ -6,7 +6,7 @@ int main(int argc,char **argv) { - pw::axisangle<float> aa = pw::axisangle<float>(); + pw::axisangle_<float> aa = pw::axisangle_<float>(); pw::quaternionf qf = pw::quaternionf::from_axisangle(aa); diff --git a/src/core/tests/pwcore_test_matrix.cpp b/src/core/tests/pwcore_test_matrix.cpp index a8cdd63..d06b380 100644 --- a/src/core/tests/pwcore_test_matrix.cpp +++ b/src/core/tests/pwcore_test_matrix.cpp @@ -6,7 +6,7 @@ int main(int argc,char **argv) { - pw::matrix44d m; + pw::matrix4x4d m; m.set_identity(); @@ -22,18 +22,18 @@ int main(int argc,char **argv) { std::cout << "determinant(): " << m.determinant() << std::endl; - pw::matrix44d mi = m.get_inverse(); + pw::matrix4x4d mi = m.get_inverse(); std::cout << "mi.at(0,0) : " << mi.at(0,0) << std::endl; - pw::matrix44d mscale = m * 4.2; + pw::matrix4x4d mscale = m * 4.2; std::cout << "mscale = " << pw::serialize::matrix(mscale) << std::endl; - pw::matrix44d a; + pw::matrix4x4d a; for (int r = 0; r < m.rows(); r++) { for (int c = 0; c < m.cols(); c++) { @@ -42,7 +42,7 @@ int main(int argc,char **argv) { } std::cout << "a = " << pw::serialize::matrix(a) << std::endl; - pw::matrix44d r = a * mscale; + pw::matrix4x4d r = a * mscale; std::cout << "a * mscale = " << pw::serialize::matrix(r) << std::endl; diff --git a/src/deps/CMakeLists.txt b/src/deps/CMakeLists.txt index 04a59b4..c267051 100644 --- a/src/deps/CMakeLists.txt +++ b/src/deps/CMakeLists.txt @@ -1,5 +1,5 @@ add_subdirectory(glfw-3.2.1) -add_subdirectory(lua-5.3.4) +add_subdirectory(lua-5.3.5) add_subdirectory(glad) #add_subdirectory(arrrgh) diff --git a/src/scene/include/pw/scene/camera.hpp b/src/scene/include/pw/scene/camera.hpp index 7b8ae9d..66dede6 100644 --- a/src/scene/include/pw/scene/camera.hpp +++ b/src/scene/include/pw/scene/camera.hpp @@ -49,8 +49,8 @@ public: camera(); - void set_projection(const matrix44 &projection); - const matrix44& projection() const; + void set_projection(const matrix4x4 &projection); + const matrix4x4& projection() const; // void set_field_of_view(float) @@ -64,7 +64,7 @@ protected: private: - matrix44 _projection; + matrix4x4 _projection; }; diff --git a/src/scene/include/pw/scene/transform.hpp b/src/scene/include/pw/scene/transform.hpp index 99f24c5..f7f5c5a 100644 --- a/src/scene/include/pw/scene/transform.hpp +++ b/src/scene/include/pw/scene/transform.hpp @@ -16,11 +16,11 @@ public: transform(); - inline const matrix44& local() const { return _local; } - void set_local(const matrix44 &local); + inline const matrix4x4& local() const { return _local; } + void set_local(const matrix4x4 &local); - inline const matrix44& global() const { return _global; } - void set_global(const matrix44 &global); + inline const matrix4x4& global() const { return _global; } + 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; @@ -53,8 +53,8 @@ public: protected: - matrix44 _local; - matrix44 _global; + matrix4x4 _local; + matrix4x4 _global; private: diff --git a/src/scene/src/camera.cpp b/src/scene/src/camera.cpp index 63c845a..e3c04d2 100644 --- a/src/scene/src/camera.cpp +++ b/src/scene/src/camera.cpp @@ -7,15 +7,15 @@ camera::camera() , _near_plane(0.2f) , _far_plane(1000) { - set_projection(matrix44::perspective_projection(_fov,1,_near_plane,_far_plane)); + set_projection(matrix4x4::perspective_projection(_fov,1,_near_plane,_far_plane)); } -void camera::set_projection(const matrix44 &projection) +void camera::set_projection(const matrix4x4 &projection) { this->_projection = projection; } -const matrix44 &camera::projection() const +const matrix4x4 &camera::projection() const { return _projection; } diff --git a/src/scene/src/transform.cpp b/src/scene/src/transform.cpp index e2ad2c5..6f35881 100644 --- a/src/scene/src/transform.cpp +++ b/src/scene/src/transform.cpp @@ -9,14 +9,14 @@ transform::transform() _global.set_identity(); } -void transform::set_local(const matrix44 &local) +void transform::set_local(const matrix4x4 &local) { // TODO need to rebuild the transforms: both -> global down and global up _local = local; } -void transform::set_global(const matrix44 &global) +void transform::set_global(const matrix4x4 &global) { //TODO need to rebuild **_local** from parent _global = global; diff --git a/src/scripting/CMakeLists.txt b/src/scripting/CMakeLists.txt index 1b8dcae..97533d5 100644 --- a/src/scripting/CMakeLists.txt +++ b/src/scripting/CMakeLists.txt @@ -24,7 +24,7 @@ add_library(pwscripting target_include_directories( pwscripting PRIVATE - ${CMAKE_SOURCE_DIR}/src/deps/lua-5.3.4/src + ${CMAKE_SOURCE_DIR}/src/deps/lua-5.3.5/src ${CMAKE_SOURCE_DIR}/src/deps/sol2-2.20.6 PUBLIC include